/**
  * Gets the constraints for the specified component. A copy of the actual <code>GridBagConstraints
  * </code> object is returned.
  *
  * @param comp the component to be queried
  * @return the constraint for the specified component in this grid bag layout; a copy of the
  *     actual constraint object is returned
  */
 public GridBagConstraints getConstraints(Component comp) {
   GridBagConstraints constraints = (GridBagConstraints) comptable.get(comp);
   if (constraints == null) {
     setConstraints(comp, defaultConstraints);
     constraints = (GridBagConstraints) comptable.get(comp);
   }
   return (GridBagConstraints) constraints.clone();
 }
示例#2
0
文件: GUIUtil.java 项目: Uefix/cibot
 public GridBagConstraints build() {
   return (GridBagConstraints) contraints.clone();
 }
 /**
  * Sets the constraints for the specified component in this layout.
  *
  * @param comp the component to be modified
  * @param constraints the constraints to be applied
  */
 public void setConstraints(Component comp, GridBagConstraints constraints) {
   comptable.put(comp, constraints.clone());
 }
示例#4
0
  public void setUpGameSetupPanel(GameSetupListener setupListener) {
    int boardSizeMaxDigits = 3;

    class PlayerSelectionListener implements ItemListener {
      /**
       * Constructor
       *
       * @param tabs panel whose state should be changed when event fired
       */
      public PlayerSelectionListener(JPanel tabs) {
        mTabs = tabs;
      }

      public void itemStateChanged(ItemEvent e) {
        PlayerType ptype = (PlayerType) e.getItem();
        CardLayout cl = (CardLayout) mTabs.getLayout();
        assert (cl.getClass() == CardLayout.class);
        cl.show(mTabs, ptype.toString());
      }

      private JPanel mTabs;
    }

    mGameSetupDialog = new JDialog(this, true);
    mGameSetupDialog.setTitle("Game setup");
    mGameSetupDialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    mGameSetupDialog.setSize(DIALOG_DIM);

    Container cpane = mGameSetupDialog.getContentPane();

    cpane.setLayout(new GridBagLayout());

    JLabel playerDes = new JLabel("Configure player");

    JComboBox<BotType> botType = new JComboBox<BotType>(BotType.values());
    JComboBox<PerfMeasureType> pmType = new JComboBox<PerfMeasureType>(PerfMeasureType.values());

    JButton addCustomPM = new JButton("+");
    addCustomPM.setVisible(false);
    CustomBotListener customAdder = new CustomBotListener(addCustomPM);
    addCustomPM.addActionListener(customAdder);
    pmType.addItemListener(customAdder);

    JTextField enterPlayerName = new JTextField("name");
    enterPlayerName.selectAll();
    setupListener.setupPlayerNameInput(enterPlayerName);

    JPanel botConfigPanel = new JPanel(new GridBagLayout());
    GridBagConstraints cBotType = new GridBagConstraints();
    cBotType.gridx = 0;
    cBotType.gridy = 0;
    cBotType.gridwidth = 1;
    cBotType.gridheight = 1;
    cBotType.fill = GridBagConstraints.BOTH;

    GridBagConstraints cPerfMeasureType = (GridBagConstraints) cBotType.clone();
    cPerfMeasureType.gridy = 1;
    GridBagConstraints cCustomAdder = (GridBagConstraints) cBotType.clone();
    cCustomAdder.gridx = 1;
    botConfigPanel.add(botType, cBotType);
    botConfigPanel.add(pmType, cPerfMeasureType);
    botConfigPanel.add(addCustomPM, cCustomAdder);
    setupListener.setupCustomBotListener(customAdder);

    JPanel playerConfigPanel = new JPanel(new CardLayout());
    playerConfigPanel.add(enterPlayerName, PlayerType.HUMAN.toString());
    playerConfigPanel.add(botConfigPanel, PlayerType.BOT.toString());

    JComboBox<PlayerType> playerType = new JComboBox<PlayerType>(PlayerType.values());
    PlayerSelectionListener listenPlayerSelection = new PlayerSelectionListener(playerConfigPanel);
    playerType.addItemListener(listenPlayerSelection);
    setupListener.setupTypeInput(playerType, botType, pmType);

    JLabel boardDes = new JLabel("Configure board");
    JTextField enterWidth = new JTextField("10");
    enterWidth.setColumns(boardSizeMaxDigits);
    JTextField enterHeight = new JTextField("15");
    enterHeight.setColumns(boardSizeMaxDigits);
    setupListener.setupBoardInputs(enterWidth, enterHeight);

    JButton startGameButton = new JButton("start");
    startGameButton.addActionListener(setupListener);

    int extSpace = 5;
    GridBagConstraints cUniversal = new GridBagConstraints();
    cUniversal.gridwidth = 1;
    cUniversal.gridheight = 1;
    cUniversal.fill = GridBagConstraints.BOTH;
    cUniversal.insets = new Insets(extSpace, extSpace, extSpace, extSpace);
    cUniversal.anchor = GridBagConstraints.CENTER;

    GridBagConstraints cDesPSelect = (GridBagConstraints) cUniversal.clone();
    cDesPSelect.gridx = 0;
    cDesPSelect.gridy = 0;
    cDesPSelect.gridwidth = 2;
    cDesPSelect.gridheight = 1;

    GridBagConstraints cPTypeSelect = (GridBagConstraints) cDesPSelect.clone();
    cPTypeSelect.gridy = 1;

    GridBagConstraints cPlayerSelection = (GridBagConstraints) cDesPSelect.clone();
    cPlayerSelection.gridy = 2;

    GridBagConstraints cDesBoardConfig = (GridBagConstraints) cUniversal.clone();
    cDesBoardConfig.gridx = 0;
    cDesBoardConfig.gridy = 3;
    cDesBoardConfig.gridwidth = 2;

    GridBagConstraints cBoardWInput;
    cBoardWInput = (GridBagConstraints) cDesBoardConfig.clone();
    cBoardWInput.gridy = 4;
    cBoardWInput.gridwidth = 1;
    cBoardWInput.weightx = 0.5;

    GridBagConstraints cBoardHInput;
    cBoardHInput = (GridBagConstraints) cBoardWInput.clone();
    cBoardHInput.gridx = 1;

    GridBagConstraints cStartButton;
    cStartButton = (GridBagConstraints) cDesPSelect.clone();
    cStartButton.gridy = 5;
    cStartButton.gridwidth = 2;

    mGameSetupDialog.add(playerDes, cDesPSelect);
    mGameSetupDialog.add(playerType, cPTypeSelect);
    mGameSetupDialog.add(playerConfigPanel, cPlayerSelection);
    mGameSetupDialog.add(boardDes, cDesBoardConfig);
    mGameSetupDialog.add(enterWidth, cBoardWInput);
    mGameSetupDialog.add(enterHeight, cBoardHInput);
    mGameSetupDialog.add(startGameButton, cStartButton);
  }