Пример #1
0
  public void sendMessage() {
    if (client == null) {
      connect();
      return;
    }
    String toSomebody = combobox.getSelectedItem().toString();
    short channelType = 1;
    String status = "";
    if (checkbox.isSelected()) {
      status = "Secret";
    }
    String action = actionlist.getSelectedItem().toString();

    String message = clientMessage.getText();
    message = action + message;
    switch (toSomebody) {
      case "all":
        channelType = 2;
        break;
      default:
        message = status + message;
        break;
    }
    try {
      ChatMessage chat = new ChatMessage(channelType, message, userName, toSomebody);
      client.write(chat);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void initComponents() {

    addWindowListener(HelperWindow.get());

    jScrollPane1 = new javax.swing.JScrollPane();
    _messageList = new RPList();
    _historyLabel = new RPLabel();
    _my_messageLabel = new RPLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    _messageText = new RPTextArea();
    _messageText.setEditable(true);
    _messageText.setFont(GraphicsUtils.getFont(15));
    _recipientLabel = new RPLabel();
    _passwordText = new RPTextBox();
    _passwordLabel = new RPLabel();
    _feeAmount = new RPTextBox();
    _encodeCheckBox = new RPCheckBox();
    _encodeCheckBox.setBackground(UIConfig.dialogbackground);
    _encodeCheckBox.setFont(font);
    _feeLabel = new RPLabel();
    _amountText = new RPTextBox();
    jSeparator1 = new javax.swing.JSeparator();
    _exitButton = new RPCButton();
    _submitButton = new RPCButton();
    _resetButton = new RPCButton();
    _amountLabel = new RPLabel();
    _recipientText = new RPTextBox();

    getContentPane().setLayout(null);

    _messageList.setFont(GraphicsUtils.getFont(Font.SANS_SERIF, 0, 12));
    _messageList.setCellRenderer(new HtmlRenderer());
    _messageList.setAutoscrolls(true);
    jScrollPane1.setViewportView(_messageList);

    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(10, 28, 494, 170);

    _historyLabel.setText(LangConfig.get(this, "history", "History"));
    getContentPane().add(_historyLabel);
    _historyLabel.setFont(font);
    _historyLabel.setBounds(10, 5, 150, 20);

    _my_messageLabel.setText(LangConfig.get(this, "mmessage", "My Message"));
    getContentPane().add(_my_messageLabel);
    _my_messageLabel.setFont(font);
    _my_messageLabel.setBounds(10, 208, 150, 20);

    _messageText.setColumns(20);
    _messageText.setRows(5);
    jScrollPane2.setViewportView(_messageText);
    if (_message != null) {
      _messageText.setText(_message);
    } else {
      _messageText.setText("Hello Rippled Message!");
    }

    getContentPane().add(jScrollPane2);
    jScrollPane2.setBounds(10, 233, 494, 110);

    _recipientLabel.setFont(font); // NOI18N
    _recipientLabel.setText(LangConfig.get(this, "recipient", "Recipient"));
    getContentPane().add(_recipientLabel);
    _recipientLabel.setBounds(10, 360, 70, 20);
    getContentPane().add(_passwordText);
    _passwordText.setBounds(80, 440, 180, 20);

    _passwordLabel.setFont(font); // NOI18N
    _passwordLabel.setText(LangConfig.get(this, "password", "Password"));
    getContentPane().add(_passwordLabel);
    _passwordLabel.setBounds(10, 440, 70, 20);
    getContentPane().add(_feeAmount);
    _feeAmount.setBounds(340, 400, 160, 20);
    _feeAmount.setText(LSystem.getFee());

    _encodeCheckBox.setText(LangConfig.get(this, "mpassword", "Message Password"));
    getContentPane().add(_encodeCheckBox);
    _encodeCheckBox.setBounds(285, 440, 210, 23);
    if (!_encodeCheckBox.isSelected()) {
      _passwordText.setEnabled(false);
    }
    _encodeCheckBox.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (!_encodeCheckBox.isSelected()) {
              _passwordText.setText("");
              _passwordText.setEnabled(false);
            } else {
              PasswordEasy easy = new PasswordEasy();
              _passwordText.setText(easy.pass(12, 18));
              _passwordText.setEnabled(true);
            }
          }
        });

    _feeLabel.setFont(font); // NOI18N
    _feeLabel.setText(LangConfig.get(this, "fee", "Fee"));
    getContentPane().add(_feeLabel);
    _feeLabel.setBounds(290, 400, 50, 20);
    getContentPane().add(_amountText);
    _amountText.setBounds(80, 400, 180, 20);
    _amountText.setText(LSystem.getMinSend());

    getContentPane().add(jSeparator1);
    jSeparator1.setBounds(0, 480, 520, 10);

    _exitButton.setText(UIMessage.exit);
    _exitButton.setFont(font);
    getContentPane().add(_exitButton);
    _exitButton.setBounds(420, 500, 81, 40);
    _exitButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            SwingUtils.close(RPRippledMemoDialog.this);
          }
        });

    _submitButton.setText(UIMessage.send);
    _submitButton.setFont(font);
    getContentPane().add(_submitButton);
    _submitButton.setBounds(320, 500, 81, 40);
    _submitButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (_item == null) {
              return;
            }
            String address = _recipientText.getText().trim();
            if (address.startsWith("~")) {
              try {
                address = NameFind.getAddress(address);
              } catch (Exception ex) {
                UIRes.showWarningMessage(
                    LSystem.applicationMain, UIMessage.warning, UIMessage.errNotAddress);
                return;
              }
            }
            if (AccountFind.isRippleAddress(address)) {
              String password = null;
              if (_encodeCheckBox.isSelected()) {
                password = _passwordText.getText();
                if (password.length() == 0) {
                  password = null;
                }
              }
              String context = _messageText.getText();
              String amount = _amountText.getText().trim();
              String fee = _feeAmount.getText().trim();
              if (!StringUtils.isNumber(fee)) {
                RPToast.makeText(RPRippledMemoDialog.this, UIMessage.errFee, Style.ERROR).display();
                return;
              }
              Amount amountValue = Amount.fromString(amount);
              if (StringUtils.isNumber(amountValue.valueText())) {
                RippleMemoEncode encode = null;
                if (password == null) {
                  encode =
                      new RippleMemoEncode(
                          RippleMemoEncode.Mode.BASE64, "MESSAGE", context, password);
                } else {
                  encode =
                      new RippleMemoEncode(
                          RippleMemoEncode.Mode.ENCODE, "MESSAGE", context, password);
                }
                final WaitDialog wait = WaitDialog.showDialog(RPRippledMemoDialog.this);
                _waitDialogs.add(wait);
                Payment.send(
                    _item.getSeed(),
                    amount,
                    address,
                    encode,
                    fee,
                    new Rollback() {

                      @Override
                      public void success(JSONObject res) {
                        RPJSonLog.get().println(res);
                        wait.closeDialog();
                        RPToast.makeText(
                                RPRippledMemoDialog.this, UIMessage.completed, Style.SUCCESS)
                            .display();
                      }

                      @Override
                      public void error(JSONObject res) {
                        RPJSonLog.get().println(res);
                        wait.closeDialog();
                      }
                    });
              } else {
                RPToast.makeText(RPRippledMemoDialog.this, UIMessage.errMoney, Style.ERROR)
                    .display();
              }
            } else {
              RPToast.makeText(RPRippledMemoDialog.this, UIMessage.errAddress, Style.ERROR)
                  .display();
            }
          }
        });

    _resetButton.setText(LangConfig.get(this, "reset", "Reset"));
    _resetButton.setFont(font);
    getContentPane().add(_resetButton);
    _resetButton.setBounds(10, 500, 81, 40);
    _resetButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (_address != null) {
              loadMessages(_address, -1, -1, 20);
            }
          }
        });

    _amountLabel.setFont(font); // NOI18N
    _amountLabel.setText(LangConfig.get(this, "amount", "Amount"));
    getContentPane().add(_amountLabel);
    _amountLabel.setBounds(10, 400, 70, 20);
    getContentPane().add(_recipientText);
    _recipientText.setBounds(80, 360, 420, 21);
    getContentPane().setBackground(UIConfig.dialogbackground);
    if (_address != null) {
      loadMessages(_address, -1, -1, 200);
    }
    if (_item == null) {
      _submitButton.setEnabled(false);
      // _resetButton.setEnabled(false);
    }
    pack();
  }
Пример #3
0
  public void init() {
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    loginButton = new RPCButton("Login");
    logoffButton = new RPCButton("Quit");
    userButton = new RPCButton("Set User");
    connectButton = new RPCButton("Set Connection");
    exitButton = new RPCButton("Exit UI");

    toolBar.setBackground(UIConfig.dialogbackground);
    toolBar.setBorder(new EmptyBarBorder());
    toolBar.add(userButton);
    toolBar.add(connectButton);
    toolBar.addSeparator();
    toolBar.add(loginButton);
    toolBar.add(logoffButton);
    toolBar.addSeparator();
    toolBar.add(exitButton);
    contentPane.add(toolBar, BorderLayout.NORTH);
    checkbox = new RPCheckBox("Secret");
    checkbox.setBackground(UIConfig.dialogbackground);
    checkbox.setSelected(false);
    actionlist = new RPComboBox();
    actionlist.addItem("O(∩_∩)O");
    actionlist.addItem(">_<|||");
    actionlist.addItem("⊙﹏⊙‖");
    actionlist.addItem("→_→");
    actionlist.addItem("…(⊙_⊙;)…");
    actionlist.addItem("( ^_^ )?");
    actionlist.setSelectedIndex(0);

    loginButton.setEnabled(true);
    logoffButton.setEnabled(false);

    loginButton.addActionListener(this);
    logoffButton.addActionListener(this);
    userButton.addActionListener(this);
    connectButton.addActionListener(this);
    exitButton.addActionListener(this);
    combobox = new RPComboBox();
    combobox.insertItemAt("all", 0);
    combobox.setSelectedIndex(0);
    messageShow = new RPTextArea();
    messageShow.setEditable(false);

    messageScrollPane =
        new JScrollPane(
            messageShow,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    messageScrollPane.setPreferredSize(new Dimension(400, 400));
    messageScrollPane.revalidate();

    clientMessage = new RPTextBox(23);
    clientMessage.setEnabled(false);
    clientMessageButton = new RPCButton();
    clientMessageButton.setText(UIMessage.send);
    clientMessageButton.setFont(UIRes.getFont());

    clientMessage.addActionListener(this);
    clientMessageButton.addActionListener(this);
    sendToLabel = new RPLabel("Send To:");
    express = new RPLabel("Face:");
    messageLabel = new RPLabel("Message:");
    downPanel = new JPanel();

    downPanel.setPreferredSize(new Dimension((int) faceSize.getWidth(), 155));
    downPanel.setLayout(null);

    downPanel.add(sendToLabel);
    sendToLabel.setBounds(10, 5, 70, 30);

    downPanel.add(combobox);
    combobox.setBounds(80, 5, 90, 30);

    downPanel.add(express);
    express.setBounds(190, 5, 90, 30);

    downPanel.add(actionlist);
    actionlist.setBounds(240, 5, 110, 30);

    downPanel.add(checkbox);
    checkbox.setBounds(5, 35, 70, 30);

    downPanel.add(messageLabel);
    messageLabel.setBounds(10, 65, 70, 30);

    downPanel.add(clientMessage);
    clientMessage.setBounds(80, 65, (int) faceSize.getWidth() - 90, 30);

    downPanel.add(clientMessageButton);
    clientMessageButton.setBounds(80, 115, 90, 30);

    contentPane.add(messageScrollPane, BorderLayout.CENTER);
    contentPane.add(downPanel, BorderLayout.SOUTH);
    messageScrollPane.setBackground(UIConfig.dialogbackground);
    downPanel.setBackground(UIConfig.dialogbackground);

    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (type == 1) {
              disConnect();
            }
            SwingUtils.close(RPChatClientDialog.this);
          }
        });
  }