From: Stefan F. <ste...@us...> - 2010-02-15 23:15:32
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv14583/rails/ui/swing Modified Files: GameSetupWindow.java Log Message: Add button to GameSetupWindow that allows randomizing the player order at startup. Index: GameSetupWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameSetupWindow.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GameSetupWindow.java 31 Jan 2010 22:22:34 -0000 1.21 --- GameSetupWindow.java 15 Feb 2010 23:15:13 -0000 1.22 *************** *** 1,3 **** ! /* $Header$*/ package rails.ui.swing; --- 1,3 ---- ! /* $Header$*/ package rails.ui.swing; *************** *** 27,31 **** JPanel gameListPane, playersPane, buttonPane, optionsPane; JButton newButton, loadButton, quitButton, optionButton, infoButton; ! JButton creditsButton; JComboBox gameNameBox = new JComboBox(); JComboBox[] playerBoxes = new JComboBox[Player.MAX_PLAYERS]; --- 27,31 ---- JPanel gameListPane, playersPane, buttonPane, optionsPane; JButton newButton, loadButton, quitButton, optionButton, infoButton; ! JButton creditsButton, randomizeButton; JComboBox gameNameBox = new JComboBox(); JComboBox[] playerBoxes = new JComboBox[Player.MAX_PLAYERS]; *************** *** 259,263 **** --- 259,281 ---- break; } + } + } else if (arg0.getSource().equals(randomizeButton)) { + // randomize the order of the players + if (playerNameFields.length > 0) { + List<String> playerList = new ArrayList<String>(); + for (int i = 0; i < playerNameFields.length; i++) { + if (playerNameFields[i] != null + && playerNameFields[i].getText().length() > 0) { + playerList.add(playerNameFields[i].getText()); + playerNameFields[i].setText(""); + } + } + Collections.shuffle(playerList); + for (int i = 0; i < playerList.size(); i++) { + playerNameFields[i].setText(playerList.get(i)); + + } } + fillPlayersPane(); } } *************** *** 426,430 **** playersPane.setBorder(BorderFactory.createLoweredBevelBorder()); playersPane.add(new JLabel("Players:")); ! playersPane.add(new JLabel("")); for (int i = 0; i < GamesInfo.getMaxPlayers(gameName); i++) { --- 444,453 ---- playersPane.setBorder(BorderFactory.createLoweredBevelBorder()); playersPane.add(new JLabel("Players:")); ! // playersPane.add(new JLabel("")); replaced by randomize button ! ! randomizeButton = new JButton(LocalText.getText("RandomizePlayers")); ! randomizeButton.setMnemonic(KeyEvent.VK_R); ! randomizeButton.addActionListener(this); ! playersPane.add(randomizeButton); for (int i = 0; i < GamesInfo.getMaxPlayers(gameName); i++) { |