/* DESCRIPTION
   *	Connect button event method,
   *  Call the connect method
   * ARGUMENTS
   *	ip - Peer IP variable, integer
   *	port - Peer Port variable, integer
   *  dlg - Warning dialog, Dialog
   *  msg - Warning message, Label
   *  ok - confirm button on the warning dialog
   */
  protected void connect_btnMouseClicked(MouseEvent evt) {

    ip = ip_text.getText();
    port = Integer.parseInt(port_text.getText());

    final Dialog dlg = new Dialog(this, "Warning!");
    dlg.setSize(300, 100);
    Label msg = new Label("Input the correct Ip address and Port number.", Label.CENTER);
    Button ok = new Button("OK");

    dlg.setLayout(new FlowLayout());
    dlg.add(msg);
    dlg.add(ok);

    ok.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            dlg.dispose();
          }
        });

    // if user didn't a peer ip, it shows alarm dialog
    if (ip.equals("")) {
      dlg.setVisible(true);
    }

    // Call the connect method
    else {

      try {
        connect();

      } catch (Exception e) {

        dlg.setVisible(true);
        System.out.println(e);
      }
    }
  }
 public void setVisible(boolean visible) {
   pack();
   if (centered) {
     Dimension frameSize = getParent().getSize();
     Point frameLoc = getParent().getLocation();
     Dimension mySize = getSize();
     int x, y;
     x = frameLoc.x + (frameSize.width / 2) - (mySize.width / 2);
     y = frameLoc.y + (frameSize.height / 2) - (mySize.height / 2);
     setBounds(x, y, getSize().width, getSize().height);
   }
   super.setVisible(visible);
 }
示例#3
0
 @Override
 public void actionPerformed(java.awt.event.ActionEvent e) {
   try {
     PropertyEditor propEd = property.getPropertyEditor();
     propEd.setValue(property.getValue());
     final Component custEditor = propEd.getCustomEditor();
     Object[] options = buttons();
     DialogDescriptor descriptor =
         new DialogDescriptor(
             custEditor,
             (String) getValue(Action.NAME),
             true,
             options,
             DialogDescriptor.CANCEL_OPTION,
             DialogDescriptor.DEFAULT_ALIGN,
             HelpCtx.DEFAULT_HELP,
             (ActionEvent e1) -> {
               try {
                 String action = e1.getActionCommand();
                 switch (action) {
                   case OK_COMMAND:
                     Object value = property.getPropertyEditor().getValue();
                     property.setValue(value);
                     break;
                   case RESTORE_COMMAND:
                     property.restoreDefaultValue();
                     break;
                 }
                 dialog.dispose();
               } catch (Exception ex) {
                 NotifyDescriptor descriptor2 =
                     new NotifyDescriptor.Message(
                         NbBundle.getMessage(PropertyAction.class, "MSG_InvalidValue")); // NOI18N
                 DialogDisplayer.getDefault().notify(descriptor2);
               }
             });
     descriptor.setClosingOptions(new Object[0]);
     dialog = DialogDisplayer.getDefault().createDialog(descriptor);
     dialog.setVisible(true);
     dialog = null;
   } catch (Exception ex) {
     ErrorManager.getDefault().notify(ex);
   }
 }
示例#4
0
    /** Handles button events */
    public void actionPerformed(ActionEvent e) {

      // only chooseMainClassButton can be performed

      final MainClassChooser panel =
          new MainClassChooser(sourceRoots.getRoots(), null, mainClassTextField.getText());
      Object[] options = new Object[] {okButton, DialogDescriptor.CANCEL_OPTION};
      panel.addChangeListener(
          new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
              if (e.getSource() instanceof MouseEvent
                  && MouseUtils.isDoubleClick(((MouseEvent) e.getSource()))) {
                // click button and finish the dialog with selected class
                okButton.doClick();
              } else {
                okButton.setEnabled(panel.getSelectedMainClass() != null);
              }
            }
          });
      okButton.setEnabled(false);
      DialogDescriptor desc =
          new DialogDescriptor(
              panel,
              NbBundle.getMessage(CustomizerRun.class, "LBL_ChooseMainClass_Title"), // NOI18N
              true,
              options,
              options[0],
              DialogDescriptor.BOTTOM_ALIGN,
              null,
              null);
      // desc.setMessageType (DialogDescriptor.INFORMATION_MESSAGE);
      Dialog dlg = DialogDisplayer.getDefault().createDialog(desc);
      dlg.setVisible(true);
      if (desc.getValue() == options[0]) {
        mainClassTextField.setText(panel.getSelectedMainClass());
      }
      dlg.dispose();
    }
示例#5
0
  public static int selectPID() {
    JButton okButton = new JButton(OK_BUTTON_NAME);
    PIDSelectPanel pidSelect = new PIDSelectPanel(okButton);

    DialogDescriptor dd =
        new DialogDescriptor(
            pidSelect,
            SELECT_PROCESS_DIALOG_CAPTION,
            true,
            new Object[] {okButton, CANCEL_OPTION},
            okButton,
            BOTTOM_ALIGN,
            null,
            null);
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
    d.setVisible(true);

    if (dd.getValue() == okButton) {
      return pidSelect.getPID();
    } else {
      return -1;
    }
  }
示例#6
0
 protected void showDialog(Dialog dlg) {
   dlg.setVisible(true);
 }
  /* DESCRIPTION
   *	Send button event method,
   *  Send the data to socket
   * ARGUMENTS
   *	sendstr - send data, String
   *  hexstr -  send data converted to hex, String
   *  dlg - Warning dialog, Dialog
   *  msg - Warning message, Label
   *  ok - confirm button on the warning dialog
   *  pw - output stream
   */
  protected void send_btnMouseClicked(MouseEvent evt) {

    String sendstr = "";
    String hexstr = "";

    // if the user click the send button when the socket is close, it shows warning dialog
    if (sock == null) {

      final Dialog dlg = new Dialog(this, "Warning!");
      dlg.setSize(300, 100);
      Label msg = new Label("Connect the socket, first.", Label.CENTER);
      Button ok = new Button("OK");

      dlg.setLayout(new FlowLayout());
      dlg.add(msg);
      dlg.add(ok);

      ok.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              dlg.dispose();
            }
          });

      dlg.setVisible(true);
    }

    // send the data to socket
    else {

      sendstr = send_text.getText();

      if (sendstr.equals("") && cr_check.isSelected() == false && lf_check.isSelected() == false) {

        final Dialog dlg = new Dialog(this, "Warning!");
        dlg.setSize(300, 100);
        Label msg = new Label("Insert the message", Label.CENTER);
        Button ok = new Button("OK");

        dlg.setLayout(new FlowLayout());
        dlg.add(msg);
        dlg.add(ok);

        ok.addMouseListener(
            new MouseAdapter() {
              public void mouseClicked(MouseEvent e) {
                dlg.dispose();
              }
            });

        dlg.setVisible(true);
      } else {
        pw.print(sendstr);

        if (cr_check.isSelected()) {
          pw.print("\r");
          sendstr = sendstr + "\r";
        }
        if (lf_check.isSelected()) {
          pw.print("\n");
          sendstr = sendstr + "\n";
        }
        pw.flush();

        hexstr = StringtoHex(sendstr);

        data.append("Send data : ");
        data.append(hexstr + " | ");
        data.append(sendstr);
        data.append("\n");

        send_text.setText("");
        sendstr = "";
      }
    }
  }