List of usage examples for javax.swing JFileChooser OPEN_DIALOG
int OPEN_DIALOG
To view the source code for javax.swing JFileChooser OPEN_DIALOG.
Click Source Link
JFileChooser
supports an "Open" file operation. From source file:org.executequery.gui.drivers.AbstractDriverPanel.java
public void browseDrivers(ActionEvent e) { if (databaseDriver.isDefaultSunOdbc()) { return;/* w w w . j a v a 2s . c o m*/ } FileSelector jarFiles = new FileSelector(new String[] { "jar" }, getString("AbstractDriverPanel.javaArchiveFiles")); FileSelector zipFiles = new FileSelector(new String[] { "zip" }, getString("AbstractDriverPanel.zipArchiveFiles")); final FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(zipFiles); fileChooser.addChoosableFileFilter(jarFiles); fileChooser.setDialogTitle(getString("AbstractDriverPanel.selectJdbcDrivers")); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(true); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), getString("AbstractDriverPanel.select")); if (result == JFileChooser.CANCEL_OPTION) { return; } ThreadUtils.startWorker(new Runnable() { public void run() { try { GUIUtilities.showWaitCursor(); File[] files = fileChooser.getSelectedFiles(); for (int i = 0; i < files.length; i++) { String path = files[i].getAbsolutePath(); if (!jarPathListModel.contains(path)) { jarPathListModel.addElement(path); } } databaseDriver.setPath(jarPathsFormatted()); populateDriverClassCombo(); } finally { GUIUtilities.showNormalCursor(); } } }); }
From source file:org.executequery.gui.ExecuteSqlScriptPanel.java
public void browse() { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Select Export File Path"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;/*from ww w.java 2s .c om*/ } File file = fileChooser.getSelectedFile(); fileNameField.setText(file.getAbsolutePath()); }
From source file:org.executequery.gui.ExportResultSetPanel.java
public void browse() { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Select Export File Path"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;//from w ww . ja v a2 s .c om } File file = fileChooser.getSelectedFile(); if (file.exists()) { result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?"); if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) { browse(); return; } } fileNameField.setText(file.getAbsolutePath()); }
From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java
public void saveToFile(ActionEvent e) { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Select Output File Path"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;/*ww w . j a v a 2 s . c om*/ } File file = fileChooser.getSelectedFile(); if (file.exists()) { result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?"); if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) { saveToFile(e); return; } } try { FileUtils.writeFile(file.getAbsolutePath(), readOnlyTextArea.getText()); } catch (IOException e1) { GUIUtilities.displayErrorMessage("Error writing output pane contents to file.\n" + e1.getMessage()); } }
From source file:org.executequery.gui.scriptgenerators.GenerateScriptsPanelThree.java
public void actionPerformed(ActionEvent e) { FileSelector textFiles = new FileSelector(new String[] { "txt" }, "Text files"); FileSelector sqlFiles = new FileSelector(new String[] { "sql" }, "SQL files"); FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(textFiles); fileChooser.addChoosableFileFilter(sqlFiles); fileChooser.setDialogTitle("Select File..."); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;//from ww w .jav a 2 s .c om } String path = fileChooser.getSelectedFile().getAbsolutePath(); if (!path.toUpperCase().endsWith(".SQL")) { path += ".sql"; } pathField.setText(path); }
From source file:org.executequery.gui.text.TextUtilities.java
public static void insertFromFile(JTextComponent textComponent) { StringBuffer buf = null;//from w w w . j a v a 2 s. co m String text = null; FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setDialogTitle("Insert from file"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Insert"); if (result == JFileChooser.CANCEL_OPTION) return; File file = fileChooser.getSelectedFile(); try { FileInputStream input = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); buf = new StringBuffer(10000); char newLine = '\n'; while ((text = reader.readLine()) != null) buf.append(text).append(newLine); reader.close(); reader = null; input.close(); input = null; int index = textComponent.getCaretPosition(); StringBuffer sb = new StringBuffer(textComponent.getText()); sb.insert(index, buf.toString()); textComponent.setText(sb.toString()); textComponent.setCaretPosition(index + buf.length()); } catch (OutOfMemoryError e) { buf = null; text = null; System.gc(); GUIUtilities.displayErrorMessage("Out of Memory.\nThe file is " + "too large to\nopen for viewing."); } catch (IOException e) { e.printStackTrace(); StringBuffer sb = new StringBuffer(); sb.append("An error occurred opening the selected file.").append("\n\nThe system returned:\n") .append(e.getMessage()); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } }
From source file:org.geopublishing.geopublisher.GpUtil.java
/** * Performs a file OPEN choose as a fallback * // w w w. j a v a 2 s.co m * @param parent * component for the dialog (can be {@code null}) * @param startFolder * start folder for the chooser (if {@code null} "/" is used) * @param filter * defines which files can be selected. Only the last filter in * the list will be offered due to limitations * @return {@code null} if the dialog was not approved */ public static File chooseFileOpenFallback(Component parent, File startFolder, String title, FileExtensionFilter... filters) { if (startFolder == null) startFolder = new File("/"); if (startFolder.isFile()) startFolder = startFolder.getParentFile(); JFileChooser chooser = new JFileChooser(startFolder); chooser.setDialogType(JFileChooser.OPEN_DIALOG); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(filters[0].toJFileChooserFilter()); } if (title != null) chooser.setDialogTitle(title); int ret = chooser.showOpenDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
From source file:org.kepler.gui.kar.DeleteArchiveAction.java
/** * Invoked when an action occurs./*from w ww .j a v a2s . c o m*/ * *@param e * ActionEvent */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); File karFile = null; if (archiveFile != null) { karFile = archiveFile; } else { // ask the user what file to delete // Create a file filter that accepts .kar files. ExtensionFilenameFilter filter = new ExtensionFilenameFilter(".kar", "kar"); // Avoid white boxes in file chooser, see // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801 JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix(); Color background = null; PtFileChooser chooser = null; try { background = jFileChooserBugFix.saveBackground(); chooser = new PtFileChooser(parent, "Choose archive", JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(LocalRepositoryManager.getInstance().getSaveRepository()); chooser.addChoosableFileFilter(filter); int returnVal = chooser.showDialog(parent, "Delete"); if (returnVal == JFileChooser.APPROVE_OPTION) { // process the given kar file karFile = chooser.getSelectedFile(); } } finally { jFileChooserBugFix.restoreBackground(background); } } if (karFile != null) { int choice = JOptionPane.showConfirmDialog(parent, "Delete this kar from the library and from your disk. Continue?", "", JOptionPane.YES_NO_OPTION); if (choice == JOptionPane.YES_OPTION) { try { deleteKAR(karFile); } catch (Exception exc) { exc.printStackTrace(); } } } }
From source file:org.kepler.gui.kar.OpenArchiveAction.java
/** * Attempt to open the KAR. Any exception that is generated can be * retrieved with getOpenException()./*from w ww. j a va 2 s .c o m*/ * * @param e ActionEvent */ public void actionPerformed(ActionEvent e) { // must call this first... super.actionPerformed(e); actionEvent = e; // ...before calling this: // NamedObj target = super.getTarget(); File karFile = null; if (archiveFileToOpen != null) { karFile = archiveFileToOpen; } else { // Create a file filter that accepts .kar files. ExtensionFilenameFilter filter = new ExtensionFilenameFilter(new String[] { "kar", "xml", "moml" }); // Avoid white boxes in file chooser, see // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801 JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix(); Color background = null; PtFileChooser chooser = null; try { background = jFileChooserBugFix.saveBackground(); chooser = new PtFileChooser(parent, "Open", JFileChooser.OPEN_DIALOG); if (parent instanceof BasicGraphFrame && updateHistoryAndLastDirectory) { chooser.setCurrentDirectory(((BasicGraphFrame) parent).getLastDirectory()); } chooser.addChoosableFileFilter(filter); int returnVal = chooser.showDialog(parent, "Open"); if (returnVal == JFileChooser.APPROVE_OPTION) { // process the given file karFile = chooser.getSelectedFile(); } } finally { jFileChooserBugFix.restoreBackground(background); } } if (karFile != null) { String karFileName = karFile.getName().toLowerCase(); if (karFileName.endsWith(".kar")) { //System.out.println("DEBUG: Opening KAR"); try { openKAR(karFile, false, updateHistoryAndLastDirectory); } catch (Exception exc) { _openException = exc; } } else if (karFileName.endsWith(".xml") || karFileName.endsWith(".moml")) { //System.out.println("DEBUG: Opening XML"); _open(karFile); } } }
From source file:org.kepler.gui.kar.RefreshFolderAction.java
/** * Invoked when an action occurs.// w w w . ja v a 2s.c om * *@param e * ActionEvent */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); File folder = null; if (_folder != null) { folder = _folder; } else { // Avoid white boxes in file chooser, see // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3801 JFileChooserBugFix jFileChooserBugFix = new JFileChooserBugFix(); Color background = null; PtFileChooser chooser = null; try { background = jFileChooserBugFix.saveBackground(); // ask the user what file to refresh chooser = new PtFileChooser(parent, "Choose folder", JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(LocalRepositoryManager.getInstance().getSaveRepository()); int returnVal = chooser.showDialog(parent, "Refresh"); if (returnVal == JFileChooser.APPROVE_OPTION) { // process the given kar file folder = chooser.getSelectedFile(); } } finally { jFileChooserBugFix.restoreBackground(background); } } if (folder != null) { System.out.println("Under Construction: " + folder.toString() + " was not refreshed."); } LocalRepositoryManager lrm = LocalRepositoryManager.getInstance(); //lrm.refreshFolderModelForFolder(folder); }