9 package micropolisj.gui;
12 import java.awt.event.*;
17 import micropolisj.engine.*;
18 import static micropolisj.gui.MainWindow.formatFunds;
25 JLabel[] voterProblemLbl;
26 JLabel[] voterCountLbl;
35 static ResourceBundle cstrings = ResourceBundle.getBundle(
"micropolisj.CityStrings");
36 static ResourceBundle gstrings =
MainWindow.strings;
39 super(
new BorderLayout());
41 JButton dismissBtn =
new JButton(gstrings.getString(
"dismiss-evaluation"));
42 dismissBtn.addActionListener(
new ActionListener() {
43 public void actionPerformed(ActionEvent evt) {
47 add(dismissBtn, BorderLayout.SOUTH);
49 Box b1 =
new Box(BoxLayout.X_AXIS);
50 add(b1, BorderLayout.CENTER);
53 b1.add(
new JSeparator(SwingConstants.VERTICAL));
56 assert _engine != null;
76 JPanel me =
new JPanel(
new GridBagLayout());
77 GridBagConstraints c1 =
new GridBagConstraints();
78 GridBagConstraints c2 =
new GridBagConstraints();
79 GridBagConstraints c3 =
new GridBagConstraints();
82 c1.gridx = c1.gridy = 0;
86 c1.fill = GridBagConstraints.NONE;
87 c1.anchor = GridBagConstraints.NORTH;
89 JLabel headerLbl =
new JLabel(gstrings.getString(
"public-opinion"));
90 Font curFont = headerLbl.getFont();
91 headerLbl.setFont(curFont.deriveFont(curFont.getStyle() | Font.BOLD, (float) (curFont.getSize() * 1.2)));
92 me.add(headerLbl, c1);
95 c1.insets =
new Insets(3, 0, 3, 0);
96 me.add(
new JLabel(gstrings.getString(
"public-opinion-1")), c1);
99 me.add(
new JLabel(gstrings.getString(
"public-opinion-2")), c1);
103 c2.gridwidth = c2.gridheight = 1;
105 c2.anchor = GridBagConstraints.EAST;
106 c2.insets =
new Insets(0, 0, 0, 4);
108 me.add(
new JLabel(gstrings.getString(
"public-opinion-yes")), c2);
111 me.add(
new JLabel(gstrings.getString(
"public-opinion-no")), c2);
114 c3.gridwidth = c3.gridheight = 1;
116 c3.anchor = GridBagConstraints.WEST;
117 c3.insets =
new Insets(0, 4, 0, 0);
120 yesLbl =
new JLabel();
124 noLbl =
new JLabel();
127 c2.gridy = c3.gridy = 5;
129 final int NUM_PROBS = 4;
130 voterProblemLbl =
new JLabel[NUM_PROBS];
131 voterCountLbl =
new JLabel[NUM_PROBS];
132 for(
int i = 0; i < NUM_PROBS; i++) {
133 voterProblemLbl[i] =
new JLabel();
134 me.add(voterProblemLbl[i], c2);
136 voterCountLbl[i] =
new JLabel();
137 me.add(voterCountLbl[i], c3);
139 c2.gridy = ++c3.gridy;
145 me.add(
new JLabel(), c1);
151 JPanel me =
new JPanel(
new GridBagLayout());
152 GridBagConstraints c1 =
new GridBagConstraints();
153 GridBagConstraints c2 =
new GridBagConstraints();
154 GridBagConstraints c3 =
new GridBagConstraints();
156 c1.gridx = c1.gridy = 0;
160 c1.fill = GridBagConstraints.NONE;
161 c1.anchor = GridBagConstraints.NORTH;
162 c1.insets =
new Insets(0, 0, 3, 0);
164 JLabel headerLbl =
new JLabel(gstrings.getString(
"statistics-head"));
165 Font curFont = headerLbl.getFont();
166 headerLbl.setFont(curFont.deriveFont(curFont.getStyle() | Font.BOLD, (float) (curFont.getSize() * 1.2)));
167 me.add(headerLbl, c1);
170 c1.insets =
new Insets(9, 0, 3, 0);
171 c1.fill = GridBagConstraints.VERTICAL;
172 JLabel header2Lbl =
new JLabel(gstrings.getString(
"city-score-head"));
173 me.add(header2Lbl, c1);
176 c2.gridwidth = c2.gridheight = 1;
178 c2.anchor = GridBagConstraints.EAST;
179 c2.insets =
new Insets(0, 0, 0, 4);
182 c3.gridwidth = c3.gridheight = 1;
184 c3.anchor = GridBagConstraints.WEST;
185 c3.insets =
new Insets(0, 4, 0, 0);
187 c2.gridy = c3.gridy = 1;
188 me.add(
new JLabel(gstrings.getString(
"stats-population")), c2);
189 popLbl =
new JLabel();
192 c2.gridy = ++c3.gridy;
193 me.add(
new JLabel(gstrings.getString(
"stats-net-migration")), c2);
194 deltaLbl =
new JLabel();
195 me.add(deltaLbl, c3);
197 c2.gridy = ++c3.gridy;
198 me.add(
new JLabel(gstrings.getString(
"stats-last-year")), c2);
200 c2.gridy = ++c3.gridy;
201 me.add(
new JLabel(gstrings.getString(
"stats-assessed-value")), c2);
202 assessLbl =
new JLabel();
203 me.add(assessLbl, c3);
205 c2.gridy = ++c3.gridy;
206 me.add(
new JLabel(gstrings.getString(
"stats-category")), c2);
207 cityClassLbl =
new JLabel();
208 me.add(cityClassLbl, c3);
210 c2.gridy = ++c3.gridy;
211 me.add(
new JLabel(gstrings.getString(
"stats-game-level")), c2);
212 gameLevelLbl =
new JLabel();
213 me.add(gameLevelLbl, c3);
215 c2.gridy = c3.gridy = 21;
216 me.add(
new JLabel(gstrings.getString(
"city-score-current")), c2);
217 scoreLbl =
new JLabel();
218 me.add(scoreLbl, c3);
220 c2.gridy = ++c3.gridy;
221 me.add(
new JLabel(gstrings.getString(
"city-score-change")), c2);
222 scoreDeltaLbl =
new JLabel();
223 me.add(scoreDeltaLbl, c3);
228 c1.insets =
new Insets(0, 0, 0, 0);
229 me.add(
new JLabel(), c1);
259 NumberFormat pctFmt = NumberFormat.getPercentInstance();
261 yesLbl.setText(pctFmt.format(0.01 * info.evaluation.cityYes));
262 noLbl.setText(pctFmt.format(0.01 * info.evaluation.cityNo));
264 for (
int i = 0; i < voterProblemLbl.length; i++) {
265 CityProblem p = i < info.evaluation.problemOrder.length ? info.evaluation.problemOrder[i] : null;
266 int numVotes = p != null ? info.evaluation.problemVotes.get(p) : 0;
269 voterProblemLbl[i].setText(cstrings.getString(
"problem." + p.name()));
270 voterCountLbl[i].setText(pctFmt.format(0.01 * numVotes));
271 voterProblemLbl[i].setVisible(
true);
272 voterCountLbl[i].setVisible(
true);
275 voterProblemLbl[i].setVisible(
false);
276 voterCountLbl[i].setVisible(
false);
280 NumberFormat nf = NumberFormat.getInstance();
281 popLbl.setText(nf.format(info.evaluation.cityPop));
282 deltaLbl.setText(nf.format(info.evaluation.deltaCityPop));
283 assessLbl.setText(formatFunds(info.evaluation.cityAssValue));
284 cityClassLbl.setText(getCityClassName(info.evaluation.cityClass));
285 gameLevelLbl.setText(getGameLevelName(engine.
gameLevel));
286 scoreLbl.setText(nf.format(info.evaluation.cityScore));
287 scoreDeltaLbl.setText(nf.format(info.evaluation.deltaCityScore));
290 static String getCityClassName(
int cityClass) {
291 return cstrings.getString(
"class." + cityClass);
294 static String getGameLevelName(
int gameLevel) {
295 return cstrings.getString(
"level." + gameLevel);