예제 #1
0
 protected boolean informUserError(String msg) // this is just for SPPmon
     {
   if (!ExpCoordinator.isSPPMon()) return false;
   final String opt0 = "Try Again";
   final String opt1 = "Cancel";
   JLabel lbl = new JLabel(msg);
   TextFieldwLabel tfaddress = new TextFieldwLabel(30, "daemon addr:");
   tfaddress.setText(host);
   TextFieldwLabel tfport = new TextFieldwLabel(30, "daemon port:");
   tfport.setText(String.valueOf(port));
   Object[] params = {lbl, tfaddress, tfport};
   Object[] options = {opt0, opt1};
   int rtn =
       JOptionPane.showOptionDialog(
           ExpCoordinator.getMainWindow(),
           params,
           "Connection Error",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.WARNING_MESSAGE,
           null,
           options,
           options[0]);
   if (rtn == JOptionPane.NO_OPTION) {
     connectionFailed();
     return false;
   } else {
     String tmp_host = host;
     boolean change = false;
     if (tfaddress.getText().length() > 0) tmp_host = tfaddress.getText();
     int tmp_port = port;
     if (tfport.getText().length() > 0) tmp_port = Integer.parseInt(tfport.getText());
     if (!tmp_host.equals(host)) {
       host = new String(tmp_host);
       change = true;
     }
     if (port != tmp_port) {
       port = tmp_port;
       change = true;
     }
     if (change) fireEvent(new ConnectionEvent(this, ConnectionEvent.ADDRESS_CHANGED));
     state = ConnectionEvent.CONNECTION_CLOSED;
     return (connect());
   }
 }
예제 #2
0
  // ask user for script file and name of new profile
  // return false if user cancelled operation
  private boolean getNewWkldInput(
      JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile) {
    // let user select script file with queries
    boolean fileOk = false;
    int retval;
    File file = null;
    FileReader reader = null;
    while (!fileOk) {
      if ((retval = chooser.showDialog(this, "Ok")) != 0) {
        return false;
      }
      file = chooser.getSelectedFile();
      try {
        reader = new FileReader(file.getPath());
        fileOk = true;
        scriptFile.append(file.getPath());
      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(
            this,
            "Selected script file does not exist",
            "Error: New Profile",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    // let user select filename for profile
    int response =
        JOptionPane.showOptionDialog(
            this,
            optionDlgMsg,
            "New Profile",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            null);
    if (response != JOptionPane.OK_OPTION) {
      return false;
    }
    JTextField textFld = (JTextField) optionDlgMsg[1];
    name.append(file.getParent() + "/" + textFld.getText());
    return true;
  }