private void loadFile() { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html"); fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(filter); if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) { fileChooser.setCurrentDirectory( new File(internalBalloon.getBalloonContentPath().getLastUsedPath())); } else { fileChooser.setCurrentDirectory( new File(internalBalloon.getBalloonContentPath().getStandardPath())); } int result = fileChooser.showSaveDialog(getTopLevelAncestor()); if (result == JFileChooser.CANCEL_OPTION) return; try { String exportString = fileChooser.getSelectedFile().toString(); browseText.setText(exportString); internalBalloon .getBalloonContentPath() .setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath()); internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED); } catch (Exception e) { // } }
public String chooseElf() { JFileChooser chooser = new JFileChooser(new java.io.File(".")); FileFilter ff = new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) return true; else if (f.getName().endsWith(".elf")) return true; else if (f.getName().endsWith(".sin")) return true; else return false; } public String getDescription() { return "*.elf *.sin"; } }; chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileFilter(ff); chooser.setDialogTitle("Choose sin file)"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); // chooser.setFileFilter(newkernelimgFileFilter); // // disable the "All files" option. // chooser.setAcceptAllFileFilterUsed(false); // if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().getAbsolutePath(); } return "ERROR"; }
public static JFileChooser createJFileChooser(final String... fileFilters) { final JFileChooser chooser = new JFileChooser(); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); for (final String fileFilter : fileFilters) { final String[] fileFilterArr = StringUtils.split(fileFilter, "|"); chooser.addChoosableFileFilter( new FileFilter() { @Override public boolean accept(final File f) { final String[] types = StringUtils.split(fileFilterArr[0], ";"); if (types.length == 0) { return true; } else { if (!f.isFile()) { return true; } else { final String ext = FileUtils.getFilenameExtension(f.getPath()); for (final String type : types) { if (type.equalsIgnoreCase(ext)) { return true; } } return false; } } } @Override public String getDescription() { return fileFilterArr.length > 1 ? fileFilterArr[1] : fileFilterArr[0]; } }); } return chooser; }
/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
private void findPresentation() { JFileChooser fileChooser = new JFileChooser(); if (lastDirectory_ != null) fileChooser.setCurrentDirectory(lastDirectory_); // if (imc.lecturnity.converter.ConverterWizard.USE_CUSTOM_COLORS) if (USE_CUSTOM_COLORS) fileChooser.setBackground(Wizard.BG_COLOR); LecturnityFileFilter lff = new LecturnityFileFilter(); fileChooser.addChoosableFileFilter(lff); LpdFileFilter lpf = new LpdFileFilter(); fileChooser.addChoosableFileFilter(lpf); EPresentationFileFilter eff = new EPresentationFileFilter(); fileChooser.addChoosableFileFilter(eff); AofFileFilter aff = new AofFileFilter(); fileChooser.addChoosableFileFilter(aff); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(lff); Dimension fcSize = fileChooser.getPreferredSize(); fileChooser.setPreferredSize(new Dimension(fcSize.width + 100, fcSize.height + 50)); int action = fileChooser.showOpenDialog(this); lastDirectory_ = fileChooser.getCurrentDirectory(); if (action == fileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); presentationFileField_.setText(selectedFile.getAbsolutePath()); } }
public ExportStatisticsFile(List<MyObjectStatistics> valores) { JFileChooser jfc = new JFileChooser(lastPath); jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter()); // Adding required extensions (dbf, csv) dbfExtensionsSupported = new Hashtable<String, MyFileFilter>(); csvExtensionsSupported = new Hashtable<String, MyFileFilter>(); dbfExtensionsSupported.put( "dbf", new MyFileFilter("dbf", PluginServices.getText(this, "Ficheros_dbf"), "dbf")); csvExtensionsSupported.put( "csv", new MyFileFilter("csv", PluginServices.getText(this, "Ficheros_csv"), "csv")); Iterator<MyFileFilter> iter = csvExtensionsSupported.values().iterator(); while (iter.hasNext()) { jfc.addChoosableFileFilter(iter.next()); } iter = dbfExtensionsSupported.values().iterator(); while (iter.hasNext()) { jfc.addChoosableFileFilter(iter.next()); } // Opening a JFileCooser if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { File endFile = jfc.getSelectedFile(); if (endFile.exists()) { // File exists in the directory. int resp = JOptionPane.showConfirmDialog( (Component) PluginServices.getMainFrame(), PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo") + "\n" + endFile.getAbsolutePath(), PluginServices.getText(this, "guardar"), JOptionPane.YES_NO_OPTION); // Informing the user if (resp != JOptionPane.YES_OPTION) { // cancel pressed. return; } } // end if exits. MyFileFilter filter = (MyFileFilter) jfc.getFileFilter(); // dbf, csv endFile = filter.normalizeExtension(endFile); // "name" + "." + // "dbf", "name" + // "." + "csv" if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("csv") == 0) { // csv file exportToCSVFile(valores, endFile); // export to csv format } else if (filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("dbf") == 0) { // dbf file exportToDBFFile(valores, endFile); // export to dbf format } } // end if aprove option. }
private void browseReferenceSystemFile(String title) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(title); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML Files (*.xml)", "xml"); chooser.addChoosableFileFilter(filter); chooser.addChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileFilter(filter); if (!fileText.getText().trim().isEmpty()) chooser.setCurrentDirectory(new File(fileText.getText())); else chooser.setCurrentDirectory(new File(Internal.SRS_TEMPLATES_PATH)); int result = chooser.showOpenDialog(getTopLevelAncestor()); if (result == JFileChooser.CANCEL_OPTION) return; fileText.setText(chooser.getSelectedFile().toString()); }
// Listener für die Menüelemente und Buttons @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == btnAusw) { LOG.info("DB Verbindung wird hergestellt."); dbgetter = new DBConnection(SERVERNAME, PORT, DB, USER, PWD); dwAusw = new DWAuswertung(dbgetter); lblErgebnis.setText( dwAusw.getQuartal( (String) cBoxJahr.getSelectedItem(), (String) cBoxQuartal.getSelectedItem())); } if (e.getSource() == btnAusw2) { LOG.info("DB Verbindung wird hergestellt."); dbgetter = new DBConnection(SERVERNAME, PORT, DB, USER, PWD); dwAusw = new DWAuswertung(dbgetter); String[] array = dwAusw.getAuswertung( (String) cBoxJahr2.getSelectedItem(), (String) cBoxQuartal2.getSelectedItem(), (String) cBoxEinArt.getSelectedItem(), (String) cBoxMitglied.getSelectedItem()); lblErgebnis_2.setText(array[0]); lblMengeErg.setText(array[1]); } if (e.getSource() == mnItmQExp) { pfad = null; chooser = new JFileChooser(pfad); chooser.setDialogType(JFileChooser.SAVE_DIALOG); plainFilter = new FileNameExtensionFilter("*.csv", "csv"); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileFilter(plainFilter); chooser.setDialogTitle("Speichern unter..."); chooser.setVisible(true); file = null; int result = chooser.showSaveDialog(frmAuswertung); if (result == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (plainFilter.accept(file)) { LOG.info(file.getAbsolutePath() + " bereit zum speichern."); entries = new String[3]; entries[0] = lblErgebnis.getText().substring(0, lblErgebnis.getText().length() - 4); entries[1] = (String) cBoxJahr.getSelectedItem(); entries[2] = (String) cBoxQuartal.getSelectedItem(); if (new CSVParser().saveAs(file, entries)) { LOG.info("Datei erfolgreich gespeichert."); JOptionPane.showMessageDialog( new JFrame(), "Daten erfolgreich exportiert nach:\n" + file.getAbsolutePath(), "Datenexport", JOptionPane.INFORMATION_MESSAGE); } else { LOG.log(Level.WARNING, "Datei nicht gespeichert."); JOptionPane.showMessageDialog( new JFrame(), "Daten nicht exportiert!", "Datenexport", JOptionPane.ERROR_MESSAGE); } } else { LOG.info(file.getAbsolutePath() + " ist der falsche Dateityp."); JOptionPane.showMessageDialog( new JFrame(), "Bitte folgendes Format nutzen:\n" + "{DATEINAME}.csv", "Datenexport", JOptionPane.ERROR_MESSAGE); } chooser.setVisible(false); } if (e.getSource() == mnItmAExp) { pfad = null; chooser = new JFileChooser(pfad); chooser.setDialogType(JFileChooser.SAVE_DIALOG); plainFilter = new FileNameExtensionFilter("*.csv", "csv"); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileFilter(plainFilter); chooser.setDialogTitle("Speichern unter..."); chooser.setVisible(true); file = null; int result = chooser.showSaveDialog(frmAuswertung); if (result == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (plainFilter.accept(file)) { LOG.info(file.getAbsolutePath() + " bereit zum speichern."); entries = new String[6]; entries[0] = lblErgebnis.getText().substring(0, lblErgebnis.getText().length() - 4); entries[1] = lblMengeErg.getText().substring(0, lblMengeErg.getText().length() - 4); entries[2] = (String) cBoxEinArt.getSelectedItem(); entries[3] = (String) cBoxMitglied.getSelectedItem(); entries[4] = (String) cBoxJahr.getSelectedItem(); entries[5] = (String) cBoxQuartal.getSelectedItem(); if (new CSVParser().saveAs(file, entries)) { LOG.info("Datei erfolgreich gespeichert."); JOptionPane.showMessageDialog( new JFrame(), "Daten erfolgreich exportiert nach:\n" + file.getAbsolutePath(), "Datenexport", JOptionPane.INFORMATION_MESSAGE); } else { LOG.log(Level.WARNING, "Datei nicht gespeichert."); JOptionPane.showMessageDialog( new JFrame(), "Daten nicht exportiert!", "Datenexport", JOptionPane.ERROR_MESSAGE); } } else { LOG.info(file.getAbsolutePath() + " ist der falsche Dateityp."); JOptionPane.showMessageDialog( new JFrame(), "Bitte folgendes Format nutzen:\n" + "{DATEINAME}.csv", "Datenexport", JOptionPane.ERROR_MESSAGE); } chooser.setVisible(false); } if (e.getSource() == mnItmLog) { try { Desktop.getDesktop() .browse( new URI( "file://" + System.getProperty("user.home") + System.getProperty("file.separator") + "dw-log.html")); } catch (URISyntaxException | IOException e1) { LOG.log(Level.WARNING, "Protokoll kann nicht geöffnet werden.", e1); JOptionPane.showMessageDialog( new JFrame(), "Protokoll konnte nicht geöffnet werden.", "Protokoll öffnen...", JOptionPane.ERROR_MESSAGE); } } if (e.getSource() == mnItmQuit) { frmAuswertung.dispose(); } if (e.getSource() == mnItmAbout) { About frame = new About(); frame.setVisible(true); } }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == binfo) { JOptionPane.showMessageDialog( frame, "Programme crée par Sarathai\n" + "Licence creative commons\n" + "\n" + "Pour envoyer des fichiers sur le serveur, cliquer d'abord sur le bouton ajouter,\n" + "puis sélectionnez le dossier ou fichier à ajouter. Répétez cette opération autant de foi que nécessaire.\n" + "Puis cliquez sur le bouton envoyer en ayant d'abord rempli les champs de l'adresse ip et du port.\n" + "\n" + "Pour recevoir des fichiers sauvegardés sur le serveur, cliquez sur le bouton recevoir,\n" + "puis sélectionnez le ou les fichier(s) voulu(s) dans la liste de gauche, et enfin recliquez\n" + "sur le bouton recevoir pour importer les fichiers.\n" + "\n" + "Pour toutes les infos, bien lire le texte qui s'affiche dans le champ de texte en bas.", "Informations", JOptionPane.INFORMATION_MESSAGE); } else if (src == ajouter) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int i = chooser.showOpenDialog(Fenetre.frame); if (i == JFileChooser.APPROVE_OPTION) { frame.setCursor(waitCursor); File file = chooser.getSelectedFile(); if (file.isDirectory()) { name = file.getAbsolutePath().toString() + sep; selection.addElement(name); new WhatIDo("Ajouté à la séléction", name); } else { name = file.getAbsolutePath().toString(); selection.addElement(name); new WhatIDo("Ajouté à la séléction", name); } liste.updateUI(); enlever.setEnabled(true); frame.setCursor(Cursor.getDefaultCursor()); } } else if (src == enlever) { try { int j = liste.getSelectedIndex(); new WhatIDo("Supprimé de la séléction", selection.elementAt(j).toString()); selection.removeElementAt(j); } catch (ArrayIndexOutOfBoundsException e1) { new WhatIDo("Supprimé de la séléction", selection.elementAt(0).toString()); selection.removeElementAt(0); } if (selection.size() == 0) { selection.clear(); liste.clearSelection(); enlever.setEnabled(false); } liste.updateUI(); } else if (src == bquitter) { System.exit(0); } else if (src == bnouveau) { selection.clear(); liste.clearSelection(); liste.updateUI(); new WhatIDo("Nouvelle sauvegarde"); } else if (src == benvoyer) { if (!selection.isEmpty()) { new Envoyer(selection); } else { new WhatIDo("Veuillez ajouter des fichiers ou dossiers"); } } else if (src == brecevoir) { if (!liste.isSelectionEmpty()) { Vector<String> vec = new Vector<String>(); for (int i : liste.getSelectedIndices()) { vec.addElement(selection.elementAt(i)); } new Recevoir(vec); } else { new Recevoir(); } } }