1 package micropolisj.research;
3 import java.awt.BorderLayout;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.Rectangle;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.io.Serializable;
11 import java.util.HashSet;
13 import java.util.ResourceBundle;
15 import javax.swing.JButton;
16 import javax.swing.JFrame;
17 import javax.swing.JLabel;
18 import javax.swing.JOptionPane;
19 import javax.swing.JPanel;
20 import javax.swing.JScrollPane;
21 import javax.swing.JToggleButton;
23 import micropolisj.engine.Micropolis;
24 import micropolisj.engine.MicropolisTool;
25 import micropolisj.gui.MainWindow;
27 public class ResearchState extends JFrame implements ActionListener, Serializable {
30 static ResourceBundle strings = ResourceBundle.getBundle(
"micropolisj.GuiStrings");
64 int buttonWidth = 250;
65 int buttonHeight = 100;
71 HashSet<Integer> reached_nodes;
77 public Map<MicropolisTool, JToggleButton>
toolBtns;
80 System.out.println(
"no but");
84 JScrollPane scrollPane;
87 JLabel researchPointsLabel;
135 reached_nodes =
new HashSet<Integer>();
137 setName(
"Research Tree");
138 setLayout(
new BorderLayout());
140 insidePane =
new JPanel();
141 insidePane.setLayout(null);
143 scrollPane =
new JScrollPane(insidePane);
145 add(scrollPane, BorderLayout.CENTER);
147 subMenu =
new JPanel();
148 subMenu.setLayout(
new BorderLayout());
149 add(subMenu, BorderLayout.SOUTH);
151 researchPointsLabel =
new JLabel(Integer.toString(
researchPoints) +
" " + strings.getString(
"research.POINTS_NAME") +
" ");
152 subMenu.add(researchPointsLabel, BorderLayout.EAST);
154 JPanel ppanel =
new JPanel();
155 ppanel.setLayout(
new FlowLayout(FlowLayout.CENTER));
156 subMenu.add(ppanel, BorderLayout.CENTER);
158 closeButton =
new JButton(strings.getString(
"research.CLOSE_BUTTON"));
159 closeButton.addActionListener(
new ActionListener() {
165 ppanel.add(closeButton);
168 buttons =
new JButton[n];
170 for(
int node_id = 0; node_id < n; node_id++) {
173 buttons[node_id] =
new JButton();
175 buttonWidth, buttonHeight));
177 buttons[node_id].setActionCommand(Integer.toString(node_id));
178 buttons[node_id].addActionListener(
this);
181 maxWidth = Math.max(maxWidth,
ResearchTree.positionsX[node_id] + buttonWidth);
182 maxHeight = Math.max(maxHeight,
ResearchTree.positionsY[node_id] + buttonHeight);
184 insidePane.add(buttons[node_id]);
187 insidePane.setPreferredSize(
new Dimension(maxWidth, maxHeight));
257 setBounds(200, 200, maxWidth + 40, maxHeight + 100);
266 researchPointsLabel.setText(Integer.toString(
researchPoints) +
" " + strings.getString(
"research.POINTS_NAME") +
" ");
268 for(
int node_id = 0; node_id <
ResearchTree.possible_nodes.length; node_id++) {
271 if(reached_nodes.contains(node_id)) {
272 buttons[node_id].setEnabled(
false);
273 buttons[node_id].setText(
"<html>" + node.
getName() + node.
getDesc() +
"</html>");
274 buttons[node_id].setBackground(Color.blue);
276 else if(!
tree.isReachable(reached_nodes, node_id)) {
277 buttons[node_id].setEnabled(
false);
278 buttons[node_id].setText(
"<html>"+node.
getName() + node.
getDesc() +
"</html>");
282 buttons[node_id].setEnabled(
true);
283 buttons[node_id].setText(
"<html>" + node.
getName() +
" (" + Integer.toString(node.
getCost()) +
"pts)" + node.
getDesc() +
"</html>");
292 int node_id = Integer.parseInt(ev.getActionCommand());
298 reached_nodes.add(node_id);
307 JOptionPane.showMessageDialog(
this, strings.getString(
"research.POINTS_MISSING"));