예제 #1
0
파일: Notes.java 프로젝트: justin0127/IM
  private void saveNotes() {
    String note = textPane.getText();

    // Check for empty note.
    if (!ModelUtil.hasLength(note)) {
      return;
    }

    // Save note.
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
      agentSession.setNote(sessionID, note);
      saveButton.setEnabled(false);
      statusLabel.setText(" " + FpRes.getString("message.notes.updated"));
      SwingWorker worker =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(3000);
              } catch (InterruptedException e1) {
                Log.error(e1);
              }
              return true;
            }

            public void finished() {
              statusLabel.setText("");
            }
          };
      worker.start();
    } catch (XMPPException e1) {
      showError(FpRes.getString("message.unable.to.update.notes"));
      Log.error("Could not commit note.", e1);
    }
  }
예제 #2
0
  public void display() {
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new GridBagLayout());

    // Setup resource
    ResourceUtils.resLabel(addressLabel, addressField, Res.getString("label.jabber.address") + ":");

    RolloverButton backButton = new RolloverButton();
    backButton.setIcon(SparkRes.getImageIcon(SparkRes.LEFT_ARROW_IMAGE));
    backButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int selectedItem = addressField.getSelectedIndex();
            if (selectedItem > 0) {
              Object historyItem = addressField.getItemAt(selectedItem - 1);
              browse((String) historyItem);
            }
          }
        });

    mainPanel.add(
        backButton,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        addressLabel,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        addressField,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));

    JButton browseButton = new JButton("");
    ResourceUtils.resButton(browseButton, Res.getString("button.browse"));
    browseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String serviceName = (String) addressField.getSelectedItem();
            if (!ModelUtil.hasLength(serviceName)) {
              return;
            }
            browse(serviceName);
          }
        });
    mainPanel.add(
        addressField,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    mainPanel.add(
        browseButton,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    browsePanel = new JPanel();
    browsePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    browsePanel.setBackground(Color.white);

    JScrollPane pane =
        new JScrollPane(
            browsePanel,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    browsePanel.setPreferredSize(new Dimension(0, 0));
    mainPanel.add(
        pane,
        new GridBagConstraints(
            0,
            1,
            4,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    JFrame frame = new JFrame();
    frame.setIconImage(SparkRes.getImageIcon(SparkRes.FIND_IMAGE).getImage());

    JDialog dialog = new JDialog(frame, Res.getString("title.jabber.browser"));
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(mainPanel, BorderLayout.CENTER);
    dialog.pack();
    dialog.setSize(600, 400);
    dialog.setLocationRelativeTo(SparkManager.getMainWindow());
    dialog.setVisible(true);
  }
예제 #3
0
  private void addButtons() {
    // Build Accept Button
    acceptButton =
        new RolloverButton(
            "      " + PhoneRes.getIString("phone.accept"),
            PhoneRes.getImageIcon("TOASTER_ACCEPT_BUTTON"));
    acceptButton.setHorizontalTextPosition(JLabel.CENTER);
    acceptButton.setFont(new Font("Dialog", Font.BOLD, 11));
    acceptButton.setForeground(new Color(91, 175, 41));
    acceptButton.setMargin(new Insets(0, 0, 0, 0));

    // Build Reject Button
    rejectButton =
        new RolloverButton(
            "      " + PhoneRes.getIString("phone.reject"),
            PhoneRes.getImageIcon("TOASTER_REJECT_BUTTON"));
    rejectButton.setHorizontalTextPosition(JLabel.CENTER);
    rejectButton.setFont(new Font("Dialog", Font.BOLD, 11));
    rejectButton.setForeground(new Color(153, 32, 10));
    rejectButton.setMargin(new Insets(0, 0, 0, 0));

    final JPanel panel = new JPanel(new GridBagLayout());
    panel.setOpaque(false);
    panel.add(
        acceptButton,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    panel.add(
        rejectButton,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    add(
        panel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
예제 #4
0
파일: Notes.java 프로젝트: justin0127/IM
  public Notes(String sessionID, ChatRoom room) {
    setLayout(new BorderLayout());

    this.chatRoom = room;

    this.sessionID = sessionID;

    textPane = new JTextPane();
    textPane.setText(FpRes.getString("message.click.to.add.notes"));
    textPane.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (!hasClickedInPane) {
              textPane.setText("");
              hasClickedInPane = true;
            }
          }
        });

    scrollPane = new JScrollPane(textPane);

    this.add(scrollPane, BorderLayout.CENTER);

    toolBar = new JToolBar();
    toolBar.setFloatable(false);

    saveButton = new RolloverButton(FastpathRes.getImageIcon(FastpathRes.SAVE_AS_16x16));

    toolBar.add(saveButton);

    ResourceUtils.resButton(saveButton, FpRes.getString("button.save.note"));

    final BackgroundPane titlePanel = new BackgroundPane();
    titlePanel.setLayout(new GridBagLayout());

    JLabel notesLabel = new JLabel();
    notesLabel.setFont(new Font("Dialog", Font.BOLD, 12));

    ResourceUtils.resLabel(notesLabel, textPane, FpRes.getString("label.notes"));

    JLabel descriptionLabel = new JLabel();
    descriptionLabel.setText(FpRes.getString("message.chat.notes"));

    titlePanel.add(
        notesLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    titlePanel.add(
        descriptionLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 10, 5, 5),
            0,
            0));
    titlePanel.add(
        saveButton,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 10, 5, 5),
            0,
            0));

    // add(titlePanel, BorderLayout.NORTH);

    textPane
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }

              public void insertUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }

              public void removeUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }
            });

    saveButton.setEnabled(false);

    // Add status label
    statusLabel = new JLabel();
    this.add(statusLabel, BorderLayout.SOUTH);

    chatRoom.addClosingListener(
        new ChatRoomClosingListener() {
          public void closing() {
            if (updated) {
              saveNotes();
            }
          }
        });
  }