Пример #1
1
 private void addIndexnode(final MainFrame frame) {
   String result =
       (String)
           JOptionPane.showInputDialog(
               null,
               "Enter the URL of the new indexnode:",
               "New Indexnode",
               JOptionPane.QUESTION_MESSAGE,
               null,
               null,
               "");
   if (result == null) return;
   try {
     if (!result.toLowerCase().startsWith("http://")) result = "http://" + result;
     final URL resURL = new URL(result);
     Thread elsewhere =
         new Thread(
             new Runnable() {
               @Override
               public void run() {
                 comm.registerNewIndexNode(resURL);
               }
             });
     elsewhere.setDaemon(true);
     elsewhere.setName("Add new indexnode thread");
     elsewhere.start();
     frame.setStatusHint("Added: " + result + "... It might take a few seconds to show up...");
   } catch (MalformedURLException e1) {
     frame.setStatusHint(
         new StatusHint(
             frame.getGui().getUtil().getImage("error"),
             "Invalid new indexnode URL! (" + e1.getMessage() + ")"));
     Logger.log("Invalid new indexnode url: " + e1);
   }
 }
Пример #2
0
 @Override
 public void mouseEntered(MouseEvent e) {
   if (e.getSource() == message) {
     frame.setStatusHint("Enter your message here");
   } else if (e.getSource() == sendMessage) {
     frame.setStatusHint("Click to send your message");
   } else if (e.getSource() == avatarTable) {
     frame.setStatusHint("Lists everyone connected to the index node");
   }
 }
Пример #3
0
  private void setupTab() {

    // The chat area
    BorderLayout chatLayout = new BorderLayout();
    JPanel chatWrapper = new JPanel(chatLayout);

    chatLog = new JTextPane();
    chatLog.setEditable(false);
    chatLog.setDocument(new ChatDocument());
    chatLogScrollPane = new JScrollPane(chatLog);
    chatLogScrollPane.addMouseListener(this);

    chatWrapper.add(chatLogScrollPane, BorderLayout.CENTER);

    // The send message panel
    message = new JTextArea();
    message.addMouseListener(this);
    message.addKeyListener(this);
    messageScrollPane = new JScrollPane(message);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
    message.requestFocus();
    message.setDocument(new JTextFieldLimit(512));

    sendMessage = new JButton("Send", frame.getGui().getUtil().getImage("sendmessage"));
    sendMessage.addMouseListener(this);
    sendMessage.addActionListener(this);

    chatMessagePanel = new JPanel();
    chatMessagePanel.setLayout(new BoxLayout(chatMessagePanel, BoxLayout.X_AXIS));
    chatMessagePanel.add(messageScrollPane);
    chatMessagePanel.add(sendMessage);

    chatWrapper.add(chatMessagePanel, BorderLayout.PAGE_END);

    // Setup the avatars
    avatarTable = new JTable(new AvatarTableModel(indexNode));
    avatarTable.addMouseListener(this);
    avatarTable.setTableHeader(null);
    avatarTable.setDefaultRenderer(Object.class, new AvatarRenderer(frame));
    avatarTable.setRowHeight(70);
    avatarScrollPane = new JScrollPane(avatarTable);
    avatarScrollPane.setMaximumSize(new Dimension(200, -1));
    avatarScrollPane.setPreferredSize(new Dimension(200, -1));

    // Add all to parent
    BorderLayout pageLayout = new BorderLayout();

    this.setLayout(pageLayout);
    this.add(avatarScrollPane, BorderLayout.LINE_END);
    this.add(chatWrapper, BorderLayout.CENTER);

    // Set the status
    active = true;
  }
Пример #4
0
  public IndexnodeSettings(final MainFrame frame) {
    super(frame, "Indexnodes", frame.getGui().getUtil().getImage("autodetect"));

    comm = frame.getGui().getShareServer().getIndexNodeCommunicator();

    setupAutoDetectButton(frame);
    setupButtons(frame);

    nodesTable = new FancierTable(comm, frame.getGui().getConf(), CK.INDEXNODE_TABLE_COLWIDTHS);
    add(new JScrollPane(nodesTable), BorderLayout.CENTER);
    for (int i = 0; i < comm.getColumnCount(); i++) {
      TableColumn col = nodesTable.getColumn(comm.getColumnName(i));
      if (i == 0) col.setCellRenderer(new IndexNodeNameRenderer());
      if (i == 1) col.setCellRenderer(new IndexNodeStatusRenderer());
      if (i == 2) col.setCellRenderer(new IndexNodeDateRenderer());
    }

    registerHint(
        nodesTable,
        new StatusHint(null, "Lists all indexnodes known to FS2 at this point in time"));
    nodesTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (nodesTable.getSelectedRows().length == 0) {
                  removeIndexnode.setEnabled(false);
                  setPassword.setEnabled(false);
                } else {
                  removeIndexnode.setEnabled(true);
                  setPassword.setEnabled(
                      comm.getRegisteredIndexNodes()
                          .get(nodesTable.convertRowIndexToModel(nodesTable.getSelectedRow()))
                          .isSecure());
                }
              }
            });
  }
Пример #5
0
  private void setupAutoDetectButton(final MainFrame frame) {
    JPanel autoPanel = new JPanel(new BorderLayout());
    add(autoPanel, BorderLayout.NORTH);

    autodetect = new JCheckBox();
    autodetect.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (autodetect.isSelected()) {
              comm.enableAdvertAcceptance();
            } else {
              comm.disableAdvertAcceptance();
            }
          }
        });
    autodetect.setSelected(comm.isListeningForAdverts());
    autoPanel.add(autodetect, BorderLayout.CENTER);
    registerHint(
        autodetect,
        new StatusHint(
            frame.getGui().getUtil().getImage("autodetect"),
            "(saved on change) Check this box to enable autodetection of indexnodes"));

    JLabel autolabel =
        new JLabel(
            "Autodetect indexnodes: ",
            frame.getGui().getUtil().getImage("autodetect"),
            JLabel.LEFT);
    autoPanel.add(autolabel, BorderLayout.WEST);
    registerHint(
        autolabel,
        new StatusHint(
            frame.getGui().getUtil().getImage("autodetect"),
            "(saved on change) Check this box to enable autodetection of indexnodes"));
  }
Пример #6
0
  private void setupButtons(final MainFrame frame) {
    JPanel buttonsPanel = new JPanel(new FlowLayout());
    add(buttonsPanel, BorderLayout.SOUTH);
    addIndexnode = new JButton("Add indexnode...", frame.getGui().getUtil().getImage("add"));
    addIndexnode.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            addIndexnode(frame);
          }
        });
    registerHint(
        addIndexnode,
        new StatusHint(
            frame.getGui().getUtil().getImage("add"),
            "Click here to add a new indexnode manually"));
    removeIndexnode =
        new JButton("Remove selected indexnode", frame.getGui().getUtil().getImage("delete"));
    removeIndexnode.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            removeIndexnode();
          }
        });
    registerHint(
        removeIndexnode,
        new StatusHint(
            frame.getGui().getUtil().getImage("delete"),
            "Click here to de-register the selected indexnode"));
    removeIndexnode.setEnabled(false);

    setPassword = new JButton("Provide password...", frame.getGui().getUtil().getImage("unlock"));
    setPassword.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            setPassword();
          }
        });
    registerHint(
        setPassword,
        new StatusHint(
            frame.getGui().getUtil().getImage("unlock"),
            "Click here to provide a password for a secure indexnode..."));
    setPassword.setEnabled(false);

    buttonsPanel.add(addIndexnode);
    buttonsPanel.add(removeIndexnode);
    buttonsPanel.add(setPassword);
  }
Пример #7
0
  @Override
  public void newMessages(LinkedList<ChatMessage> messages) {
    ChatDocument doc = (ChatDocument) chatLog.getDocument();

    for (ChatMessage m : messages) {
      if (m.id != -1) { // Only print non-commands
        try {
          doc.insertChatMessage(
              doc.getLength(), m.message + "\n", indexNode.getStats().getPeers().values());

          if (!owner.isActiveTab()) {
            missedMessageCount++;
          } else {
            missedMessageCount = 0;
          }

          if (owner.displayChatNotifications()) {
            // Only show messages if we're not focused on the tab

            // Currently pops up messages intended for the user only
            // If we don't trim the username out of the string then it will pop up every time the
            // user sends a message
            //						if (m.message.replaceFirst(".*:",
            // "").contains(frame.getGui().getShareServer().getAlias())){
            toaster.showToaster(
                frame.getGui().getUtil().getImageFullname("chat.png"),
                indexNode.getName(),
                m.message); // "There are "+missedMessageCount+" unread chat messages.");
            //						}

            // toaster.showToaster(m.message);
          }

          chatLogScrollPane
              .getVerticalScrollBar()
              .setValue(chatLogScrollPane.getVerticalScrollBar().getMaximum());
        } catch (BadLocationException e) {
          Logger.log(e);
        }
      }
    }
  }