/**
   * 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);
    }
  }
Esempio n. 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);
    }
  }
Esempio n. 3
0
  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();
      }
    }
  }