Source code: org/zazof/jteg/gui/MissionDialog.java
1 package org.zazof.jteg.gui;
2
3 import javax.swing.*;
4 import javax.swing.border.*;
5 import java.awt.*;
6 import java.awt.event.*;
7 import org.zazof.jteg.*;
8
9 /**
10 * This class implements the MissionDialog, which queries the user for the desired missiontype:
11 *
12 * @author Yves Vandewoude
13 *
14 */
15
16
17 public class MissionDialog extends JDialog implements WindowListener{
18
19 public MissionDialog(){
20
21 addWindowListener(this);
22
23 Dimension dimension = new Dimension(300,180);
24 setSize(dimension);
25
26 setVisible(true);
27 setResizable(false);
28
29 getContentPane().setLayout(new BorderLayout());
30
31 JPanel buttonPanel = new JPanel();
32 JButton okButton = new JButton(LanguageManager.getInstance().lookup("ok"));
33
34 okButton.addActionListener(new ActionListener(){
35 public void actionPerformed(ActionEvent ae){
36 try
37 {
38 if (DEBUG) System.out.println("MissionDialog: Removing MissionDialog");
39
40 GameController.getInstance().startGame(MissionDialog.this.getMissionMode());
41
42 JTEGStateMachine.getInstance().setCurrentState(JTEGStateMachine.GAME_STARTED);
43 MissionDialog.this.setVisible(false);
44 }
45 catch (Exception exc)
46 {
47 exc.printStackTrace();
48 }
49 }
50 });
51
52 JButton cancelButton = new JButton(LanguageManager.getInstance().lookup("cancel"));
53 cancelButton.addActionListener(new ActionListener(){
54 public void actionPerformed(ActionEvent ae){
55 MissionDialog.this.setVisible(false);
56 JTEGStateMachine.getInstance().setCurrentState(JTEGStateMachine.CONNECTED);
57 }
58 });
59 buttonPanel.add(okButton);
60 buttonPanel.add(cancelButton);
61
62 // The panel of the dialog
63 JPanel aPanel = new JPanel();
64 Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
65 aPanel.setBorder(padding);
66
67 // Asks the user to select his missiontype
68 Box radioBox = new Box(BoxLayout.Y_AXIS);
69 // make 2 radio buttons for selecting observer or player mode
70 ButtonGroup bg = new ButtonGroup();
71 $conquerWorld = new JRadioButton(LanguageManager.getInstance().lookup("conquerworld"), true);
72 $secretMission = new JRadioButton(LanguageManager.getInstance().lookup("secretmission"), false);
73 bg.add($conquerWorld);
74 bg.add($secretMission);
75 radioBox.add($conquerWorld);
76 radioBox.add($secretMission);
77
78 JLabel informationField = new JLabel(LanguageManager.getInstance().lookup("choosemission"));
79
80 // Add some whitespaces
81
82 Box topBox = new Box(BoxLayout.Y_AXIS);
83
84 aPanel.add(informationField, BorderLayout.NORTH);
85 aPanel.add(radioBox, BorderLayout.CENTER);
86 aPanel.add(buttonPanel, BorderLayout.SOUTH);
87 getContentPane().add(aPanel);
88 }
89
90
91 public int getMissionMode(){
92 int result = 0;
93 if ($conquerWorld.isSelected()) result = 1;
94 if ($secretMission.isSelected()) result = 0;
95 if (DEBUG) System.out.println("Selected mode: " + result);
96 return result;
97 }
98
99 // implementation of interface WindowListener
100 public void windowOpened(WindowEvent we){
101 }
102
103 public void windowClosed(WindowEvent we){
104 }
105
106 public void windowClosing(WindowEvent we){
107 System.out.println("Closing MissionDialog");
108 MissionDialog.this.setVisible(false);
109 JTEGStateMachine.getInstance().setCurrentState(JTEGStateMachine.CONNECTED);
110 }
111
112 public void windowIconified(WindowEvent we){
113 }
114
115 public void windowDeiconified(WindowEvent we){
116 }
117
118 public void windowActivated(WindowEvent we){
119 }
120
121 public void windowDeactivated(WindowEvent we){
122 }
123
124
125
126 private JRadioButton $conquerWorld;
127 private JRadioButton $secretMission;
128
129 private static boolean DEBUG = false;
130
131
132 }