/** * Sets initial answer (i.e. button that will be preselected by default). * * <p>Please note that this is not the default answer that will be returned by {@link * #getReturnCode()} if user does nothing (i.e. closes the window). It is just the preselectated * button. * * @param initialAnswer {@link #A_OK}, {@link #A_CANCEL}. */ public void setInitialAnswer(final int initialAnswer) { // If the inial answer did not actual changed, do nothing if (this._initialAnswer == initialAnswer) { return; } // // Configure buttons accelerator (KeyStroke) and RootPane's default button final JRootPane rootPane = getRootPane(); final CButton okButton = confirmPanel.getOKButton(); final AppsAction okAction = (AppsAction) okButton.getAction(); final CButton cancelButton = confirmPanel.getCancelButton(); final AppsAction cancelAction = (AppsAction) cancelButton.getAction(); if (initialAnswer == A_OK) { okAction.setDefaultAccelerator(); cancelAction.setDefaultAccelerator(); rootPane.setDefaultButton(okButton); } else if (initialAnswer == A_CANCEL) { // NOTE: we need to set the OK's Accelerator keystroke to null because in most of the cases it // is "Enter" // and we want to prevent user for hiting ENTER by mistake okAction.setAccelerator(null); cancelAction.setDefaultAccelerator(); rootPane.setDefaultButton(cancelButton); } else { throw new IllegalArgumentException("Unknown inital answer: " + initialAnswer); } // // Finally, set the new inial answer this._initialAnswer = initialAnswer; }
/** * ************************************************************************ Set Info * * @param messageType */ private void setInfoIcon(int messageType) { final CButton cancelButton = confirmPanel.getCancelButton(); cancelButton.setVisible(false); cancelButton.setEnabled(false); // switch (messageType) { case JOptionPane.ERROR_MESSAGE: iconLabel.setIcon(i_error); break; case JOptionPane.INFORMATION_MESSAGE: iconLabel.setIcon(i_inform); break; case JOptionPane.QUESTION_MESSAGE: cancelButton.setVisible(true); cancelButton.setEnabled(true); iconLabel.setIcon(i_question); break; case JOptionPane.WARNING_MESSAGE: iconLabel.setIcon(i_warn); break; case JOptionPane.PLAIN_MESSAGE: default: break; } // switch } // setInfo
/** Request focus on inital answer (see {@link #getInialAnswer()}) button. */ private void focusInitialAnswerButton() { final CButton defaultButton; if (_initialAnswer == A_OK) { defaultButton = confirmPanel.getOKButton(); } else if (_initialAnswer == A_CANCEL) { defaultButton = confirmPanel.getCancelButton(); } else { return; } defaultButton.requestFocusInWindow(); }