Example #1
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
Example #2
0
 public static void main(String[] args) {
   boolean sender = false;
   File fi = null;
   try {
     if (args.length == 0) {
       int ret =
           JOptionPane.showConfirmDialog(
               null,
               "Are you the sender? (no = reciever)",
               "Send/Recieve",
               JOptionPane.YES_NO_OPTION);
       JFileChooser chooser = new JFileChooser();
       if (ret == JOptionPane.YES_OPTION) {
         chooser.showOpenDialog(null);
         sender = true;
       } else {
         chooser.showSaveDialog(null);
         sender = false;
       }
       fi = chooser.getSelectedFile();
     } else {
       if (args[0].equalsIgnoreCase("-s")) {
         sender = true;
       } else if (args[0].equalsIgnoreCase("-r")) {
         sender = false;
       }
       fi = new File(args[1]);
     }
   } catch (Exception e) {
     e.printStackTrace();
     exit();
   }
   if (sender && !fi.exists()) {
     System.err.println("Cannot send, file doesn't exist");
     exit();
   }
   try {
     if (sender) {
       ServerSocket ss = new ServerSocket(DEFAULT_PORT);
       Socket sck = ss.accept();
       byte[] hsh = SecureUtils.hash(fi);
       System.out.println(SecureUtils.hexify(hsh));
       sendFile(sck, fi, hsh);
       sck.close();
     } else {
       Socket sck = new Socket("localhost", DEFAULT_PORT);
       byte[] hsh = recvFile(sck, fi);
       System.out.println(SecureUtils.hexify(hsh));
       sck.close();
     }
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #3
0
  private void selectFolder() {

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File(textFolder.getText()));
    fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setApproveButtonText("Select");
    fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER);

    if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) {
      // Get the selected file
      String path = fileChooser.getSelectedFile().getPath() + "\\";
      textFolder.setText(path);
    }
  }