List of usage examples for javax.swing JFileChooser setAcceptAllFileFilterUsed
@BeanProperty(preferred = true, description = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.") public void setAcceptAllFileFilterUsed(boolean b)
AcceptAll FileFilter
is used as an available choice in the choosable filter list. From source file:MyFormApp.java
private void AddbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddbuttonMouseClicked // TODO add your handling code here: //? ?/*from w w w . j a v a2s .c o m*/ JFileChooser fileChooser = new JFileChooser(); //? fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf"));//?pdf fileChooser.setAcceptAllFileFilterUsed(false); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) {//???? File selectedFile = fileChooser.getSelectedFile(); try { pdfToimage(selectedFile); //??? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(selectedFile.getName()); //?? File source = new File("" + selectedFile); File dest = new File(PATH + selectedFile.getName()); //copy file conventional way using Stream long start = System.nanoTime(); //copy files using apache commons io start = System.nanoTime(); int a = i + 1; String imagename = FilenameUtils.removeExtension(selectedFile.getName()); model.addElement(new Book(selectedFile.getName(), "" + a, imagename, PATH)); //list i = i + 1; jList2.setModel(model); jList2.setCellRenderer(new BookRenderer()); try { copyFileUsingApacheCommonsIO(source, dest); //? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Time taken by Apache Commons IO Copy = " + (System.nanoTime() - start)); } }
From source file:pl.dpbz.poid.zadanie3.GUI.java
private String readSoundFile() { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("WAV sounds", "wav"); fc.addChoosableFileFilter(filter);// w w w .j a v a2 s .c o m int returnVal = fc.showOpenDialog(this); String path = fc.getSelectedFile().getAbsolutePath(); System.out.println("path: " + path); return path; }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected File promptUserForNewFile(String wavePath) { JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP3s and WAVs", "mp3", "wav"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);//from www.ja v a2s. c o m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { DefaultMutableTreeNode selectedFile = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); //Strip caps and spaces out of filenames. The item sound parser seems to have trouble with them. String destFileName = chosenFile.getFileName().toString().toLowerCase().replace(" ", "_"); Path destPath = Paths.get(installDir, "/dota/sound/" + getCustomSoundPathString() + destFileName); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); String waveString = selectedFile.getUserObject().toString(); int startIndex = -1; int endIndex = -1; if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); waveString = waveString.replace(waveStringFilePath, "\"" + getCustomSoundPathString() + destFileName + "\""); selectedFile.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java
public ExistingFileChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new ExistingFileChooserDialog(findRegisteredWindowIfAny(), appProps, SOURCE_FOLDER) {/*from ww w . j a v a 2s. c om*/ @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setDialogTitle(Messages.get("phrase.selectFileToEncrypt")); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter(notEncryptedFiles); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); } private FileFilter notEncryptedFiles = new FileFilter() { @Override public boolean accept(File f) { return !DecryptOnePm.isItLooksLikeYourSourceFile(f.getAbsolutePath()); } @Override public String getDescription() { return text("phrase.allExceptEncrypted"); } }; }; } return sourceFileChooser; }
From source file:hspc.submissionsprogram.AppDisplay.java
AppDisplay() { this.setTitle("Dominion High School Programming Contest"); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.setResizable(false); WindowListener exitListener = new WindowAdapter() { @Override//from www. j a va 2s . c o m public void windowClosing(WindowEvent e) { System.exit(0); } }; this.addWindowListener(exitListener); JTabbedPane pane = new JTabbedPane(); this.add(pane); JPanel submitPanel = new JPanel(null); submitPanel.setPreferredSize(new Dimension(500, 500)); UIManager.put("FileChooser.readOnly", true); JFileChooser fileChooser = new JFileChooser(); fileChooser.setBounds(0, 0, 500, 350); fileChooser.setVisible(true); FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java files (*.java)", "java"); fileChooser.setFileFilter(javaFilter); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setControlButtonsAreShown(false); submitPanel.add(fileChooser); JSeparator separator1 = new JSeparator(); separator1.setBounds(12, 350, 476, 2); separator1.setForeground(new Color(122, 138, 152)); submitPanel.add(separator1); JLabel problemChooserLabel = new JLabel("Problem:"); problemChooserLabel.setBounds(12, 360, 74, 25); submitPanel.add(problemChooserLabel); String[] listOfProblems = Main.Configuration.get("problem_names") .split(Main.Configuration.get("name_delimiter")); JComboBox problems = new JComboBox<>(listOfProblems); problems.setBounds(96, 360, 393, 25); submitPanel.add(problems); JButton submit = new JButton("Submit"); submit.setBounds(170, 458, 160, 30); submit.addActionListener(e -> { try { File file = fileChooser.getSelectedFile(); try { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost(Main.Configuration.get("submit_url")); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("accountID", Main.accountID, ContentType.TEXT_PLAIN); builder.addTextBody("problem", String.valueOf(problems.getSelectedItem()), ContentType.TEXT_PLAIN); builder.addBinaryBody("submission", file, ContentType.APPLICATION_OCTET_STREAM, file.getName()); HttpEntity multipart = builder.build(); uploadFile.setEntity(multipart); CloseableHttpResponse response = httpClient.execute(uploadFile); HttpEntity responseEntity = response.getEntity(); String inputLine; BufferedReader br = new BufferedReader(new InputStreamReader(responseEntity.getContent())); try { if ((inputLine = br.readLine()) != null) { int rowIndex = Integer.parseInt(inputLine); new ResultWatcher(rowIndex); } br.close(); } catch (IOException ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } } catch (NullPointerException ex) { JOptionPane.showMessageDialog(this, "No file selected.\nPlease select a java file.", "Error", JOptionPane.WARNING_MESSAGE); } }); submitPanel.add(submit); JPanel clarificationsPanel = new JPanel(null); clarificationsPanel.setPreferredSize(new Dimension(500, 500)); cList = new JList<>(); cList.setBounds(12, 12, 476, 200); cList.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)), BorderFactory.createEmptyBorder(8, 8, 8, 8))); cList.setBackground(new Color(254, 254, 255)); clarificationsPanel.add(cList); JButton viewC = new JButton("View"); viewC.setBounds(12, 224, 232, 25); viewC.addActionListener(e -> { if (cList.getSelectedIndex() != -1) { int id = Integer.parseInt(cList.getSelectedValue().split("\\.")[0]); clarificationDatas.stream().filter(data -> data.getId() == id).forEach( data -> new ClarificationDisplay(data.getProblem(), data.getText(), data.getResponse())); } }); clarificationsPanel.add(viewC); JButton refreshC = new JButton("Refresh"); refreshC.setBounds(256, 224, 232, 25); refreshC.addActionListener(e -> updateCList(true)); clarificationsPanel.add(refreshC); JSeparator separator2 = new JSeparator(); separator2.setBounds(12, 261, 476, 2); separator2.setForeground(new Color(122, 138, 152)); clarificationsPanel.add(separator2); JLabel problemChooserLabelC = new JLabel("Problem:"); problemChooserLabelC.setBounds(12, 273, 74, 25); clarificationsPanel.add(problemChooserLabelC); JComboBox problemsC = new JComboBox<>(listOfProblems); problemsC.setBounds(96, 273, 393, 25); clarificationsPanel.add(problemsC); JTextArea textAreaC = new JTextArea(); textAreaC.setLineWrap(true); textAreaC.setWrapStyleWord(true); textAreaC.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)), BorderFactory.createEmptyBorder(8, 8, 8, 8))); textAreaC.setBackground(new Color(254, 254, 255)); JScrollPane areaScrollPane = new JScrollPane(textAreaC); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setBounds(12, 312, 477, 134); clarificationsPanel.add(areaScrollPane); JButton submitC = new JButton("Submit Clarification"); submitC.setBounds(170, 458, 160, 30); submitC.addActionListener(e -> { if (textAreaC.getText().length() > 2048) { JOptionPane.showMessageDialog(this, "Clarification body is too long.\nMaximum of 2048 characters allowed.", "Error", JOptionPane.WARNING_MESSAGE); } else if (textAreaC.getText().length() < 20) { JOptionPane.showMessageDialog(this, "Clarification body is too short.\nClarifications must be at least 20 characters, but no more than 2048.", "Error", JOptionPane.WARNING_MESSAGE); } else { Connection conn = null; PreparedStatement stmt = null; try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"), Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass")); String sql = "INSERT INTO clarifications (team, problem, text) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(sql); stmt.setInt(1, Integer.parseInt(String.valueOf(Main.accountID))); stmt.setString(2, String.valueOf(problemsC.getSelectedItem())); stmt.setString(3, String.valueOf(textAreaC.getText())); textAreaC.setText(""); stmt.executeUpdate(); stmt.close(); conn.close(); updateCList(false); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } } } }); clarificationsPanel.add(submitC); pane.addTab("Submit", submitPanel); pane.addTab("Clarifications", clarificationsPanel); Timer timer = new Timer(); TimerTask updateTask = new TimerTask() { @Override public void run() { updateCList(false); } }; timer.schedule(updateTask, 10000, 10000); updateCList(false); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
private void exportReport() { JFileChooser jfc = new JFileChooser(); jfc.setAcceptAllFileFilterUsed(false); jfc.setDialogTitle("Export CRAM Module"); FileFilter filter = new FileNameExtensionFilter("Word Document", "docx"); jfc.setFileFilter(filter);//from w ww .j a v a 2s . co m jfc.setSelectedFile(new File(module.getModuleName() + ".docx")); //Open the dialog and wait for the user to provide a name for the file int returnVal = jfc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); //Add the file extension if (!jfc.getSelectedFile().getAbsolutePath().endsWith(".docx")) { file = new File(jfc.getSelectedFile() + ".docx"); } try { this.setCursor(WAIT); Report report = new Report(module); report.save(file); } catch (Docx4JException ex) { LOGGER.log(Level.SEVERE, "Failed to export report", ex); JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "Failed to export report", JOptionPane.ERROR_MESSAGE); } finally { this.setCursor(Cursor.getDefaultCursor()); } } }
From source file:firmadigital.Firma.java
private void cmdExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarActionPerformed JFileChooser fileChooser = new JFileChooser(); txtUbicacion.setText(""); lblNombreArchivo.setText(""); lblRutaArchivo.setText(""); String signFileName = txtUbicacion.getText(); File directory = new File(signFileName).getParentFile(); fileChooser.setCurrentDirectory(directory); FileNameExtensionFilter filter; filter = new FileNameExtensionFilter("XML file", "xml"); fileChooser.setFileFilter(filter);/*from w w w . j ava 2 s . c o m*/ fileChooser.setFileHidingEnabled(true); /*Remove All File option*/ fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacion.setText(selectedFile); lblNombreArchivo.setText(fileChooser.getSelectedFile().getName()); lblRutaArchivo.setText(fileChooser.getSelectedFile().getParent()); } }
From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java
/** * Save all settings to a given file//from w w w.j a v a 2s . c o m * @param evt */ private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsButtonActionPerformed // Save all configuration properties this.settings.setProperty("config.input-file-processor", this.inputFileFormatComboBox.getSelectedItem()); this.settings.setProperty("config.output-file-processor", this.outputFileFormatComboBox.getSelectedItem()); this.settings.setProperty("config.input-file-encoding", this.ifEncodingComboBox.getSelectedItem().toString()); this.settings.setProperty("config.output-file-encoding", this.ofEncodingComboBox.getSelectedItem().toString()); this.settings.setProperty("config.input-id-prefix", this.inputIDPrefixTextField.getText()); this.settings.setProperty("config.count-threshold", this.countThresholdTextField.getText()); this.settings.setProperty("config.input-field-order", MappingsHandler.Self().getInputOrder()); this.settings.setProperty("config.output-field-order", MappingsHandler.Self().getOutputOrder()); // Save File-Processor specific options FileProcessor fp = this.inputOptionsPanel.getProcessor(); String fpOptions[] = fp.getAvailableOptions(); for (String fpOption : fpOptions) { this.settings.setProperty("config.inputProcessor.options." + fpOption, fp.getOption(fpOption)); } fp = this.outputOptionsPanel.getProcessor(); fpOptions = fp.getAvailableOptions(); for (String fpOption : fpOptions) { this.settings.setProperty("config.outputProcessor.options." + fpOption, fp.getOption(fpOption)); } JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter fnef = new FileNameExtensionFilter("SMT Processing Settings (*.sps)", "sps"); fc.addChoosableFileFilter(fnef); // Let the user chose a settings file if (fc.showDialog(this, "Save Processing Settings") == JFileChooser.APPROVE_OPTION) { try { this.settings.save(fc.getSelectedFile()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.pgptool.gui.ui.decryptone.DecryptOnePm.java
public ExistingFileChooserDialog getSourceFileChooser() { if (sourceFileChooser == null) { sourceFileChooser = new ExistingFileChooserDialog(findRegisteredWindowIfAny(), appProps, SOURCE_FOLDER) {//w w w. j a v a 2s .c o m @Override protected void doFileChooserPostConstruct(JFileChooser ofd) { super.doFileChooserPostConstruct(ofd); ofd.setAcceptAllFileFilterUsed(false); ofd.addChoosableFileFilter( new FileNameExtensionFilter("Encrypted files (.gpg, .pgp, .asc)", EXTENSIONS)); ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter()); ofd.setFileFilter(ofd.getChoosableFileFilters()[0]); ofd.setDialogTitle(text("phrase.selectFileToDecrypt")); } @Override protected String handleFileWasChosen(String filePathName) { if (filePathName == null) { return null; } sourceFile.setValueByOwner(filePathName); return filePathName; } }; } return sourceFileChooser; }
From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java
private void loadSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSettingsButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter fnef = new FileNameExtensionFilter("SMT Processing Settings (*.sps)", "sps"); fc.addChoosableFileFilter(fnef);/*from w w w.ja v a2 s .com*/ // Let the user chose a settings file if (fc.showDialog(this, "Load Processing Settings") == JFileChooser.APPROVE_OPTION) { try { this.settings = new XMLConfiguration(fc.getSelectedFile()); // Update the interface to show all saved settings this.inputFileFormatComboBox .setSelectedItem(this.settings.getProperty("config.input-file-processor")); this.outputFileFormatComboBox .setSelectedItem(this.settings.getProperty("config.output-file-processor")); this.ifEncodingComboBox.setSelectedItem( Charset.forName((String) this.settings.getProperty("config.input-file-encoding"))); this.ofEncodingComboBox.setSelectedItem( Charset.forName((String) this.settings.getProperty("config.output-file-encoding"))); this.inputIDPrefixTextField.setText((String) this.settings.getProperty("config.input-id-prefix")); this.countThresholdTextField.setText((String) this.settings.getProperty("config.count-threshold")); MappingsHandler.Self() .setInputOrder((ArrayList<String>) this.settings.getProperty("config.input-field-order")); MappingsHandler.Self() .setOutputOrder((ArrayList<String>) this.settings.getProperty("config.output-field-order")); // Now load the processor specific settings FileProcessor fp = this.inputOptionsPanel.getProcessor(); String options[] = fp.getAvailableOptions(); for (String option : options) { if (this.settings.containsKey("config.inputProcessor.options." + option)) fp.setOption(option, this.settings.getProperty("config.inputProcessor.options." + option)); } fp = this.outputOptionsPanel.getProcessor(); options = fp.getAvailableOptions(); for (String option : options) { if (this.settings.containsKey("config.outputProcessor.options." + option)) fp.setOption(option, this.settings.getProperty("config.outputProcessor.options." + option)); } // Update options from processor for display this.inputOptionsPanel.loadOptions(); this.outputOptionsPanel.loadOptions(); /*Iterator it = this.settings.getKeys("config.inputProcessor.options"); while( it.hasNext() ) { System.out.println( it.next().toString() ); }*/ //this.settings.get } catch (Exception e) { e.printStackTrace(); } } }