List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:Display.java
@SuppressWarnings("unchecked") Display() {//from w w w . j ava2s. c om super(Reference.NAME); cardLayout = new CardLayout(); panel.setLayout(cardLayout); final int java7Update = Utils.Validators.java7Update.check(); final int java8Update = Utils.Validators.java8Update.check(); try { URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY); JSONParser parser = new JSONParser(); Object json = parser.parse(new URLReader(host)); final JSONArray array = (JSONArray) json; JSONObject nameObject1 = (JSONObject) array.get(0); XPackInstaller.selected_url = nameObject1.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString()); XPackInstaller.profile = nameObject1.get("profile").toString(); XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject1.get("canAcceptOptional").toString()); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } for (Object anArray : array) { comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name")); } comboBox1.addActionListener(e -> { int i = 0; while (true) { JSONObject nameObject = (JSONObject) array.get(i); String name1 = nameObject.get("name").toString(); if (name1 == comboBox1.getSelectedItem()) { XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject.get("canAcceptOptional").toString()); XPackInstaller.selected_url = nameObject.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString()); XPackInstaller.profile = nameObject.get("profile").toString(); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } break; } i++; } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { if (XPackInstaller.javaVersion == 8) { javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!"); } else { javaversion.setText("Nie posiadasz najnowszej wersji JRE7!"); } javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } }); } catch (FileNotFoundException | ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { PathLauncherLabel.setEnabled(true); textField1.setEnabled(true); button3.setEnabled(true); XPackInstaller.installLauncher = true; labelLauncher.setEnabled(true); progressBar3.setEnabled(true); } else { PathLauncherLabel.setEnabled(false); textField1.setEnabled(false); button3.setEnabled(false); XPackInstaller.installLauncher = false; labelLauncher.setEnabled(false); progressBar3.setEnabled(false); } }); button3.addActionListener(e -> { JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); chooser.setApproveButtonText("Wybierz"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle("Wybierz ciek"); int returnValue = chooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { try { XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath(); } catch (IOException x) { x.printStackTrace(); } textField1.setText(XPackInstaller.launcher_path); } }); slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2); slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue()); button1.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe"); if (textField1.getText().equals("")) { JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!", "Bd", JOptionPane.ERROR_MESSAGE); } else if (launcher.exists()) { JOptionPane.showMessageDialog(panel, "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad", JOptionPane.ERROR_MESSAGE); } else { cardLayout.next(panel); } } else { cardLayout.next(panel); if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK") && javaarch.getText().equals("NIE") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); JOptionPane.showMessageDialog(gui, "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.", "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE); } } }); if (Utils.Validators.systemArchitecture.check()) { osarch.setText("TAK"); osarch.setForeground(Reference.COLOR_DARK_GREEN); } else { osarch.setText("NIE"); osarch.setForeground(Color.RED); } if (Utils.Validators.ramAmount.check()) { Ram.setText("TAK"); Ram.setForeground(Reference.COLOR_DARK_GREEN); } else { Ram.setText("NIE"); Ram.setForeground(Color.RED); } if (Utils.Validators.javaArchitecture.check()) { javaarch.setText("TAK"); javaarch.setForeground(Reference.COLOR_DARK_GREEN); } else { javaarch.setText("NIE"); javaarch.setForeground(Color.RED); } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { javaversion.setText("Nie posiadasz najnowszej wersji JRE!"); javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } button2.addActionListener(e -> { if (XPackInstaller.canGoForward) { cardLayout.next(panel); } else { System.exit(1); } }); wsteczButton.addActionListener(e -> cardLayout.previous(panel)); try { editorPane1.setPage("http://xpack.pl/licencja.html"); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } licenseC.addActionListener(e -> { if (licenseC.isSelected()) { dalejButton.setEnabled(true); } else { dalejButton.setEnabled(false); } }); try { File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller"); if (mainDir.exists()) { FileUtils.deleteDirectory(mainDir); if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } else { if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods"); if (!optionalDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } dalejButton.addActionListener(e -> { cardLayout.next(panel); try { progressBar1.setValue(0); if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task3(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (checkOptifine.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (zainstalujMoCreaturesCheckBox.isSelected()) { task3(); } else { task(); } } catch (Exception exx) { exx.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } final JScrollBar bar = scrollPane1.getVerticalScrollBar(); bar.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); bar.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); scrollPane1.setWheelScrollingEnabled(true); scrollPane1.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); panel.add(panel3); panel.add(panel1); panel.add(panel2); panel.add(panel4); add(panel); }
From source file:be.fedict.eid.tsl.tool.TslTool.java
@Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (EXIT_ACTION_COMMAND.equals(command)) { System.exit(0);//from w ww . j av a 2 s .c o m } else if (OPEN_ACTION_COMMAND.equals(command)) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open TSL"); int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { displayTsl(fileChooser.getSelectedFile()); } } else if (ABOUT_ACTION_COMMAND.equals(command)) { JOptionPane.showMessageDialog(this, "eID TSL Tool\n" + "Copyright (C) 2009-2013 FedICT\n" + "http://code.google.com/p/eid-tsl/", "About", JOptionPane.INFORMATION_MESSAGE); } else if (CLOSE_ACTION_COMMAND.equals(command)) { if (this.activeTslInternalFrame.getTrustServiceList().hasChanged()) { int result = JOptionPane.showConfirmDialog(this, "TSL has been changed.\n" + "Save the TSL?", "Save", JOptionPane.YES_NO_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == result) { return; } if (JOptionPane.YES_OPTION == result) { try { this.activeTslInternalFrame.save(); } catch (IOException e) { LOG.error("IO error: " + e.getMessage(), e); } } } try { this.activeTslInternalFrame.setClosed(true); } catch (PropertyVetoException e) { LOG.warn("property veto error: " + e.getMessage(), e); } } else if (SIGN_ACTION_COMMAND.equals(command)) { LOG.debug("sign"); TrustServiceList trustServiceList = this.activeTslInternalFrame.getTrustServiceList(); if (trustServiceList.hasSignature()) { int confirmResult = JOptionPane.showConfirmDialog(this, "TSL is already signed.\n" + "Resign the TSL?", "Resign", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } SignSelectPkcs11FinishablePanel pkcs11Panel = new SignSelectPkcs11FinishablePanel(); WizardDescriptor wizardDescriptor = new WizardDescriptor( new WizardDescriptor.Panel[] { new SignInitFinishablePanel(), pkcs11Panel, new SignSelectCertificatePanel(pkcs11Panel, trustServiceList), new SignFinishFinishablePanel() }); wizardDescriptor.setTitle("Sign TSL"); wizardDescriptor.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); DialogDisplayer dialogDisplayer = DialogDisplayer.getDefault(); Dialog wizardDialog = dialogDisplayer.createDialog(wizardDescriptor); wizardDialog.setVisible(true); } else if (SAVE_ACTION_COMMAND.equals(command)) { LOG.debug("save"); try { this.activeTslInternalFrame.save(); this.saveMenuItem.setEnabled(false); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } else if (SAVE_AS_ACTION_COMMAND.equals(command)) { LOG.debug("save as"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save As"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File tslFile = fileChooser.getSelectedFile(); if (tslFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + tslFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.saveAs(tslFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } this.saveMenuItem.setEnabled(false); } } else if (EXPORT_ACTION_COMMAND.equals(command)) { LOG.debug("export"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Export to PDF"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File pdfFile = fileChooser.getSelectedFile(); if (pdfFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + pdfFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.export(pdfFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } } else if ("TSL-BE-2010-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.FIRST); displayTsl("*TSL-BE-2010-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.SECOND); displayTsl("*TSL-BE-2010-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.THIRD); displayTsl("*TSL-BE-2010-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.FIRST); displayTsl("*TSL-BE-2011-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.SECOND); displayTsl("*TSL-BE-2011-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.THIRD); displayTsl("*TSL-BE-2011-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.FIRST); displayTsl("*TSL-BE-2012-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.SECOND); displayTsl("*TSL-BE-2012-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.THIRD); displayTsl("*TSL-BE-2012-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.FIRST); displayTsl("*TSL-BE-2013-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.SECOND); displayTsl("*TSL-BE-2013-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.THIRD); displayTsl("*TSL-BE-2013-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.FIRST); displayTsl("*TSL-BE-2014-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.SECOND); displayTsl("*TSL-BE-2014-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.THIRD); displayTsl("*TSL-BE-2014-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.FIRST); displayTsl("*TSL-BE-2015-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.SECOND); displayTsl("*TSL-BE-2015-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.THIRD); displayTsl("*TSL-BE-2015-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobSingleBarcodeScan.java
@Override public void start() { startDate = new Date(); Singleton.getSingletonInstance().getJobList().addJob((RunnableJob) this); setPercentComplete(0);/* ww w .ja v a 2 s . c o m*/ Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Selecting file to check."); String rawOCR = ""; // to hold unparsed ocr output from unit tray label //Create a file chooser final JFileChooser fileChooser = new JFileChooser(); if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser.setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } //FileNameExtensionFilter filter = new FileNameExtensionFilter("TIFF Images", "tif", "tiff"); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "tif", "tiff", "jpg", "jpeg", "png"); fileChooser.setFileFilter(filter); int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); setPercentComplete(10); Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Scanning file for barcode."); if (returnValue == JFileChooser.APPROVE_OPTION) { File fileToCheck = fileChooser.getSelectedFile(); Singleton.getSingletonInstance().getProperties().getProperties() .setProperty(ImageCaptureProperties.KEY_LASTPATH, fileToCheck.getPath()); String filename = fileToCheck.getName(); log.debug("Selected file " + filename + " to scan for barcodes"); CandidateImageFile.debugCheckHeightWidth(fileToCheck); // scan selected file PositionTemplate defaultTemplate = null; // Figure out which template to use. DefaultPositionTemplateDetector detector = new DefaultPositionTemplateDetector(); String template = ""; try { template = detector.detectTemplateForImage(fileToCheck); } catch (UnreadableFileException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } setPercentComplete(20); try { defaultTemplate = new PositionTemplate(template); log.debug("Set template to: " + defaultTemplate.getTemplateId()); } catch (NoSuchTemplateException e1) { try { defaultTemplate = new PositionTemplate(PositionTemplate.TEMPLATE_DEFAULT); log.error("Template not recongised, reset template to: " + defaultTemplate.getTemplateId()); } catch (Exception e2) { // We shouldn't end up here - we just asked for the default template by its constant. log.fatal("PositionTemplate doesn't recognize TEMPLATE_DEFAULT"); log.trace(e2); ImageCaptureApp.exit(ImageCaptureApp.EXIT_ERROR); } } // TODO: Store the template id for this image with the other image metadata so // that we don't have to check again. CandidateImageFile scannableFile; try { scannableFile = new CandidateImageFile(fileToCheck, defaultTemplate); String barcode = scannableFile.getBarcodeTextAtFoundTemplate(); if (scannableFile.getCatalogNumberBarcodeStatus() != CandidateImageFile.RESULT_BARCODE_SCANNED) { log.error("Error scanning for barcode: " + barcode); barcode = ""; } String exifComment = scannableFile.getExifUserCommentText(); if (barcode.equals("") && Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(exifComment)) { // There should be a template for this image, and it shouldn't be the TEMPLATE_NO_COMPONENT_PARTS if (defaultTemplate.getTemplateId().equals(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS)) { try { // This will give us a shot at OCR of the text and display of the image parts. defaultTemplate = new PositionTemplate(PositionTemplate.TEMPLATE_DEFAULT); log.error("Barcode not recongised, but exif contains barcode, reset template to: " + defaultTemplate.getTemplateId()); } catch (Exception e2) { // We shouldn't end up here - we just asked for the default template by its constant. log.fatal("PositionTemplate doesn't recognize TEMPLATE_DEFAULT"); log.trace(e2); ImageCaptureApp.exit(ImageCaptureApp.EXIT_ERROR); } } } log.debug("With template:" + defaultTemplate.getTemplateId()); log.debug("Barcode=" + barcode); setPercentComplete(30); String warning = ""; if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_REDUNDANT_COMMENT_BARCODE).equals("true")) { if (!barcode.equals(exifComment)) { warning = "Warning: non-matching QR code barcode and exif Comment"; System.out.println(warning); } } Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Loading image."); ImageDisplayFrame resultFrame = new ImageDisplayFrame(); if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_REDUNDANT_COMMENT_BARCODE).equals("true")) { resultFrame.setBarcode("QR=" + barcode + " Comment=" + exifComment + " " + warning); } else { resultFrame.setBarcode("QR=" + barcode); } try { resultFrame.loadImagesFromFile(fileToCheck, defaultTemplate, null); } catch (ImageLoadException e2) { System.out.println("Error loading image file."); System.out.println(e2.getMessage()); } catch (BadTemplateException e2) { System.out.println("Template doesn't match image file."); System.out.println(e2.getMessage()); try { try { try { template = detector.detectTemplateForImage(fileToCheck); } catch (UnreadableFileException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } defaultTemplate = new PositionTemplate(template); } catch (NoSuchTemplateException e) { // TODO Auto-generated catch block e.printStackTrace(); } resultFrame.loadImagesFromFile(fileToCheck, defaultTemplate, null); } catch (ImageLoadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadTemplateException e) { System.out.println("Template doesn't match image file."); System.out.println(e2.getMessage()); } } UnitTrayLabel labelRead = null; try { // Read unitTrayLabelBarcode, failover to OCR and parse UnitTray Label rawOCR = ""; labelRead = scannableFile.getTaxonLabelQRText(defaultTemplate); if (labelRead == null) { try { labelRead = scannableFile.getTaxonLabelQRText(new PositionTemplate("Test template 2")); } catch (NoSuchTemplateException e1) { try { labelRead = scannableFile .getTaxonLabelQRText(new PositionTemplate("Small template 2")); } catch (NoSuchTemplateException e2) { log.error("None of " + defaultTemplate.getName() + " Test template 2 or Small template 2 were found"); } } } else { log.debug("Translated UnitTrayBarcode to: " + labelRead.toJSONString()); } if (labelRead != null) { rawOCR = labelRead.toJSONString(); } else { log.debug("Failing over to OCR with tesseract"); rawOCR = scannableFile.getLabelOCRText(defaultTemplate); } log.debug(rawOCR); resultFrame.setRawOCRLabel(rawOCR); setPercentComplete(40); } catch (Exception ex) { System.out.println(ex.getMessage()); } setPercentComplete(50); resultFrame.pack(); resultFrame.setVisible(true); resultFrame.centerSpecimen(); resultFrame.center(); setPercentComplete(60); if (persist) { // Check that fileToCheck is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(fileToCheck)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan file (" + fileToCheck.getPath() + ") outside of base image directory (" + base + ")"); throw new UnreadableFileException( "Can't scan and database files outside of base image directory (" + base + ")"); } String state = WorkFlowStatus.STAGE_0; Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Connecting to database."); // try to parse the raw OCR TaxonNameReturner parser = null; if (labelRead != null) { rawOCR = labelRead.toJSONString(); state = WorkFlowStatus.STAGE_1; parser = (TaxonNameReturner) labelRead; } else { log.debug("Failing over to OCR with tesseract"); rawOCR = scannableFile.getLabelOCRText(defaultTemplate); state = WorkFlowStatus.STAGE_0; parser = new UnitTrayLabelParser(rawOCR); } // Case 1: This is an image of papers associated with a container (a unit tray or a box). // This case can be identified by there being no barcode data associated with the image. // Action: // A) Check the exifComment to see what metadata is there, if blank, bring up a dialog. // Options: A drawer, for which number is captured. A unit tray, capture ?????????. A specimen // where barcode wasn't read, allow capture of barcode and treat as Case 2. // B) Create an image record and store the image metadata (with a null specimen_id). boolean isSpecimenImage = false; boolean isDrawerImage = false; // Test: is exifComment a barcode: if (Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(exifComment) || Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(barcode)) { isSpecimenImage = true; System.out.println("Specimen Image"); } else { if (exifComment.matches(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_REGEX_DRAWERNUMBER))) { isDrawerImage = true; System.out.println("Drawer Image"); } else { // Ask. System.out.println("Need to ask."); WhatsThisImageDialog askDialog = new WhatsThisImageDialog(resultFrame, fileToCheck); askDialog.setVisible(true); if (askDialog.isSpecimen()) { isSpecimenImage = true; exifComment = askDialog.getBarcode(); } if (askDialog.isDrawerImage()) { isDrawerImage = true; exifComment = askDialog.getDrawerNumber(); } } } // applies to both cases. ICImageLifeCycle imageCont = new ICImageLifeCycle(); ICImage tryMe = new ICImage(); tryMe.setFilename(filename); //String path = fileToCheck.getParentFile().getPath(); String path = ImageCaptureProperties.getPathBelowBase(fileToCheck); //String[] bits = rawOCR.split(":"); List<ICImage> matches = imageCont.findByExample(tryMe); // Case 2: This is an image of a specimen and associated labels or an image assocated with // a specimen with the specimen's barcode label in the image. // This case can be identified by there being a barcode in a templated position or there // being a barcode in the exif comment tag. // Action: // A) Check if a specimen record exists, if not, create one from the barcode and OCR data. // B) Create an image record and store the image metadata. // Handle a potential failure case, existing image record without a linked specimen, but which // should have one. if (matches.size() == 1 && isSpecimenImage) { ICImage existing = imageCont.findById(matches.get(0).getImageId()); if (existing.getSpecimen() == null) { // If the existing image record has no attached specimen, delete it. // We will create it again from tryMe. try { Singleton.getSingletonInstance().getMainFrame() .setStatusMessage("Removing existing unlinked image record."); imageCont.delete(existing); matches.remove(0); } catch (SaveFailedException e) { log.error(e.getMessage(), e); } } } if (matches.size() == 0) { String rawBarcode = barcode; if (isSpecimenImage) { Singleton.getSingletonInstance().getMainFrame() .setStatusMessage("Creating new specimen record."); Specimen s = new Specimen(); if ((!Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(barcode)) && Singleton.getSingletonInstance().getBarcodeMatcher() .matchesPattern(exifComment)) { s.setBarcode(exifComment); barcode = exifComment; } else { if (!Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(barcode)) { // Won't be able to save the specimen record if we end up here. log.error( "Neither exifComment nor QR Code barcode match the expected pattern for a barcode, but isSpecimenImage got set to true."); } s.setBarcode(barcode); } s.setWorkFlowStatus(state); if (!state.equals(WorkFlowStatus.STAGE_0)) { s.setFamily(parser.getFamily()); s.setSubfamily(parser.getSubfamily()); s.setTribe(parser.getTribe()); } else { s.setFamily(""); // Look up likely matches for the OCR of the higher taxa in the HigherTaxon authority file. HigherTaxonLifeCycle hls = new HigherTaxonLifeCycle(); if (parser.getTribe().trim().equals("")) { if (hls.isMatched(parser.getFamily(), parser.getSubfamily())) { // If there is a match, use it. String[] higher = hls.findMatch(parser.getFamily(), parser.getSubfamily()); s.setFamily(higher[0]); s.setSubfamily(higher[1]); } else { // otherwise use the raw OCR output. s.setFamily(parser.getFamily()); s.setSubfamily(parser.getSubfamily()); } s.setTribe(""); } else { if (hls.isMatched(parser.getFamily(), parser.getSubfamily(), parser.getTribe())) { String[] higher = hls.findMatch(parser.getFamily(), parser.getSubfamily(), parser.getTribe()); s.setFamily(higher[0]); s.setSubfamily(higher[1]); s.setTribe(higher[2]); } else { s.setFamily(parser.getFamily()); s.setSubfamily(parser.getSubfamily()); s.setTribe(parser.getTribe()); } } if (!parser.getFamily().equals("")) { // check family against database (with a soundex match) String match = hls.findMatch(parser.getFamily()); if (match != null && !match.trim().equals("")) { s.setFamily(match); } } } // trim family to fit (in case multiple parts of taxon name weren't parsed // and got concatenated into family field. if (s.getFamily().length() > 40) { s.setFamily(s.getFamily().substring(0, 40)); } s.setGenus(parser.getGenus()); s.setSpecificEpithet(parser.getSpecificEpithet()); s.setSubspecificEpithet(parser.getSubspecificEpithet()); s.setInfraspecificEpithet(parser.getInfraspecificEpithet()); s.setInfraspecificRank(parser.getInfraspecificRank()); s.setAuthorship(parser.getAuthorship()); s.setDrawerNumber(((DrawerNameReturner) parser).getDrawerNumber()); s.setCollection(((CollectionReturner) parser).getCollection()); s.setCreatingPath(ImageCaptureProperties.getPathBelowBase(fileToCheck)); s.setCreatingFilename(fileToCheck.getName()); if (parser.getIdentifiedBy() != null && parser.getIdentifiedBy().length() > 0) { s.setIdentifiedBy(parser.getIdentifiedBy()); } log.debug(s.getCollection()); // TODO: non-general workflows // ********* Special Cases ********** if (s.getWorkFlowStatus().equals(WorkFlowStatus.STAGE_0)) { // ***** Special case, images in ent-formicidae // get family set to Formicidae if in state OCR. if (path.contains("formicidae")) { s.setFamily("Formicidae"); } } s.setLocationInCollection(LocationInCollection.getDefaultLocation()); if (s.getFamily().equals("Formicidae")) { // ***** Special case, families in Formicidae are in Ant collection s.setLocationInCollection(LocationInCollection.GENERALANT); } // ********* End Special Cases ********** s.setCreatedBy(ImageCaptureApp.APP_NAME + " " + ImageCaptureApp.APP_VERSION); SpecimenLifeCycle sh = new SpecimenLifeCycle(); try { sh.persist(s); s.attachNewPart(); } catch (SpecimenExistsException e) { log.debug(e); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), filename + " " + barcode + " \n" + e.getMessage(), "Specimen Exists, linking Image to existing record.", JOptionPane.ERROR_MESSAGE); List<Specimen> checkResult = sh.findByBarcode(barcode); if (checkResult.size() == 1) { s = checkResult.get(0); } } catch (SaveFailedException e) { // Couldn't save, but for some reason other than the // specimen record already existing. log.debug(e); try { List<Specimen> checkResult = sh.findByBarcode(barcode); if (checkResult.size() == 1) { s = checkResult.get(0); } // Drawer number with length limit (and specimen that fails to save at over this length makes // a good canary for labels that parse very badly. String badParse = ""; if (((DrawerNameReturner) parser).getDrawerNumber().length() > MetadataRetriever .getFieldLength(Specimen.class, "DrawerNumber")) { badParse = "Parsing problem. \nDrawer number is too long: " + s.getDrawerNumber() + "\n"; } JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), filename + " " + barcode + " \n" + badParse + e.getMessage(), "Badly parsed OCR", JOptionPane.ERROR_MESSAGE); } catch (Exception err) { log.error(e); log.error(err); // TODO: Add a general error handling/inform user class. // Cause of exception is not likely to be drawer number now that drawer number // length is enforced in Specimen.setDrawerNumber, but the text returned by the parser // might indicate very poor OCR as a cause. String badParse = ((DrawerNameReturner) parser).getDrawerNumber(); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), filename + " " + barcode + "\n" + badParse + e.getMessage(), "Save Failed", JOptionPane.ERROR_MESSAGE); s = null; } } setPercentComplete(70); if (s != null) { tryMe.setSpecimen(s); } } tryMe.setRawBarcode(rawBarcode); if (isDrawerImage) { tryMe.setDrawerNumber(exifComment); } else { tryMe.setRawExifBarcode(exifComment); tryMe.setDrawerNumber(((DrawerNameReturner) parser).getDrawerNumber()); } tryMe.setRawOcr(rawOCR); tryMe.setTemplateId(defaultTemplate.getTemplateId()); tryMe.setPath(path); if (tryMe.getMd5sum() == null || tryMe.getMd5sum().length() == 0) { try { tryMe.setMd5sum(DigestUtils.md5Hex(new FileInputStream(fileToCheck))); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } } try { imageCont.persist(tryMe); } catch (SaveFailedException e) { // TODO Auto-generated catch block log.error(e.getMessage()); e.printStackTrace(); } setPercentComplete(80); if (isSpecimenImage) { SpecimenControler controler = null; try { controler = new SpecimenControler(tryMe.getSpecimen()); controler.setTargetFrame(resultFrame); } catch (NoSuchRecordException e) { // TODO Auto-generated catch block e.printStackTrace(); } SpecimenDetailsViewPane sPane = new SpecimenDetailsViewPane(tryMe.getSpecimen(), controler); resultFrame.addWest((JPanel) sPane); if (!tryMe.getRawBarcode().equals(tryMe.getRawExifBarcode())) { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_REDUNDANT_COMMENT_BARCODE) .equals("true")) { // If so configured, warn about missmatch sPane.setWarning( "Warning: Scanned Image has missmatch between barcode and comment."); } } } resultFrame.center(); } else { // found one or more matching image records. setPercentComplete(80); Singleton.getSingletonInstance().getMainFrame() .setStatusMessage("Loading existing image record."); ICImage existing = imageCont.findById(matches.get(0).getImageId()); System.out.println(existing.getRawBarcode()); existing.setRawBarcode(barcode); if (isDrawerImage) { existing.setDrawerNumber(exifComment); } else { existing.setRawExifBarcode(exifComment); } existing.setTemplateId(defaultTemplate.getTemplateId()); if (existing.getPath() == null || existing.getPath().equals("")) { existing.setPath(path); } if (existing.getDrawerNumber() == null || existing.getDrawerNumber().equals("")) { existing.setDrawerNumber(((DrawerNameReturner) parser).getDrawerNumber()); } try { imageCont.attachDirty(existing); } catch (SaveFailedException e) { // TODO Auto-generated catch block log.error(e.getMessage()); e.printStackTrace(); } if (isSpecimenImage) { SpecimenControler controler = null; try { controler = new SpecimenControler(existing.getSpecimen()); controler.setTargetFrame(resultFrame); System.out.println(existing.getSpecimen().getBarcode()); } catch (NullPointerException e1) { log.debug("Specimen barcode not set"); } catch (NoSuchRecordException e) { // Failure case log.error(e.getMessage(), e); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), filename + " " + barcode + "\n" + "Existing Image record with no Specimen Record. " + e.getMessage(), "Save Failed.", JOptionPane.ERROR_MESSAGE); } SpecimenDetailsViewPane sPane = new SpecimenDetailsViewPane(existing.getSpecimen(), controler); resultFrame.addWest((JPanel) sPane); resultFrame.center(); resultFrame.setActiveTab(ImageDisplayFrame.TAB_LABELS); resultFrame.fitPinLabels(); if (!existing.getRawBarcode().equals(existing.getRawExifBarcode())) { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_REDUNDANT_COMMENT_BARCODE) .equals("true")) { sPane.setWarning( "Warning: Scanned Image has missmatch between barcode and comment."); } } } setPercentComplete(90); } } } catch (UnreadableFileException e1) { log.error("Unable to read selected file." + e1.getMessage()); } catch (OCRReadException e) { log.error("Failed to OCR file." + e.getMessage()); } } else { System.out.println("No file selected from dialog."); } setPercentComplete(100); Singleton.getSingletonInstance().getMainFrame().setStatusMessage(""); SpecimenLifeCycle sls = new SpecimenLifeCycle(); Singleton.getSingletonInstance().getMainFrame().setCount(sls.findSpecimenCount()); Singleton.getSingletonInstance().getJobList().removeJob((RunnableJob) this); }
From source file:io.heming.accountbook.ui.MainFrame.java
private void importRecords() { final JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.addChoosableFileFilter(new AbbFileFilter()); chooser.setAcceptAllFileFilterUsed(false); int value = chooser.showOpenDialog(this); if (value == JFileChooser.APPROVE_OPTION) { // ?// w w w . j a v a2 s . c o m disableAllControls(); new Thread() { @Override public void run() { try { statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif"))); setStatusText("?..."); FacadeUtil.shutdown(); File file = chooser.getSelectedFile(); setStatusText("??..."); FileUtils.cleanDirectory(new File(Constants.DATA_DIR)); setStatusText("??..."); ZIPUtil.decompress(file, new File(Constants.HOME_DIR)); setStatusText("?..."); FacadeUtil.restart(); // ?? setStatusText("????..."); categories = categoryFacade.listBySale(); // ???? setStatusText("?..."); searchRecords(); enableAllControls(); setStatusText(""); statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png"))); JOptionPane.showMessageDialog(MainFrame.this, "???", "?", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(MainFrame.this, e.getMessage(), "", JOptionPane.ERROR_MESSAGE); } } }.start(); } }
From source file:edu.gcsc.vrl.jfreechart.JFExport.java
/** * Show dialog for exporting JFreechart object. *//* ww w . ja v a 2s . c o m*/ public void openExportDialog(JFreeChart jfreechart) { JFileChooser chooser = new JFileChooser(); String path0; File file; chooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Files", "pdf")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG Files", "jpg")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("PNG Files", "png")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("EPS Files", "eps")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG Files", "svg")); chooser.setFileFilter(new FileNameExtensionFilter("PDF Files", "pdf")); int returnVal = chooser.showSaveDialog(null); String fd = chooser.getFileFilter().getDescription(); // Get selected FileFilter String filter_extension = null; if (fd.equals("PNG Files")) { filter_extension = "png"; } if (fd.equals("SVG Files")) { filter_extension = "svg"; } if (fd.equals("JPEG Files")) { filter_extension = "jpg"; } if (fd.equals("PDF Files")) { filter_extension = "pdf"; } if (fd.equals("EPS Files")) { filter_extension = "eps"; } // Cancel if (returnVal == JFileChooser.CANCEL_OPTION) { return; } // OK if (returnVal == JFileChooser.APPROVE_OPTION) { path0 = chooser.getSelectedFile().getAbsolutePath(); //System.out.println(path0); try { file = new File(path0); // Get extension (if any) String ext = JFUtils.getExtension(file); // No extension -> use selected Filter if (ext == null) { file = new File(path0 + "." + filter_extension); ext = filter_extension; } // File exists - overwrite ? if (file.exists()) { Object[] options = { "OK", "CANCEL" }; int answer = JOptionPane.showOptionDialog(null, "File exists - Overwrite ?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (answer != JOptionPane.YES_OPTION) { return; } //System.out.println(answer+""); } // Export file export(file, jfreechart); } catch (Exception f) { // I/O - Error } } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createLoadButton() { JButton load = new JButton("Load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PersistentLayout pl = (PersistentLayout) vv.getGraphLayout(); try { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new LayoutFileFilter()); int result = chooser.showOpenDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".layout")) { absolutePath += ".layout"; }/*from w ww . j a v a 2 s .co m*/ pl.restore(absolutePath); vv.repaint(); } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error restoring layout: " + e1.getMessage()); } } }); return load; }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private void saveReferenceXML() { JFileChooser chooser = new JFileChooser( "Save as alignment xml format. YOUR EVALUATION WILL NOT BE SAVED, ONLY A COPY OF THE INPUT."); chooser.setCurrentDirectory(new File(".")); int returnVal = chooser.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile().exists() && (JOptionPane.showConfirmDialog(frame, "File already exists. Overwrite?") != JOptionPane.YES_OPTION)) { return; }/*w ww. ja v a2 s.c o m*/ frame.saveReferenceXML(chooser.getSelectedFile(), true); } }
From source file:GUI.GraphicalInterface.java
/** * Save terminal text to file on disk./* w ww .ja va 2 s .c o m*/ */ private void saveToFile() { savesJFileChooser.setApproveButtonText("Save"); savesJFileChooser.setDialogTitle("Save terminal text to file"); int returnValue = savesJFileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = savesJFileChooser.getSelectedFile(); try { String text = terminalJTextArea.getText(); BufferedWriter op = new BufferedWriter(new FileWriter(file)); /* Save output to file */ op.write(text, 0, text.length()); op.close(); /* if we have to open file after saving */ if (saveJCheckBox.isSelected() == true) { m_runtime.exec(Platform.getTextEditor() + " " + file); } statusJLabel.setText("Terminal text saved to file successfully. File path: " + file); } catch (IOException ex) { statusJLabel.setText("Error occured while saving terminal text to file."); } } else { statusJLabel.setText("Save cancelled."); } }
From source file:Compare.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);//from w w w. j a v a 2 s. co m int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); } listofFiles(myfolder); sortByName(); DefaultTableModel model = (DefaultTableModel) FileDetails.getModel(); int count = 1; for (Files filename : filenames1) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:com.seanmadden.net.fast.FastInterpretype.java
public boolean saveLogToFile() { JFileChooser jfc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt"); jfc.setFileFilter(filter);// w ww . ja va 2s .c om int retVal = jfc.showSaveDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { String filename = jfc.getSelectedFile().getPath(); mw.saveWindowToFile(filename); return true; } return false; }