示例#1
0
        public void actionPerformed(ActionEvent e) {
          String NameItem = (((JMenuItem) e.getSource()).getText());
          if (NameItem == "Load File") {
            // all files disabled
            fc.setAcceptAllFileFilterUsed(false);

            // only XML files
            FileNameExtensionFilter xmlfilter =
                new FileNameExtensionFilter("xml files (*.xml)", "xml");
            fc.setFileFilter(xmlfilter);

            // Set Directory!!
            fc.setCurrentDirectory(new java.io.File("data"));

            // Open XML
            fc.setDialogTitle("Open XML");
            int returnVal = fc.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fc.getSelectedFile();
              String FileLocation = file.getPath();
              textArea.setText("");
              // textArea.setText(FileLocation + "\n" + "\n");

              // Parse XML
              xmlParser parser = new xmlParser();
              final ContainerSetXml containers;

              try {
                long time = System.nanoTime();
                containers = parser.parse(FileLocation);

                System.out.println(
                    "It took" + (System.nanoTime() - time) + "ns to parse the xml file");
                // new Thread for display next container after some time
                Thread t =
                    new Thread() {
                      public void run() {
                        for (ContainerXml c : containers.containers) {
                          DateFormat dateFormat = new SimpleDateFormat(" HH:mm:ss");
                          Calendar now = Calendar.getInstance();
                          String Time = "[" + dateFormat.format(now.getTime()) + "]";

                          textArea.append(Time + " " + c.id + " " + c.ownerName + "\n");
                          textArea.setCaretPosition(textArea.getDocument().getLength());
                          try {
                            sleep(150); // milliseconds
                          } catch (InterruptedException ex) {
                          }
                        }
                      }
                    };
                t.start(); // call back run()

              } catch (Exception ex) {
                System.out.println(ex);
              }
            }

          } else if (NameItem == "Start server") {
            // server.start() launches server.run() in a new thread
            // Meaning server.start won't freeze the gui anymore
            server.start(6666);
          } else if (NameItem == "Login to ftp") {
            FtpLoginView ftpLoginView = new FtpLoginView(server);
            ftpLoginView.display();
            String name = ftpLoginView.name;
            String password = ftpLoginView.name;

            // server.login() is called in ftpLoginView
          } else if (NameItem == "About") {
            JOptionPane.showMessageDialog(
                null,
                "Mede mogelijk gemaakt door Groep 5!",
                "About",
                JOptionPane.INFORMATION_MESSAGE);
          } else if (NameItem == "Help") {
            JOptionPane.showMessageDialog(
                null, "Moet nog ingevuld worden!", "Help", JOptionPane.INFORMATION_MESSAGE);
          } else if (NameItem == "Quit") {
            System.exit(0);
          } else if (NameItem == "Restart server") {
            server.restart(6666);
          } else if (NameItem == "Stop server") {
            server.stop();
          }
        }