List of usage examples for javax.swing JFileChooser setDialogTitle
@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle)
JFileChooser
window's title bar. From source file:tax.MainForm.java
private void excelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excelActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String folderName = chooser.getSelectedFile().getAbsolutePath(); String data[][] = null;//ww w . jav a 2 s . c o m data = Util.arrayFromTablename(curTable); List month = new ArrayList(); List receipts = new ArrayList(); month.add(Util.tablenameToDate(curTable)); Map beans = new HashMap(); beans.put("month", month); for (int i = 0; i < data.length; i++) { receipts.add(new Receipt(data[i][0], Float.parseFloat(data[i][1]), data[i][2], data[i][3])); } beans.put("receipts", receipts); XLSTransformer transformer = new XLSTransformer(); transformer.markAsFixedSizeCollection("month"); transformer.markAsFixedSizeCollection("receipts"); try { FileUtils.forceMkdir(new File(folderName + "/" + curYear + "/excel")); transformer.transformXLS("etc/excel.xls", beans, folderName + "/" + curYear + "/excel/" + curMonth + ". " + Util.months[curMonth - 1] + ".xls"); } catch (IOException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (ParsePropertyException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidFormatException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } new Completed("<html> ?<br> .</html>") .setVisible(true); } }
From source file:tax.MainForm.java
public void printYear(int inYear) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String folderName = chooser.getSelectedFile().getAbsolutePath(); String output = "\u0009\u0009\u0009\n" + "-----------------------------------\n"; float totalSum = 0; Connection c = null;/*w w w . jav a2 s . com*/ Statement stmt = null; try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:etc/tax.sqlite"); c.setAutoCommit(false); stmt = c.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM main.sqlite_master WHERE type='table';"); while (rs.next()) { String name = rs.getString("name"); if (!name.startsWith("t")) continue; int monthYear[] = new int[2]; monthYear = Util.tablenameToMonthAndYear(name); int month = monthYear[0]; int year = monthYear[1]; float monthlySum = 0; if (inYear != year) continue; String data[][] = null; data = Util.arrayFromTablename(name); for (int i = 0; i < data.length; i++) { Float price = Float.parseFloat(data[i][1]); monthlySum += price; } totalSum += monthlySum; String sumS = Util.formatSum(monthlySum); String tabSpace; if (Util.months[month - 1].length() >= 8) tabSpace = "\u0009\u0009"; else tabSpace = "\u0009\u0009\u0009"; output += Util.months[month - 1] + tabSpace + sumS + "\n"; try { FileUtils.forceMkdir(new File(folderName + "/" + year + "/pdf")); Printer.createPdf( folderName + "/" + year + "/pdf/" + month + ". " + Util.months[month - 1] + ".pdf", name); } catch (IOException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } } output += "-----------------------------------\n" + "?\u0009\u0009\u0009" + Util.formatSum(totalSum) + "\n"; FileUtils.write(new File(folderName + "/" + inYear + "/?.txt"), output, "UTF-8"); rs.close(); stmt.close(); c.close(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } new Completed("<html> ? ?<br> .</html>") .setVisible(true); } }
From source file:tax.MainForm.java
public void exportExcelYear(int inYear) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(" "); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String folderName = chooser.getSelectedFile().getAbsolutePath(); String output = "\u0009\u0009\u0009\n" + "-----------------------------------\n"; float totalSum = 0; Connection c = null;/* ww w. j a va 2 s.com*/ Statement stmt = null; try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:etc/tax.sqlite"); c.setAutoCommit(false); stmt = c.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM main.sqlite_master WHERE type='table';"); while (rs.next()) { String name = rs.getString("name"); if (!name.startsWith("t")) continue; int monthYear[] = new int[2]; monthYear = Util.tablenameToMonthAndYear(name); int month = monthYear[0]; int year = monthYear[1]; float monthlySum = 0; if (inYear != year) continue; String data[][] = null; data = Util.arrayFromTablename(name); List monthL = new ArrayList(); List receipts = new ArrayList(); monthL.add(Util.tablenameToDate(name)); Map beans = new HashMap(); beans.put("month", monthL); for (int i = 0; i < data.length; i++) { Float price = Float.parseFloat(data[i][1]); receipts.add(new Receipt(data[i][0], price, data[i][2], data[i][3])); monthlySum += price; } totalSum += monthlySum; String sumS = Util.formatSum(monthlySum); String tabSpace; if (Util.months[month - 1].length() >= 8) tabSpace = "\u0009\u0009"; else tabSpace = "\u0009\u0009\u0009"; output += Util.months[month - 1] + tabSpace + sumS + "\n"; beans.put("receipts", receipts); XLSTransformer transformer = new XLSTransformer(); transformer.markAsFixedSizeCollection("month"); transformer.markAsFixedSizeCollection("receipts"); try { FileUtils.forceMkdir(new File(folderName + "/" + year + "/excel")); transformer.transformXLS("etc/excel.xls", beans, folderName + "/" + year + "/excel/" + month + ". " + Util.months[month - 1] + ".xls"); } catch (IOException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (ParsePropertyException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidFormatException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } } output += "-----------------------------------\n" + "?\u0009\u0009\u0009" + Util.formatSum(totalSum) + "\n"; FileUtils.write(new File(folderName + "/" + inYear + "/?.txt"), output, "UTF-8"); rs.close(); stmt.close(); c.close(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } new Completed("<html> ?<br> .</html>") .setVisible(true); } }
From source file:terminotpad.MainFrame.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed // TODO add your handling code here: String content;// w w w . j a v a 2 s . c o m String destFile; int ext = 0; content = rSyntax.getText(); // destFile = "src/doc/test.txt"; while (ext == 0) { JFileChooser dlg = new JFileChooser(); dlg.addChoosableFileFilter(new MessageFilter()); dlg.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG); dlg.setDialogTitle("Enregistrer sous ..."); int ret = dlg.showOpenDialog(this); File fileReturn; // Traite le contenu du fichier if (ret == JFileChooser.APPROVE_OPTION) { fileReturn = dlg.getSelectedFile(); destFile = fileReturn.toString(); System.out.println(destFile); Fichier file = new Fichier(destFile, content); file.fileWrite(); String reg = "[.][a-zA-Z0-9]{3}$"; if (file.getExtend().matches(reg)) { ext = 1; } localFile.setFile(file.getFile()); } } }
From source file:test.integ.be.fedict.performance.TestLoadResults.java
@Test public void testLoad() throws Exception { File resultsFile = null;/* www . j av a 2 s . com*/ JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select results file..."); int result = fileChooser.showOpenDialog(new JFrame()); if (JFileChooser.APPROVE_OPTION == result) { resultsFile = fileChooser.getSelectedFile(); } if (null != resultsFile) { PerformanceResultsData data = PerformanceResultDialog.readResults(resultsFile); PerformanceResultDialog dialog = new PerformanceResultDialog(data); while (dialog.isVisible()) { Thread.sleep(1000); } } }
From source file:ui.FtpDialog.java
private void uploadFileBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadFileBtActionPerformed if (connected) { JFileChooser uploadFileChooser = new JFileChooser(); uploadFileChooser.setPreferredSize(new Dimension(650, 450)); File rootDirectory = new File("C:\\"); uploadFileChooser/* ww w .ja v a 2 s . co m*/ .setCurrentDirectory(uploadFileChooser.getFileSystemView().getParentDirectory(rootDirectory)); uploadFileChooser.setDialogTitle("File to upload"); int result = uploadFileChooser.showOpenDialog(this); switch (result) { case JFileChooser.APPROVE_OPTION: selectedFile = uploadFileChooser.getSelectedFile(); Trace.trc("File to upload: " + selectedFile.getName() + " File size: " + FileUtils.byteCountToDisplaySize(selectedFile.length())); if (connected) { if (!selectedFile.equals(null)) { try { input = new FileInputStream(selectedFile); } catch (IOException e) { e.printStackTrace(); } pb = new ProgressBar(); pb.execute(); uploadFileChooser.setVisible(false); } else { JOptionPane.showMessageDialog(rootFrame, "No file to upload has been chosen!", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error", JOptionPane.ERROR_MESSAGE); } break; case JFileChooser.CANCEL_OPTION: Trace.trc("Closing file chooser dialog"); break; case JFileChooser.ERROR_OPTION: Trace.trc("An error occured"); break; } } else { JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:updater.UpdaterGUI.java
@SuppressWarnings("resource") public UpdaterGUI() { try {/*from ww w. j av a 2 s. c om*/ URL url1 = new URL( "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-version.txt"); ReadableByteChannel obj1 = Channels.newChannel(url1.openStream()); FileOutputStream outputstream1 = new FileOutputStream(".release-version.txt"); outputstream1.getChannel().transferFrom(obj1, 0, Long.MAX_VALUE); URL url2 = new URL( "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-changelog.txt"); ReadableByteChannel obj2 = Channels.newChannel(url2.openStream()); FileOutputStream outputstream2 = new FileOutputStream(".release-changelog.txt"); outputstream2.getChannel().transferFrom(obj2, 0, Long.MAX_VALUE); FileReader file = new FileReader(".release-version.txt"); BufferedReader reader = new BufferedReader(file); String DownloadedString = reader.readLine(); File file2 = new File(".release-version.txt"); if (file2.exists() && !file2.isDirectory()) { file2.delete(); } AvailableUpdate = Double.parseDouble(DownloadedString); InputStreamReader reader2 = new InputStreamReader( getClass().getResourceAsStream("/others/app-version.txt")); String tmp = IOUtils.toString(reader2); ApplicationVersion = Double.parseDouble(tmp); } catch (Exception e) { e.printStackTrace(); } setIconImage(Toolkit.getDefaultToolkit().getImage(UpdaterGUI.class.getResource("/graphics/Icon.png"))); setResizable(false); setType(Type.UTILITY); setTitle("Updater"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 430, 415); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblApplicationVersion = new JLabel("App Version: v" + ApplicationVersion); lblApplicationVersion.setBounds(12, 12, 222, 15); contentPane.add(lblApplicationVersion); JLabel lblUpdateVersion = new JLabel("Update Version: v" + AvailableUpdate); lblUpdateVersion.setBounds(12, 30, 222, 15); contentPane.add(lblUpdateVersion); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(0, 51, 422, 281); contentPane.add(scrollPane); JTextArea UpdateChangelogViewer = new JTextArea(); scrollPane.setViewportView(UpdateChangelogViewer); JButton btnDownload = new JButton("Download"); btnDownload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFrame parentFrame = new JFrame(); JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip Files", "zip"); fileChooser.setFileFilter(filter); fileChooser.setDialogTitle("Save as"); int userSelection = fileChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); try { URL url = new URL("https://github.com/kvsjxd/Droid-PC-Suite/releases/download/" + AvailableUpdate + "/DPCS.v" + AvailableUpdate + ".Stable.zip"); ReadableByteChannel obj = Channels.newChannel(url.openStream()); FileOutputStream outputstream = new FileOutputStream(fileToSave.getAbsolutePath() + ".zip"); outputstream.getChannel().transferFrom(obj, 0, Long.MAX_VALUE); JOptionPane.showMessageDialog(null, "Download complete!\nPlease delete this version and extract the downloaded zip\nwhich is saved at " + fileToSave.getAbsolutePath() + ".zip"); } catch (Exception e) { e.printStackTrace(); } } } }); btnDownload.setBounds(140, 344, 117, 25); contentPane.add(btnDownload); try { FileReader reader3 = new FileReader(new File(".release-changelog.txt")); UpdateChangelogViewer.read(reader3, ""); File file3 = new File(".release-changelog.txt"); if (file3.exists() && !file3.isDirectory()) { file3.delete(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Exports the results to a file//from w ww . j a v a 2s . c o m * * @param model * The model for the current results * @param fileType * The export file type */ private void chooseFileForSave(TableModel model, int fileType) { final JFileChooser chooser = new JFileChooser(); int returnVal; chooser.setDialogTitle(Resources.getString("dlgSaveDataTitle")); chooser.setApproveButtonText(Resources.getString("dlgSaveDataButton")); chooser.setApproveButtonMnemonic(Resources.getChar("dlgSaveDataButtonMnemonic")); if (latestFileDirectory != null) { if (latestFileDirectory.isDirectory()) { chooser.setCurrentDirectory(latestFileDirectory); } else if (latestFileDirectory.getParentFile().isDirectory()) { chooser.setCurrentDirectory(latestFileDirectory.getParentFile()); } } returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { latestFileDirectory = chooser.getSelectedFile().getParentFile(); switch (fileType) { case FILE_EXPORT_CSV: saveResultAsCSV(model, chooser.getSelectedFile().getAbsoluteFile()); break; case FILE_EXPORT_TRIPLES: saveResultsAsTriples(model, chooser.getSelectedFile().getAbsoluteFile()); break; default: throw new IllegalArgumentException("Unknown file type mode for export: " + fileType); } } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Open or create a SQL statement file.//from w ww . j av a2 s . c om */ private void openSQLFile() { JFileChooser fileMenu; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenSQLFile; int returnVal; chosenSQLFile = null; // Save current information, including SQL Statements saveConfig(); // Allow user to choose/create new file for SQL Statements fileMenu = new JFileChooser(new File(queryFilename)); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("QUERY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileMenu.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileMenu.setFileFilter(defaultFileFilter); } else if (latestChosenQueryFileFilterDescription != null && latestChosenQueryFileFilterDescription.startsWith("All")) { fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileMenu.setFileFilter(preferredFileFilter); } fileMenu.setSelectedFile(new File(queryFilename)); fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle")); fileMenu.setDialogType(JFileChooser.OPEN_DIALOG); fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.setMultiSelectionEnabled(false); if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { chosenSQLFile = fileMenu.getSelectedFile(); // Adjust file suffix if necessary final FileFilter fileFilter = fileMenu.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileMenu.getFileFilter().accept(chosenSQLFile)) { chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile); } if (!chosenSQLFile.exists()) { returnVal = JOptionPane.showConfirmDialog(this, Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()), Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (returnVal == JOptionPane.NO_OPTION) { querySelection.removeAllItems(); queryText.setText(""); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } else if (returnVal == JOptionPane.CANCEL_OPTION) { chosenSQLFile = null; } } else { setQueryFilename(chosenSQLFile.getAbsolutePath()); querySelection.removeAllItems(); queryText.setText(""); loadCombo(querySelection, queryFilename); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } } try { latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } if (chosenSQLFile != null) { setQueryFilename(chosenSQLFile.getAbsolutePath()); saveConfig(); } }
From source file:verdandi.ui.action.ImportPluginAction.java
/** * Ask the import file from the user/*from ww w. j a v a2 s .c om*/ */ private File getFile() { File res = null; Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get(KEY_CWD, System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".jar") || f.isDirectory(); } @Override public String getDescription() { return RC.getString("pluginimportaction.filechooser.jarfilter.description"); } }); chooser.setDialogTitle(RC.getString("pluginimportaction.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return null; } res = chooser.getSelectedFile(); prefs.put("import.dir", res.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } return res; }