예제 #1
0
  /**
   * Add a Politics Panel button to the game menu, this panel will show the current political
   * landscape as a reference, no actions on this panel.
   *
   * @param menuGame
   */
  private void addPoliticsMenu(final JMenu menuGame) {
    final AbstractAction politicsAction =
        SwingAction.of(
            "Show Politics Panel",
            e -> {
              final PoliticalStateOverview ui =
                  new PoliticalStateOverview(gameData, iuiContext, false);
              final JScrollPane scroll = new JScrollPane(ui);
              scroll.setBorder(BorderFactory.createEmptyBorder());
              final Dimension screenResolution = Toolkit.getDefaultToolkit().getScreenSize();
              // not only do we have a start bar, but we also have the message dialog to account for
              final int availHeight = screenResolution.height - 120;
              // just the scroll bars plus the window sides
              final int availWidth = screenResolution.width - 40;

              scroll.setPreferredSize(
                  new Dimension(
                      (scroll.getPreferredSize().width > availWidth
                          ? availWidth
                          : scroll.getPreferredSize().width),
                      (scroll.getPreferredSize().height > availHeight
                          ? availHeight
                          : scroll.getPreferredSize().height)));

              JOptionPane.showMessageDialog(
                  frame, scroll, "Politics Panel", JOptionPane.PLAIN_MESSAGE);
            });
    menuGame.add(politicsAction).setMnemonic(KeyEvent.VK_P);
  }
예제 #2
0
 private void addShowVerifiedDice(final JMenu parentMenu) {
   final Action showVerifiedDice =
       SwingAction.of(
           "Show Verified Dice",
           e -> new VerifiedRandomNumbersDialog(frame.getRootPane()).setVisible(true));
   if (game instanceof ClientGame) {
     parentMenu.add(showVerifiedDice).setMnemonic(KeyEvent.VK_V);
   }
 }
예제 #3
0
 private void addBattleCalculatorMenu(final JMenu menuGame) {
   final Action showBattleMenu =
       SwingAction.of("Battle Calculator", e -> OddsCalculatorDialog.show(frame, null));
   final JMenuItem showBattleMenuItem = menuGame.add(showBattleMenu);
   showBattleMenuItem.setMnemonic(KeyEvent.VK_B);
   showBattleMenuItem.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_B, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
 }
예제 #4
0
 protected void addGameOptionsMenu(final JMenu menuGame) {
   if (!gameData.getProperties().getEditableProperties().isEmpty()) {
     final AbstractAction optionsAction =
         SwingAction.of(
             "Game Options",
             e -> {
               final PropertiesUI ui =
                   new PropertiesUI(gameData.getProperties().getEditableProperties(), false);
               JOptionPane.showMessageDialog(frame, ui, "Game options", JOptionPane.PLAIN_MESSAGE);
             });
     menuGame.add(optionsAction).setMnemonic(KeyEvent.VK_O);
   }
 }
예제 #5
0
 /**
  * @param parent parent component
  * @param properties properties that will get displayed
  * @param buttonOptions button options. They will be displayed in a row on the bottom
  * @return pressed button
  */
 public static Object getButton(
     final JComponent parent,
     final String title,
     final List<IEditableProperty> properties,
     final Object... buttonOptions) {
   if (!SwingUtilities.isEventDispatchThread()) {
     // throw new IllegalStateException("Must run from EventDispatchThread");
     final AtomicReference<Object> rVal = new AtomicReference<>();
     SwingAction.invokeAndWait(
         () -> rVal.set(showDialog(parent, title, properties, buttonOptions)));
     return rVal.get();
   } else {
     return showDialog(parent, title, properties, buttonOptions);
   }
 }
예제 #6
0
 private void addShowDiceStats(final JMenu parentMenu) {
   final Action showDiceStats =
       SwingAction.of(
           "Show Dice Stats",
           e -> {
             final IRandomStats randomStats =
                 (IRandomStats)
                     game.getRemoteMessenger().getRemote(IRandomStats.RANDOM_STATS_REMOTE_NAME);
             final RandomStatsDetails stats = randomStats.getRandomStats(gameData.getDiceSides());
             JOptionPane.showMessageDialog(
                 frame,
                 new JScrollPane(stats.getAllStats()),
                 "Random Stats",
                 JOptionPane.INFORMATION_MESSAGE);
           });
   parentMenu.add(showDiceStats).setMnemonic(KeyEvent.VK_D);
 }
예제 #7
0
  private JMenu createGameMenu() {
    final JMenu menuGame = SwingComponents.newJMenu("Game", SwingComponents.KeyboardCode.G);
    addEditMode(menuGame);

    menuGame.addSeparator();
    menuGame.add(SwingAction.of("Engine Settings", e -> SettingsWindow.showWindow()));
    SoundOptions.addGlobalSoundSwitchMenu(menuGame);
    SoundOptions.addToMenu(menuGame);
    menuGame.addSeparator();
    menuGame.add(frame.getShowGameAction()).setMnemonic(KeyEvent.VK_G);
    menuGame.add(frame.getShowHistoryAction()).setMnemonic(KeyEvent.VK_H);
    menuGame.add(frame.getShowMapOnlyAction()).setMnemonic(KeyEvent.VK_M);

    menuGame.addSeparator();
    addGameOptionsMenu(menuGame);
    addShowVerifiedDice(menuGame);
    addPoliticsMenu(menuGame);
    addNotificationSettings(menuGame);
    addShowDiceStats(menuGame);
    addRollDice(menuGame);
    addBattleCalculatorMenu(menuGame);
    return menuGame;
  }
예제 #8
0
 /**
  * Blocks until all Swing event thread actions have completed.
  *
  * <p>Task is accomplished by adding a do-nothing event with SwingUtilities to the event thread
  * and then blocking until the do-nothing event is done.
  */
 public static void waitForSwingThreads() {
   // add a no-op action to the end of the swing event queue, and then wait for it
   SwingAction.invokeAndWait(() -> {});
 }
예제 #9
0
  @Override
  protected void layoutComponents() {

    final JLabel labelSettingName = new JLabel("Setting Name");
    Dimension dimension = labelSettingName.getPreferredSize();
    labelSettingName.setPreferredSize(dimension);
    final JLabel labelValue = new JLabel("Value");
    dimension = (Dimension) dimension.clone();
    dimension.width = DynamicRow.INPUT_FIELD_SIZE_SMALL;
    labelValue.setPreferredSize(dimension);
    final JLabel labelEditable = new JLabel("Editable");
    dimension = (Dimension) dimension.clone();
    dimension.width = DynamicRow.INPUT_FIELD_SIZE_SMALL;
    labelEditable.setPreferredSize(dimension);
    final JLabel labelMinNumber = new JLabel("Min. N.");
    dimension = (Dimension) dimension.clone();
    labelMinNumber.setPreferredSize(dimension);
    final JLabel labelMaxNumber = new JLabel("Max. N.");
    dimension = (Dimension) dimension.clone();
    labelMaxNumber.setPreferredSize(dimension);

    // <1> Set panel layout
    final GridBagLayout gbl_stepActionPanel = new GridBagLayout();
    setColumns(gbl_stepActionPanel);
    setRows(gbl_stepActionPanel, MapXmlHelper.getGameSettingsMap().size());
    getOwnPanel().setLayout(gbl_stepActionPanel);

    // <2> Add Row Labels: Setting Name, Alliance Name, Buy Quantity
    final GridBagConstraints gridBadConstLabelSettingName = new GridBagConstraints();
    gridBadConstLabelSettingName.insets = new Insets(0, 0, 5, 5);
    gridBadConstLabelSettingName.gridy = 0;
    gridBadConstLabelSettingName.gridx = 0;
    gridBadConstLabelSettingName.anchor = GridBagConstraints.WEST;
    getOwnPanel().add(labelSettingName, gridBadConstLabelSettingName);

    final GridBagConstraints gridBadConstLabelValue =
        (GridBagConstraints) gridBadConstLabelSettingName.clone();
    gridBadConstLabelValue.gridx = 1;
    getOwnPanel().add(labelValue, gridBadConstLabelValue);

    final GridBagConstraints gridBadConstLabelEditable =
        (GridBagConstraints) gridBadConstLabelSettingName.clone();
    gridBadConstLabelEditable.gridx = 2;
    getOwnPanel().add(labelEditable, gridBadConstLabelEditable);

    final GridBagConstraints gridBadConstLabelMinNumber =
        (GridBagConstraints) gridBadConstLabelSettingName.clone();
    gridBadConstLabelMinNumber.gridx = 3;
    getOwnPanel().add(labelMinNumber, gridBadConstLabelMinNumber);

    final GridBagConstraints gridBadConstLabelMaxNumber =
        (GridBagConstraints) gridBadConstLabelSettingName.clone();
    gridBadConstLabelMaxNumber.gridx = 4;
    getOwnPanel().add(labelMaxNumber, gridBadConstLabelMaxNumber);

    // <3> Add Main Input Rows
    int yValue = 1;

    final String[] settingNamesArray = settingNames.toArray(new String[settingNames.size()]);
    for (final Entry<String, List<String>> settingEntry :
        MapXmlHelper.getGameSettingsMap().entrySet()) {
      final GridBagConstraints gbc_tValue =
          (GridBagConstraints) gridBadConstLabelSettingName.clone();
      gbc_tValue.gridx = 0;
      gridBadConstLabelValue.gridy = yValue;
      final List<String> settingValue = settingEntry.getValue();
      int minValueInteger, maxValueInteger;
      try {
        minValueInteger = Integer.parseInt(settingValue.get(2));
        maxValueInteger = Integer.parseInt(settingValue.get(3));
      } catch (final NumberFormatException nfe) {
        minValueInteger = 0;
        maxValueInteger = 0;
      }
      final GameSettingsRow newRow =
          new GameSettingsRow(
              this,
              getOwnPanel(),
              settingEntry.getKey(),
              settingNamesArray,
              settingValue.get(0),
              settingValue.get(1),
              minValueInteger,
              maxValueInteger);
      newRow.addToParentComponentWithGbc(getOwnPanel(), yValue, gbc_tValue);
      rows.add(newRow);
      ++yValue;
    }

    // <4> Add Final Button Row
    final JButton buttonAddValue = new JButton("Add Game Setting");

    buttonAddValue.setFont(MapXmlUIHelper.defaultMapXMLCreatorFont);
    buttonAddValue.addActionListener(
        SwingAction.of(
            "Add Game Setting",
            e -> {
              final String suggestedSettingName =
                  (String)
                      JOptionPane.showInputDialog(
                          getOwnPanel(),
                          "Which game setting should be added?",
                          "Choose Game Setting",
                          JOptionPane.QUESTION_MESSAGE,
                          null,
                          settingNames.toArray(new String[settingNames.size()]), // Array of choices
                          settingNames.iterator().next()); // Initial choice
              if (suggestedSettingName == null || suggestedSettingName.isEmpty()) {
                return;
              }

              final ArrayList<String> newSettingValue = new ArrayList<>();
              final boolean settingIsBoolean = isBoolean(suggestedSettingName);
              final String newValue = settingIsBoolean ? "true" : "0";
              newSettingValue.add(newValue);
              newSettingValue.add("true");
              newSettingValue.add("0");
              newSettingValue.add("0");
              MapXmlHelper.putGameSettings(suggestedSettingName, newSettingValue);

              // UI Update
              setRows(
                  (GridBagLayout) getOwnPanel().getLayout(),
                  MapXmlHelper.getGameSettingsMap().size());
              addRowWith(suggestedSettingName, newValue, "true", 0, 0);
              SwingUtilities.invokeLater(
                  () -> {
                    getOwnPanel().revalidate();
                    getOwnPanel().repaint();
                  });
            }));
    addButton(buttonAddValue);

    final GridBagConstraints gridBadConstButtonAddUnit =
        (GridBagConstraints) gridBadConstLabelSettingName.clone();
    gridBadConstButtonAddUnit.gridx = 0;
    gridBadConstButtonAddUnit.gridy = yValue;
    addFinalButtonRow(gridBadConstButtonAddUnit);
  }