// Raises the Save As dialog to have the user identify the location to save groups of things. public File determineSaveLocation(String dialogTitle, String defaultFolderName) { String defaultPath = this.getFileChooser().getCurrentDirectory().getPath(); if (!WWUtil.isEmpty(defaultPath)) defaultPath += File.separatorChar + defaultFolderName; File outFile; while (true) { this.getFileChooser().setDialogTitle(dialogTitle); this.getFileChooser().setSelectedFile(new File(defaultPath)); this.getFileChooser().setMultiSelectionEnabled(false); this.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int status = this.getFileChooser().showSaveDialog(this.getFrame()); if (status != JFileChooser.APPROVE_OPTION) return null; outFile = this.getFileChooser().getSelectedFile(); if (outFile == null) { this.showMessageDialog("No location selected", "No Selection", JOptionPane.ERROR_MESSAGE); continue; } break; } if (!outFile.exists()) //noinspection ResultOfMethodCallIgnored outFile.mkdir(); return outFile; }
public int showConfirmFileOverwriteDialog(File outFile) { return JOptionPane.showConfirmDialog( this.getFrame(), "Replace existing file\n" + outFile.getName() + "?", "Overwrite Existing File?", JOptionPane.YES_NO_CANCEL_OPTION); }
public void openLink(String link) { if (WWUtil.isEmpty(link)) return; try { try { // See if the link is a URL, and invoke the browser if it is URL url = new URL(link.replace(" ", "%20")); Desktop.getDesktop().browse(url.toURI()); return; } catch (MalformedURLException ignored) { // just means that the link is not a URL } // It's not a URL, so see if it's a file and invoke the desktop to open it if it is. File file = new File(link); if (file.exists()) { Desktop.getDesktop().open(new File(link)); return; } String message = "Cannot open resource. It's not a valid file or URL."; Util.getLogger().log(Level.SEVERE, message); this.showErrorDialog(null, "No Reconocido V\u00ednculo", message); } catch (UnsupportedOperationException e) { String message = "Unable to open resource.\n" + link + (e.getMessage() != null ? "\n" + e.getMessage() : ""); Util.getLogger().log(Level.SEVERE, message, e); this.showErrorDialog(e, "Error Opening Resource", message); } catch (IOException e) { String message = "I/O error while opening resource.\n" + link + (e.getMessage() != null ? ".\n" + e.getMessage() : ""); Util.getLogger().log(Level.SEVERE, message, e); this.showErrorDialog(e, "I/O Error", message); } catch (Exception e) { String message = "Error attempting to open resource.\n" + link + (e.getMessage() != null ? "\n" + e.getMessage() : ""); Util.getLogger().log(Level.SEVERE, message); this.showMessageDialog(message, "Error Opening Resource", JOptionPane.ERROR_MESSAGE); } }
public File chooseOutputFile(String defaultName, String suffixWithoutDot, String dialogTitle) { String defaultPath = this.getFileChooser().getCurrentDirectory().getPath(); if (defaultName != null && defaultName.length() > 0) defaultPath += File.separatorChar + defaultName; if (suffixWithoutDot != null && suffixWithoutDot.length() > 0) defaultPath += "." + suffixWithoutDot; if (dialogTitle == null || dialogTitle.length() == 0) dialogTitle = "Choose Save Location"; this.getFileChooser().setDialogTitle(dialogTitle); this.getFileChooser().setSelectedFile(new File(defaultPath)); this.getFileChooser().setMultiSelectionEnabled(false); while (true) { int status = this.getFileChooser().showSaveDialog(this.getFrame()); if (status != JFileChooser.APPROVE_OPTION) return null; File outFile = this.getFileChooser().getSelectedFile(); if (outFile == null) { this.showMessageDialog("No location selected", "No Selection", JOptionPane.ERROR_MESSAGE); continue; } if (suffixWithoutDot != null && suffixWithoutDot.length() > 0) outFile = Util.ensureFileSuffix(outFile, suffixWithoutDot); if (outFile.exists()) { status = this.showConfirmFileOverwriteDialog(outFile); if (status == JOptionPane.NO_OPTION) continue; if (status == JOptionPane.CANCEL_OPTION) return null; } return outFile; } }