Example #1
0
 public PassWordInputListener(JOptionPane pane, JTextField field) {
   this.pane = pane;
   this.field = field;
   int type = pane.getOptionType();
   if (type == JOptionPane.OK_CANCEL_OPTION) {
     this.okButton = ((JPanel) pane.getComponent(pane.getComponentCount() - 1)).getComponent(0);
   }
   setSubmittable();
 }
 /**
  * Returns the <code>String</code> representation of the given <code>{@link Component}</code>,
  * which should be a <code>{@link JOptionPane}</code> (or subclass.)
  *
  * @param c the given <code>Component</code>.
  * @return the <code>String</code> representation of the given <code>JOptionPane</code>.
  */
 protected String doFormat(Component c) {
   JOptionPane optionPane = (JOptionPane) c;
   return concat(
       optionPane.getClass().getName(),
       "[",
       "message=",
       quote(optionPane.getMessage()),
       ", ",
       "messageType=",
       MESSAGE_TYPES.get(optionPane.getMessageType()),
       ", ",
       "optionType=",
       OPTION_TYPES.get(optionPane.getOptionType()),
       ", ",
       "enabled=",
       valueOf(optionPane.isEnabled()),
       ", ",
       "visible=",
       valueOf(optionPane.isVisible()),
       ", ",
       "showing=",
       valueOf(optionPane.isShowing()),
       "]");
 }
  /**
   * Returns the buttons to display from the JOptionPane the receiver is providing the look and feel
   * for. If the JOptionPane has options set, they will be provided, otherwise if the optionType is
   * YES_NO_OPTION, yesNoOptions is returned, if the type is YES_NO_CANCEL_OPTION yesNoCancelOptions
   * is returned, otherwise defaultButtons are returned.
   */
  protected Object[] getButtons() {
    if (optionPane != null) {
      Object[] suppliedOptions = optionPane.getOptions();

      if (suppliedOptions == null) {
        Object[] defaultOptions;
        int type = optionPane.getOptionType();
        Locale l = optionPane.getLocale();
        int minimumWidth =
            DefaultLookup.getInt(optionPane, this, "OptionPane.buttonMinimumWidth", -1);
        if (type == JOptionPane.YES_NO_OPTION) {
          defaultOptions = new ButtonFactory[2];
          defaultOptions[0] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.yesButtonText", l),
                  getMnemonic("OptionPane.yesButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.yesIcon"),
                  minimumWidth);
          defaultOptions[1] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.noButtonText", l),
                  getMnemonic("OptionPane.noButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.noIcon"),
                  minimumWidth);
        } else if (type == JOptionPane.YES_NO_CANCEL_OPTION) {
          defaultOptions = new ButtonFactory[3];
          defaultOptions[0] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.yesButtonText", l),
                  getMnemonic("OptionPane.yesButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.yesIcon"),
                  minimumWidth);
          defaultOptions[1] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.noButtonText", l),
                  getMnemonic("OptionPane.noButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.noIcon"),
                  minimumWidth);
          defaultOptions[2] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.cancelButtonText", l),
                  getMnemonic("OptionPane.cancelButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.cancelIcon"),
                  minimumWidth);
        } else if (type == JOptionPane.OK_CANCEL_OPTION) {
          defaultOptions = new ButtonFactory[2];
          defaultOptions[0] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.okButtonText", l),
                  getMnemonic("OptionPane.okButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.okIcon"),
                  minimumWidth);
          defaultOptions[1] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.cancelButtonText", l),
                  getMnemonic("OptionPane.cancelButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.cancelIcon"),
                  minimumWidth);
        } else {
          defaultOptions = new ButtonFactory[1];
          defaultOptions[0] =
              new ButtonFactory(
                  UIManager.getString("OptionPane.okButtonText", l),
                  getMnemonic("OptionPane.okButtonMnemonic", l),
                  (Icon) DefaultLookup.get(optionPane, this, "OptionPane.okIcon"),
                  minimumWidth);
        }
        return defaultOptions;
      }
      return suppliedOptions;
    }
    return null;
  }