⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 confirmationcallback.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @throws IllegalArgumentException if <code>prompt</code> is <code>null</code>,   * if <code>prompt</code> has a length of <code>0</code>, if   * <code>messageType</code> is not either <code>INFORMATION</code>,   * <code>WARNING</code>, or <code>ERROR</code>, if <code>optionType</code> is   * not either <code>YES_NO_OPTION</code>, <code>YES_NO_CANCEL_OPTION</code>,   * or <code>OK_CANCEL_OPTION</code>, or if <code>defaultOption</code> does   * not correspond to one of the options in <code>optionType</code>.   */  public ConfirmationCallback(String prompt, int messageType, int optionType,			      int defaultOption)  {    super();    setPrompt(prompt);    setMessageType(messageType);    setOptionType(optionType, defaultOption);    this.defaultOption = defaultOption;  }  /**   * <p>Construct a <code>ConfirmationCallback</code> with a prompt, message   * type, a list of options and a default option.</p>   *   * <p>Underlying security services use this constructor if they require a   * confirmation different from the available preset confirmations provided   * (for example, CONTINUE/ABORT or STOP/GO). The confirmation options are   * listed in the <code>options</code> array, and are displayed by the   * {@link CallbackHandler} implementation in a manner consistent with the   * way preset options are displayed.</p>   *   * @param prompt the prompt used to describe the list of options.   * @param messageType the message type (INFORMATION, WARNING or ERROR).   * @param options the list of confirmation options.   * @param defaultOption the default option, represented as an index into the   * <code>options</code> array.   * @throws IllegalArgumentException if <code>prompt</code> is <code>null</code>,   * if <code>prompt</code> has a length of <code>0</code>, if   * <code>messageType</code> is not either <code>INFORMATION</code>,   * <code>WARNING</code>, or <code>ERROR</code>, if <code>options</code> is   * <code>null</code>, if <code>options</code> has a length of <code>0</code>,   * if any element from <code>options</code> is <code>null</code>, if any   * element from <code>options</code> has a length of <code>0</code>, or if   * <code>defaultOption</code> does not lie within the array boundaries of   * <code>options</code>.   */  public ConfirmationCallback(String prompt, int messageType, String[] options,			      int defaultOption)  {    super();    setPrompt(prompt);    setMessageType(messageType);    setOptions(options, defaultOption);    this.defaultOption = defaultOption;  }  // Class methods  // -------------------------------------------------------------------------  // Instance methods  // -------------------------------------------------------------------------  /**   * Get the prompt.   *   * @return the prompt, or <code>null</code> if this   * <code>ConfirmationCallback</code> was instantiated without a prompt.   */  public String getPrompt()  {    return prompt;  }  /**   * Get the message type.   *   * @return the message type (INFORMATION, WARNING or ERROR).   */  public int getMessageType()  {    return messageType;  }  /**   * <p>Get the option type.</p>   *   * <p>If this method returns {@link #UNSPECIFIED_OPTION}, then this   * <code>ConfirmationCallback</code> was instantiated with <code>options</code>   * instead of an <code>optionType</code>. In this case, invoke the   * {@link #getOptions()} method to determine which confirmation options to   * display.</p>   *   * @return the option type (YES_NO_OPTION, YES_NO_CANCEL_OPTION or   * OK_CANCEL_OPTION), or UNSPECIFIED_OPTION if this   * <code>ConfirmationCallback</code> was instantiated with <code>options</code>   * instead of an <code>optionType</code>.   */  public int getOptionType()  {    if (options != null)      {	return UNSPECIFIED_OPTION;      }    return optionType;  }  /**   * Get the confirmation options.   *   * @return the list of confirmation options, or <code>null</code> if this   * <code>ConfirmationCallback</code> was instantiated with an   * <code>optionType</code> instead of <code>options</code>.   */  public String[] getOptions()  {    return options;  }  /**   * Get the default option.   *   * @return the default option, represented as <code>YES</code>, <code>NO</code>,   * <code>OK</code> or <code>CANCEL</code> if an <code>optionType</code> was   * specified to the constructor of this <code>ConfirmationCallback</code>.   * Otherwise, this method returns the default option as an index into the   * <code>options</code> array specified to the constructor of this   * <code>ConfirmationCallback</code>.   */  public int getDefaultOption()  {    return defaultOption;  }  /**   * Set the selected confirmation option.   *   * @param selection the selection represented as <code>YES</code>,   * <code>NO</code>, <code>OK</code> or <code>CANCEL</code> if an   * <code>optionType</code> was specified to the constructor of this   * <code>ConfirmationCallback</code>. Otherwise, the <code>selection</code>   * represents the index into the <code>options</code> array specified to the   * constructor of this <code>ConfirmationCallback</code>.   * @see #getSelectedIndex()   */  public void setSelectedIndex(int selection)  {    if (options != null)      {	setOptions(options, selection);      }    else      {	setOptionType(optionType, selection);      }  }  /**   * Get the selected confirmation option.   *   * @return the selected confirmation option represented as <code>YES</code>,   * <code>NO</code>, <code>OK</code> or <code>CANCEL</code> if an   * <code>optionType</code> was specified to the constructor of this   * <code>ConfirmationCallback</code>. Otherwise, this method returns the   * selected confirmation option as an index into the <code>options</code>   * array specified to the constructor of this <code>ConfirmationCallback</code>.   * @see #setSelectedIndex(int)   */  public int getSelectedIndex()  {    return this.selection;  }  private void setMessageType(int messageType) throws IllegalArgumentException  {    switch (messageType)      {      case INFORMATION:      case WARNING:      case ERROR: this.messageType = messageType; break;      default: throw new IllegalArgumentException("illegal message type");      }  }  private void setOptionType(int optionType, int selectedOption)    throws IllegalArgumentException  {    switch (optionType)      {      case YES_NO_OPTION:	this.optionType = optionType;	switch (selectedOption)	  {	  case YES:	  case NO: this.selection = selectedOption; break;	  default: throw new IllegalArgumentException("invalid option");	  }	break;      case YES_NO_CANCEL_OPTION:	this.optionType = optionType;	switch (selectedOption)	  {	  case YES:	  case NO:	  case CANCEL: this.selection = selectedOption; break;	  default: throw new IllegalArgumentException("invalid option");	  }	break;      case OK_CANCEL_OPTION:	this.optionType = optionType;	switch (selectedOption)	  {	  case OK:	  case CANCEL: this.selection = selectedOption; break;	  default: throw new IllegalArgumentException("invalid option");	  }	break;      default:	throw new IllegalArgumentException("illegal option type");      }  }  private void setOptions(String[] options, int selectedOption)    throws IllegalArgumentException  {    if ((selectedOption < 0) || (selectedOption > options.length - 1))      {	throw new IllegalArgumentException("invalid selection");      }    if ((options == null) || (options.length == 0))      {	throw new IllegalArgumentException("options is null or empty");      }    for (int i = 0; i < options.length; i++)      {	if ((options[i] == null) || (options[i].length() == 0))	  {	    throw new IllegalArgumentException("options[" + i + "] is null or empty");	  }      }    this.options = options;    this.selection = selectedOption;  }  private void setPrompt(String prompt) throws IllegalArgumentException  {    if ((prompt == null) || (prompt.length() == 0))      {	throw new IllegalArgumentException("prompt is null or empty");      }    this.prompt = prompt;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -