1 package net.sourceforge.simplegamenet.framework.gui;
2
3 import java.awt.*;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import javax.swing.*;
7 import net.sourceforge.simplegamenet.specs.model.GameFactory;
8 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
9 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
10
11 public class GameChoicePanel extends JPanel implements ActionListener {
12
13 private ConnectionWizardDialog connectionWizardDialog;
14 private GameFactory[] gameFactories;
15
16 private JLabel selectGameLabel = new JLabel("Select a game:");
17 private JComboBox selectGameComboBox = new JComboBox();
18 private JTextArea gameDescriptionTextArea;
19 private JLabel gameAuthorLabel = new JLabel("Game author:");
20 private JLabel gameAuthorValueLabel;
21 private JLabel gameVersionLabel = new JLabel("Game version:");
22 private JLabel gameVersionValueLabel;
23
24 private int gameFactoriesIndex = 0;
25
26 GameChoicePanel(ConnectionWizardDialog connectionWizardDialog,
27 GameFactory[] gameFactories) {
28 super();
29 this.connectionWizardDialog = connectionWizardDialog;
30 this.gameFactories = gameFactories;
31 ProportionLayout layout = new ProportionLayout();
32 layout.appendColumn(10);
33 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
34 layout.appendColumn(10);
35 layout.appendColumn(0, 1.0);
36 layout.appendColumn(10);
37 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
38 layout.appendRow(10);
39 layout.appendRow(0, 1.0);
40 layout.appendRow(10);
41 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
42 layout.appendRow(10);
43 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
44 setLayout(layout);
45
46 for (int i = 0; i < gameFactories.length; i++) {
47 selectGameComboBox.addItem(gameFactories[i].getName());
48 }
49 selectGameComboBox.addActionListener(this);
50 ProportionLayout gameDescriptionLayout = new ProportionLayout();
51 gameDescriptionLayout.appendColumn(5);
52 gameDescriptionLayout.appendColumn(0, 1.0);
53 gameDescriptionLayout.appendColumn(5);
54 gameDescriptionLayout.appendRow(0);
55 gameDescriptionLayout.appendRow(0, 1.0);
56 gameDescriptionLayout.appendRow(5);
57 JPanel gameDescriptionPanel = new JPanel(gameDescriptionLayout);
58 gameDescriptionTextArea = new JTextArea(gameFactories[gameFactoriesIndex]
59 .getDescription());
60 gameDescriptionTextArea.setEnabled(false);
61 gameDescriptionTextArea.setLineWrap(true);
62 gameDescriptionTextArea.setWrapStyleWord(true);
63 JScrollPane gameDescriptionScrollPane = new JScrollPane(gameDescriptionTextArea,
64 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
65 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
66 gameDescriptionScrollPane.setPreferredSize(new Dimension(300, 150));
67 gameDescriptionPanel.add(gameDescriptionScrollPane,
68 new ProportionConstraints(1, 1));
69 gameDescriptionPanel.setBorder(BorderFactory.createTitledBorder("Description"));
70 gameAuthorValueLabel = new JLabel(gameFactories[gameFactoriesIndex].getAuthor());
71 gameVersionValueLabel = new JLabel(gameFactories[gameFactoriesIndex]
72 .getVersion().toString());
73 add(selectGameLabel, new ProportionConstraints(1, 0));
74 add(selectGameComboBox, new ProportionConstraints(3, 0));
75 add(gameDescriptionPanel, new ProportionConstraints(0, 2, 5, 1, 3, 2));
76 add(gameAuthorLabel, new ProportionConstraints(1, 4));
77 add(gameAuthorValueLabel, new ProportionConstraints(3, 4));
78 add(gameVersionLabel, new ProportionConstraints(1, 6));
79 add(gameVersionValueLabel, new ProportionConstraints(3, 6));
80 }
81
82 boolean areSettingsAcceptable() {
83 return true;
84 }
85
86 int getGameFactoriesIndex() {
87 return gameFactoriesIndex;
88 }
89
90 /***
91 * Invoked when an action occurs.
92 */
93 public void actionPerformed(ActionEvent actionEvent) {
94 gameFactoriesIndex = selectGameComboBox.getSelectedIndex();
95 gameDescriptionTextArea.setText(gameFactories[gameFactoriesIndex]
96 .getDescription());
97 gameVersionValueLabel.setText(gameFactories[gameFactoriesIndex]
98 .getVersion().toString());
99 gameAuthorValueLabel.setText(gameFactories[gameFactoriesIndex].getAuthor());
100 }
101
102 }