public DGGameView(List<DGPlayer> players) {
   LinkedList<PlayerPanel> playerPanels = new LinkedList<PlayerPanel>();
   for (DGPlayer player : players) {
     playerPanels.add(new PlayerPanel(player, false));
   }
   this.players = playerPanels;
   setTitle("Its time to duel!");
   setLayout(new BorderLayout());
   confirmPanel = new ConfirmPanel("", this);
   playersView = new JPanel();
   switch (players.size()) {
     case 2:
       playersView.setLayout(new GridLayout(2, 1));
       break;
     case 3:
     case 4:
       playersView.setLayout(new GridLayout(2, 2));
   }
   for (PlayerPanel p : playerPanels) {
     playersView.add(p);
   }
   playersView.setVisible(true);
   playersView.setBackground(Color.BLACK);
   confirmPanel.setVisible(false);
   confirmPanel.setBackground(new Color(0.4f, 0.4f, 0.6f));
   add(playersView, BorderLayout.CENTER);
   add(confirmPanel, BorderLayout.SOUTH);
   pack();
   setVisible(true);
   /*JButton confirmButtonRef = confirmPanel.getConfirmButton();
   getRootPane().setDefaultButton(confirmButtonRef);
         confirmButtonRef.requestFocus();*/
 }
  /**
   * 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;
  }
  /** 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();
  }
  /**
   * ************************************************************************ 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
 /**
  * Static Constructor
  *
  * @throws Exception
  */
 private void jbInit() throws Exception {
   this.setJMenuBar(menuBar);
   confirmPanel.setActionListener(
       this); // set it first just to know buttons are working in case something failed
   //
   mEMail.setIcon(Images.getImageIcon2("EMailSupport16"));
   mEMail.setText(msgBL.getMsg(Env.getCtx(), "EMailSupport"));
   mEMail.addActionListener(this);
   mPreference.setIcon(Images.getImageIcon2("Preference16"));
   mPreference.setText(msgBL.getMsg(Env.getCtx(), "Preference"));
   mPreference.addActionListener(this);
   mEnd.setIcon(Images.getImageIcon2("End16"));
   mEnd.setText(msgBL.getMsg(Env.getCtx(), "End"));
   mEnd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK));
   mEnd.addActionListener(this);
   //
   westPanel.setLayout(westLayout);
   westPanel.setName("westPanel");
   westPanel.setRequestFocusEnabled(false);
   infoPanel.setLayout(infoLayout);
   infoPanel.setName("infoPanel");
   infoPanel.setRequestFocusEnabled(false);
   this.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
   this.getContentPane().add(westPanel, BorderLayout.WEST);
   westPanel.add(
       iconLabel,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(10, 10, 10, 10),
           0,
           0));
   this.getContentPane().add(infoPanel, BorderLayout.CENTER);
   infoPanel.add(
       info,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(10, 10, 10, 10),
           0,
           0));
   //
   menuBar.add(mFile);
   mFile.add(mEMail);
   if (Env.getUserRolePermissions().isShowPreference()) mFile.add(mPreference);
   mFile.addSeparator();
   mFile.add(mEnd);
 } // jbinit
Example #6
0
 /**
  * Static Init
  *
  * @throws Exception
  */
 void jbInit() throws Exception {
   mainPanel.setLayout(mainLayout);
   mainLayout.setHgap(2);
   mainLayout.setVgap(2);
   infoPane.setBorder(BorderFactory.createLoweredBevelBorder());
   infoPane.setPreferredSize(new Dimension(500, 400));
   getContentPane().add(mainPanel);
   mainPanel.add(infoPane, BorderLayout.CENTER);
   mainPanel.add(confirmPanel, BorderLayout.SOUTH);
   infoPane.getViewport().add(info, null);
   confirmPanel.addActionListener(this);
 } //	jbInit
Example #7
0
  /**
   * Descripción de Método
   *
   * @throws Exception
   */
  void jbInit() throws Exception {
    CompiereColor.setBackground(this);
    mainPanel.setLayout(mainLayout);
    mainLayout.setHgap(5);
    mainLayout.setVgap(5);
    this.getContentPane().add(mainPanel);
    northPanel.setLayout(northLayout);
    northPanel.add(toolBar, BorderLayout.CENTER);
    toolBar.add(bLoad);
    toolBar.add(bDelete);
    toolBar.add(bSave);
    toolBar.add(bOpen);
    toolBar.add(cbContent);
    mainPanel.add(northPanel, BorderLayout.NORTH);

    //

    bOpen.setEnabled(false);
    bOpen.setIcon(Env.getImageIcon("Editor24.gif"));
    bOpen.setMargin(new Insets(0, 2, 0, 2));
    bOpen.setToolTipText(Msg.getMsg(Env.getCtx(), "Open"));
    bOpen.addActionListener(this);

    //

    bSave.setEnabled(false);
    bSave.setIcon(Env.getImageIcon("Export24.gif"));
    bSave.setMargin(new Insets(0, 2, 0, 2));
    bSave.setToolTipText(Msg.getMsg(Env.getCtx(), "AttachmentSave"));
    bSave.addActionListener(this);

    //

    bLoad.setIcon(Env.getImageIcon("Import24.gif"));
    bLoad.setMargin(new Insets(0, 2, 0, 2));
    bLoad.setToolTipText(Msg.getMsg(Env.getCtx(), "Load"));
    bLoad.addActionListener(this);

    //

    bDelete.setIcon(Env.getImageIcon("Delete24.gif"));
    bDelete.setMargin(new Insets(0, 2, 0, 2));
    bDelete.setToolTipText(Msg.getMsg(Env.getCtx(), "Delete"));
    bDelete.addActionListener(this);

    //

    Dimension size = cbContent.getPreferredSize();

    size.width = 200;
    cbContent.setPreferredSize(size);

    // cbContent.setToolTipText(text);

    cbContent.addActionListener(this);
    cbContent.setLightWeightPopupEnabled(false); // Acrobat Panel is heavy

    //

    text.setBackground(CompierePLAF.getInfoBackground());
    text.setPreferredSize(new Dimension(200, 200));

    //

    mainPanel.add(confirmPanel, BorderLayout.SOUTH);
    confirmPanel.addActionListener(this);
    bDeleteAll = ConfirmPanel.createDeleteButton(true);
    confirmPanel.addButton(bDeleteAll);
    bDeleteAll.addActionListener(this);

    //

    info.setText("-");
    info.setReadWrite(false);
    graphPanel.add(info, BorderLayout.CENTER);

    //

    mainPanel.add(centerPane, BorderLayout.CENTER);
    centerPane.add(graphPanel, JSplitPane.LEFT);
    centerPane.add(text, JSplitPane.RIGHT);
    centerPane.setResizeWeight(.75); // more to graph
  } // jbInit
  public InputRequest takeInputRequest(InputRequest i) {
    makeAllUnSelectable();
    confirmPanel.setText(i.getOwner().getName() + "! " + i.getMessage());
    confirmPanel.activate();

    if (i instanceof CreatureSelectionRequest) {
      CreatureSelectionRequest request = (CreatureSelectionRequest) i;
      List<CardPanel> creaturePanels = getCreaturePanelsOnFields(request.getPossibleCreatures());
      for (CardPanel panel : creaturePanels) {
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          List<CreatureCard> creatures = new LinkedList<CreatureCard>();
          for (CardPanel panel : creaturePanels) {
            if (panel.isSelected()) {
              creatures.add((CreatureCard) panel.getCard());
            }
          }
          try {
            request.setCreatures(creatures);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }
    } else if (i instanceof PlayerSelectionRequest) {
      PlayerSelectionRequest request = (PlayerSelectionRequest) i;
      List<PlayerSelectionPanel> playerPanels =
          getPlayerSelectionPanels(request.getPossiblePlayers());
      for (PlayerSelectionPanel panel : playerPanels) {
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          List<Player> players = new LinkedList<Player>();
          for (PlayerSelectionPanel panel : playerPanels) {
            if (panel.isSelected()) {
              players.add((Player) panel.getReference());
            }
          }
          try {
            request.setSelectedPlayers(players);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }

    } else if (i instanceof CardSelectionRequest) {
      CardSelectionRequest request = (CardSelectionRequest) i;
      /*for(Card card : request.getPossibleCards())
      {
      	//System.out.println(card.getName());
      }*/
      List<CardPanel> cardPanels = getCardPanelsInHands(request.getPossibleCards());
      for (CardPanel panel : cardPanels) {
        // System.out.println("Selectable!");
        panel.setSelectable(true);
      }
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          // System.out.println(confirmPanel.isConfirmed());
          List<Card> cards = new LinkedList<Card>();
          for (CardPanel panel : cardPanels) {
            if (panel.isSelected()) {
              // System.out.println("Hellooooo");
              // System.out.println(panel.getCard().getName());
              cards.add((Card) panel.getCard());
            }
          }
          try {
            // System.out.println("Selected Cards");
            // System.out.println(cards);
            // System.out.println("Possible Cards");
            // System.out.println(request.getPossibleCards());
            request.setSelectedCards(cards);
          } catch (InvalidSelectionException e) {
            confirmPanel.setText("Invalid Selection: " + request.getMessage());
            confirmPanel.activate();
          }
        }
      }
    } else if (i instanceof BooleanInputRequest) {
      confirmPanel.getBoolPanel().activate();
      BooleanInputRequest request = (BooleanInputRequest) i;
      Thread b = new Thread();
      synchronized (b) {
        while (!request.hasAnswer()) {
          while (!confirmPanel.isConfirmed()) {
            try {
              b.wait(250);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
          request.setAnswer(confirmPanel.getBoolPanel().getAnswer());
        }
      }
      confirmPanel.getBoolPanel().deactivate();
    } else if (i instanceof EndGameInputRequest) {
      refreshPlayers();
      System.out.println("The game has ended");
    }

    makeAllUnSelectable();

    return i;
  }
/**
 * Dialog Windows
 *
 * @author Jorg Janke
 * @version $Id: ADialogDialog.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
 */
public final class ADialogDialog extends CDialog implements ActionListener {
  /** */
  private static final long serialVersionUID = 5670261006862936363L;

  // Services
  private final IMsgBL msgBL = Services.get(IMsgBL.class);

  /**
   * Create Dialog Window for Frame and show it.
   *
   * @param frame
   * @param title
   * @param message
   * @param messageType
   */
  public ADialogDialog(
      final Frame frame, final String title, final String message, final int messageType) {
    this(frame, title);

    setMessage(message, messageType);

    showCenterScreen();
  } // ADialogDialog

  public ADialogDialog(final Frame frame, final String title) {
    super(
        frame, title, frame != null // modal
        );
    init();
  }

  /**
   * Create Dialog Window for Dialog and show it.
   *
   * @param dialog
   * @param title
   * @param message
   * @param messageType
   */
  public ADialogDialog(Dialog dialog, String title, String message, int messageType) {
    this(dialog, title);

    setMessage(message, messageType);

    showCenterScreen();
  } // ADialogDialog

  public ADialogDialog(Dialog dialog, String title) {
    super(
        dialog, title, dialog != null // modal
        );

    init();
  }

  public void showCenterScreen() {
    AEnv.showCenterWindow(getOwner(), this);
  }

  /** Common Init */
  private void init() {
    assertUIOutOfTransaction();

    try {
      jbInit();

      setInitialAnswer(A_OK); // backward compatibility: OK is the default
    } catch (Exception ex) {
      log.log(Level.SEVERE, "Dialog init failed: " + ex.getMessage(), ex);
    }
  } // common

  /** Asserts dialog is opened out of transaction. */
  public static final void assertUIOutOfTransaction() {
    final ITrxManager trxManager = Services.get(ITrxManager.class);
    final String trxName = trxManager.getThreadInheritedTrxName(OnTrxMissingPolicy.ReturnTrxNone);
    if (!trxManager.isNull(trxName)) {
      final AdempiereException ex =
          new AdempiereException(
              "Opening a dialog while running in a trasaction it's always a bad idea"
                  + " because the database will be kept locked until the user will answer.");

      // NOTE: this issue is so critical that it's better to throw exception instead to just advice
      if (Services.get(IDeveloperModeBL.class).isEnabled()) {
        throw ex;
      } else {
        // In case we run in production, we won't fail because that would be a show stopper, but we
        // will log the exception.
        log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
      }
    }
  }

  /**
   * Sets message and messageType to be displayed.
   *
   * @param message
   * @param messageType
   */
  public void setMessage(final String message, final int messageType) {
    try {
      setInfoMessage(message);
      setInfoIcon(messageType);
    } catch (Exception ex) {
      log.log(
          Level.SEVERE,
          "Error while setting the message=" + message + ", messageType=" + messageType,
          ex);
    }
  }

  /**
   * Window Events - requestFocus
   *
   * @param e
   */
  @Override
  protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);

    //
    // When window is opened, focus on initial answer button
    if (e.getID() == WindowEvent.WINDOW_OPENED) {
      focusInitialAnswerButton();
    }
  } // processWindowEvent

  /** Answer OK (0) */
  public static int A_OK = 0;
  /** Answer Cancel (1) */
  public static int A_CANCEL = 1;
  /** Answer Close (-1) - Default */
  public static int A_CLOSE = -1;
  /** Answer */
  private int m_returnCode = A_CLOSE;
  /** Logger */
  private static final CLogger log = CLogger.getCLogger(ADialogDialog.class);

  private int _initialAnswer = -100; // will be initialized on construction time

  static Icon i_inform = Images.getImageIcon2("Inform32");
  static Icon i_warn = Images.getImageIcon2("Warn32");
  static Icon i_question = Images.getImageIcon2("Question32");
  static Icon i_error = Images.getImageIcon2("Error32");

  private JMenuBar menuBar = new JMenuBar();
  private JMenu mFile = AEnv.getMenu("File");
  private CMenuItem mEMail = new CMenuItem();
  private CMenuItem mEnd = new CMenuItem();
  private CMenuItem mPreference = new CMenuItem();
  private ConfirmPanel confirmPanel = ConfirmPanel.builder().withCancelButton(true).build();
  private CPanel westPanel = new CPanel();
  private CLabel iconLabel = new CLabel();
  private GridBagLayout westLayout = new GridBagLayout();
  private CTextPane info = new CTextPane();
  private GridBagLayout infoLayout = new GridBagLayout();
  private CPanel infoPanel = new CPanel();

  /**
   * Static Constructor
   *
   * @throws Exception
   */
  private void jbInit() throws Exception {
    this.setJMenuBar(menuBar);
    confirmPanel.setActionListener(
        this); // set it first just to know buttons are working in case something failed
    //
    mEMail.setIcon(Images.getImageIcon2("EMailSupport16"));
    mEMail.setText(msgBL.getMsg(Env.getCtx(), "EMailSupport"));
    mEMail.addActionListener(this);
    mPreference.setIcon(Images.getImageIcon2("Preference16"));
    mPreference.setText(msgBL.getMsg(Env.getCtx(), "Preference"));
    mPreference.addActionListener(this);
    mEnd.setIcon(Images.getImageIcon2("End16"));
    mEnd.setText(msgBL.getMsg(Env.getCtx(), "End"));
    mEnd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK));
    mEnd.addActionListener(this);
    //
    westPanel.setLayout(westLayout);
    westPanel.setName("westPanel");
    westPanel.setRequestFocusEnabled(false);
    infoPanel.setLayout(infoLayout);
    infoPanel.setName("infoPanel");
    infoPanel.setRequestFocusEnabled(false);
    this.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
    this.getContentPane().add(westPanel, BorderLayout.WEST);
    westPanel.add(
        iconLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(10, 10, 10, 10),
            0,
            0));
    this.getContentPane().add(infoPanel, BorderLayout.CENTER);
    infoPanel.add(
        info,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(10, 10, 10, 10),
            0,
            0));
    //
    menuBar.add(mFile);
    mFile.add(mEMail);
    if (Env.getUserRolePermissions().isShowPreference()) mFile.add(mPreference);
    mFile.addSeparator();
    mFile.add(mEnd);
  } // jbinit

  /**
   * Convert to HTML and Calculate Size
   *
   * @param message message
   */
  private void setInfoMessage(final String message) {
    final StringBuilder sb = new StringBuilder(message.length() + 20);
    sb.append("<b>");
    String html = Util.maskHTML(message);
    char[] chars = html.toCharArray();
    boolean first = true;
    int paras = 0;
    for (int i = 0; i < chars.length; i++) {
      char c = chars[i];
      if (c == '\n') {
        if (first) {
          sb.append("</b>");
          first = false;
        }
        if (paras > 1) sb.append("<br>");
        else sb.append("<p>");
        paras++;
      } else sb.append(c);
    }
    info.setText(sb.toString());
    Dimension size = info.getPreferredSize();
    size.width = 450;
    size.height = (Math.max(paras, message.length() / 60) + 1) * 30;
    size.height = Math.min(size.height, 600);
    info.setPreferredSize(size);

    info.setRequestFocusEnabled(false);
    info.setReadWrite(false);
    info.setOpaque(false);
    info.setBorder(null);
    //
    info.setCaretPosition(0);
  } // calculateSize

  /**
   * ************************************************************************ 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

  /**
   * ************************************************************************ ActionListener
   *
   * @param e
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    // log.finest( "ADialogDialog.actionPerformed - " + e);
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      m_returnCode = A_OK;
      dispose();
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL) || e.getSource() == mEnd) {
      m_returnCode = A_CANCEL;
      dispose();
    } else if (e.getSource() == mEMail) {
      String title = getTitle();
      String text = info.getText();
      dispose(); // otherwise locking
      ADialog.createSupportEMail(this, title, text);
    } else if (e.getSource() == mPreference) {
      if (Env.getUserRolePermissions().isShowPreference()) {
        final Preference p = new Preference(null, 0);
        p.setVisible(true);
      }
    }
  }

  /**
   * Get Return Code
   *
   * @return return code ({@link #A_OK}, {@link #A_CANCEL}, {@link #A_CLOSE})
   */
  public int getReturnCode() {
    return m_returnCode;
  } // getReturnCode

  /**
   * 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;
  }

  public int getInitialAnswer() {
    return this._initialAnswer;
  }

  /** 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();
  }
} // ADialogDialog