示例#1
0
  /**
   * Shows a file selection dialog for the given working directory.
   *
   * @param aOwner the owning window to show the dialog in;
   * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code>
   *     .
   * @return the selected file, or <code>null</code> if the user aborted the dialog.
   */
  public static final File showFileSelectionDialog(
      final Window aOwner,
      final String aCurrentDirectory,
      final javax.swing.filechooser.FileFilter... aFileFilters) {
    if (HostUtils.isMacOS()) {
      final FileDialog dialog;
      if (aOwner instanceof Dialog) {
        dialog = new FileDialog((Dialog) aOwner);
      } else {
        dialog = new FileDialog((Frame) aOwner);
      }
      dialog.setDirectory(aCurrentDirectory);

      if ((aFileFilters != null) && (aFileFilters.length > 0)) {
        dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters));
      }

      try {
        dialog.setVisible(true);
        final String selectedFile = dialog.getFile();
        return (selectedFile == null) ? null : new File(dialog.getDirectory(), selectedFile);
      } finally {
        dialog.dispose();
      }
    } else {
      final JFileChooser dialog = new JFileChooser();
      dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory));

      for (javax.swing.filechooser.FileFilter filter : aFileFilters) {
        dialog.addChoosableFileFilter(filter);
      }

      dialog.setVisible(true);
      return dialog.getSelectedFile();
    }
  }
示例#2
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);
    }
  }