Beispiel #1
0
  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 DefaultSaveDialog(
      JFrame parent,
      Path lastDirectory,
      Path initialFile,
      FileFilter filter,
      String defaultExtension) {
    this.parent = parent;
    this.defaultExtension = defaultExtension;
    fileChooser = new OverwritePromptFileChooser();

    for (javax.swing.filechooser.FileFilter fileFilter : fileChooser.getChoosableFileFilters()) {
      fileChooser.removeChoosableFileFilter(fileFilter);
    }

    if (fileChooser instanceof OverwritePromptFileChooser) {
      ((OverwritePromptFileChooser) fileChooser).setFileFilter(filter, defaultExtension);
    } else {
      fileChooser.setFileFilter(filter);
    }

    if (lastDirectory != null) {
      fileChooser.setCurrentDirectory(lastDirectory.toFile());
    }

    fileChooser.setSelectedFile(initialFile != null ? initialFile.toFile() : null);
  }
  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;
  }
 private void resetGlobFilter() {
   if (actualFileFilter != null) {
     JFileChooser chooser = getFileChooser();
     FileFilter currentFilter = chooser.getFileFilter();
     if (currentFilter != null && currentFilter.equals(globFilter)) {
       chooser.setFileFilter(actualFileFilter);
       chooser.removeChoosableFileFilter(globFilter);
     }
     actualFileFilter = null;
   }
 }
  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.
  }
Beispiel #6
0
  // 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);
    }
  }