Beispiel #1
0
  public void windowClosing(WindowEvent e) {
    if (server != null) {
      try {
        server.stop();
      } catch (Exception eClose) {
      }
      server = null;
    }

    dispose();
    System.exit(0);
  }
 /*
  * If the user click the X button to close the application
  * I need to close the connection with the server to free the port
  */
 public void windowClosing(WindowEvent e) {
   // if my Server exist
   if (server != null) {
     try {
       server.stop(); // ask the server to close the conection
     } catch (Exception eClose) {
     }
     server = null;
   }
   // dispose the frame
   dispose();
   System.exit(0);
 }
  public void actionPerformed(ActionEvent e) {

    // if running we have to stop

    if (server != null) {

      server.stop();

      server = null;

      tPortNumber.setEditable(true);

      stopStart.setText("Start");

      return;
    }

    // OK start the server

    int port;

    try {

      port = Integer.parseInt(tPortNumber.getText().trim());

    } catch (Exception er) {

      appendEvent("Invalid port number");

      return;
    }

    // ceate a new Server

    server = new Server(port, this);

    // and start it as a thread

    new ServerRunning().start();

    stopStart.setText("Stop");

    tPortNumber.setEditable(false);
  }
Beispiel #4
0
  public void actionPerformed(ActionEvent e) {
    if (server != null) {
      server.stop();
      server = null;
      tPortNumber.setEditable(true);
      stopStart.setText("Start");
      return;
    }

    int port;
    try {
      port = Integer.parseInt(tPortNumber.getText().trim());
    } catch (Exception er) {
      appendEvent("Invalid port number.");
      return;
    }

    server = new Server(port, this);
    new ServerRunning().start();
    stopStart.setText("Stop");
    tPortNumber.setEditable(false);
  }
Beispiel #5
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();
          }
        }