public static boolean openPortSettingsDialog(
     SerialPortConnection port, String title, String message) {
   port.closeConnection();
   JOptionPane optionPane = new JOptionPane();
   PanelSerialConfig configPanel = new PanelSerialConfig(port);
   Object msg[] = {message, configPanel};
   optionPane.setMessage(msg);
   optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE);
   optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
   JDialog dialog = optionPane.createDialog(null, title);
   dialog.setVisible(true);
   Object value = optionPane.getValue();
   if (value == null || !(value instanceof Integer)) {
     System.out.println("Closed");
   } else {
     int i = ((Integer) value).intValue();
     if (i == JOptionPane.OK_OPTION) {
       try {
         port.getParameters().save();
         // setCommPort(getPort().getParameters().getPortName());
       } catch (Exception ex) {
         ex.printStackTrace();
       }
       // re-open the port
       port.reOpenConnection();
       // System.out.println("OKAY - value is: " + optionPane.getInputValue());
     } else {
       return false;
     }
   }
   return true;
 }
Beispiel #2
0
  public SetRhymingWordsPane() {
    numOfRWTF = new JTextField();
    apiList = new JComboBox<>();

    try {
      rwPropsOutput = new FileOutputStream(Strings.pathToProps + "rwProps.properties");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    JOptionPane setRWPane = new JOptionPane(JOptionPane.OK_CANCEL_OPTION);
    JDialog setRWDialog;

    Object[] rwContents = {
      "Choose Which API To Use", apiList, "Choose How Many Results To Get", numOfRWTF
    };

    String[] apis = {"Stands4", "Datamuse", "Rhymebrain"};
    for (String api : apis) {
      apiList.addItem(api);
    }

    setRWPane.setMessage(rwContents);
    setRWPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
    setRWDialog = setRWPane.createDialog(null, "Font Settings");
    setRWDialog.setVisible(true);

    if (setRWPane.getValue().equals(0)) {
      numOfRW = numOfRWTF.getText();
      String chosenAPI = apiList.getSelectedItem().toString();
      String finalAPI;

      switch (chosenAPI) {
        case "Stands4":
          finalAPI = "0";
          break;
        case "Datamuse":
          finalAPI = "1";
          break;
        case "Rhymebrain":
          finalAPI = "2";
          break;
        default:
          finalAPI = "1";
          break;
      }

      saveRwProps(finalAPI, numOfRW);
    }
  }
    private String showTextEditDialog(
        final String dialogTitle,
        JTable table,
        final int row,
        final int width,
        final int height,
        final String textToEdit) {

      // This panel holds the only edit control
      BuscadorProductosController controller = new BuscadorProductosController();
      BuscadorProductosView panel = controller.getView();

      // Use JOptionPane for a pane-less (ha!) way to create a
      // dialog in just a few lines. Also get system L&F.
      JOptionPane optPane = new JOptionPane();
      optPane.setMessage(panel);
      optPane.setMessageType(JOptionPane.PLAIN_MESSAGE);
      optPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
      JDialog dialog = optPane.createDialog(fc.getView(), dialogTitle);
      // This resizable setting is critical;
      // by default the dialog is quite small
      dialog.setResizable(true);

      // Show it already!
      dialog.setVisible(true);

      // Get the value and decide if it was "OK"
      Object selectedValue = optPane.getValue();
      int n = -1;
      if (selectedValue != null && selectedValue instanceof Integer)
        n = ((Integer) selectedValue).intValue();
      String result = null;
      if (n == JOptionPane.OK_OPTION) {
        result = controller.getCodigoSeleccionado();
        table.setValueAt(controller.getDescripcionSeleccionado(), row, 2);
        table.setValueAt(controller.getPrecioUnitario(), row, 4);
      }

      // Might be good text, might be null
      return result;
    }