-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathNotificationPane.java
More file actions
197 lines (157 loc) · 5.78 KB
/
NotificationPane.java
File metadata and controls
197 lines (157 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// This file is part of MicropolisJ.
// Copyright (C) 2013 Jason Long
// Portions Copyright (C) 1989-2007 Electronic Arts Inc.
//
// MicropolisJ is free software; you can redistribute it and/or modify
// it under the terms of the GNU GPLv3, with additional terms.
// See the README file, included in this distribution, for details.
package micropolisj.gui;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import micropolisj.engine.*;
import static micropolisj.gui.ColorParser.parseColor;
public class NotificationPane extends JPanel
{
JLabel headerLbl;
JViewport mapViewport;
MicropolisDrawingArea mapView;
JPanel mainPane;
JComponent infoPane;
MainWindow mainWindow;
CityLocation loc = null;
static final Dimension VIEWPORT_SIZE = new Dimension(160,160);
static final Color QUERY_COLOR = new Color(255,165,0);
static final ResourceBundle strings = MainWindow.strings;
static final ResourceBundle mstrings = ResourceBundle.getBundle("micropolisj.CityMessages");
static final ResourceBundle s_strings = ResourceBundle.getBundle("micropolisj.StatusMessages");
public NotificationPane(Micropolis engine, MainWindow mainWindow)
{
super(new BorderLayout());
this.mainWindow = mainWindow;
setVisible(false);
headerLbl = new JLabel();
headerLbl.setOpaque(true);
headerLbl.setHorizontalAlignment(SwingConstants.CENTER);
headerLbl.setBorder(BorderFactory.createRaisedBevelBorder());
JButton goBtn = new JButton(strings.getString("notification.go_btn"));
goBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onGoClicked();
}});
JPanel headerPane = new JPanel(new BorderLayout());
headerPane.add(headerLbl, BorderLayout.CENTER);
headerPane.add(goBtn, BorderLayout.EAST);
add(headerPane, BorderLayout.NORTH);
JButton dismissBtn = new JButton(strings.getString("notification.dismiss"));
dismissBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onDismissClicked();
}});
add(dismissBtn, BorderLayout.SOUTH);
mainPane = new JPanel(new BorderLayout());
add(mainPane, BorderLayout.CENTER);
JPanel viewportContainer = new JPanel(new BorderLayout());
viewportContainer.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(8,4,8,4),
BorderFactory.createLineBorder(Color.BLACK)
));
mainPane.add(viewportContainer, BorderLayout.WEST);
mapViewport = new JViewport();
mapViewport.setPreferredSize(VIEWPORT_SIZE);
mapViewport.setMaximumSize(VIEWPORT_SIZE);
mapViewport.setMinimumSize(VIEWPORT_SIZE);
viewportContainer.add(mapViewport, BorderLayout.CENTER);
mapView = new MicropolisDrawingArea(engine);
mapViewport.setView(mapView);
}
private void onDismissClicked()
{
setVisible(false);
}
private void onGoClicked()
{
if (loc != null) {
mainWindow.centering(loc);
}
}
void setPicture(Micropolis engine, int xpos, int ypos)
{
loc = new CityLocation(xpos, ypos);
Dimension sz = VIEWPORT_SIZE;
mapView.setEngine(engine);
Rectangle r = mapView.getTileBounds(xpos,ypos);
mapViewport.setViewPosition(new Point(
r.x + r.width/2 - sz.width/2,
r.y + r.height/2 - sz.height/2
));
}
public void showMessage(Micropolis engine, MicropolisMessage msg, int xpos, int ypos)
{
setPicture(engine, xpos, ypos);
if (infoPane != null) {
mainPane.remove(infoPane);
infoPane = null;
}
headerLbl.setText(mstrings.getString(msg.name()+".title"));
headerLbl.setBackground(parseColor(mstrings.getString(msg.name()+".color")));
JLabel myLabel = new JLabel("<html><p>"+
mstrings.getString(msg.name()+".detail") + "</p></html>");
myLabel.setPreferredSize(new Dimension(1,1));
infoPane = myLabel;
mainPane.add(myLabel, BorderLayout.CENTER);
setVisible(true);
}
public void showZoneStatus(Micropolis engine, int xpos, int ypos, ZoneStatus zone)
{
headerLbl.setText(strings.getString("notification.query_hdr"));
headerLbl.setBackground(QUERY_COLOR);
String buildingStr = zone.building != -1 ? s_strings.getString("zone."+zone.building) : "";
String popDensityStr = s_strings.getString("status."+zone.popDensity);
String landValueStr = s_strings.getString("status."+zone.landValue);
String crimeLevelStr = s_strings.getString("status."+zone.crimeLevel);
String pollutionStr = s_strings.getString("status."+zone.pollution);
String growthRateStr = s_strings.getString("status."+zone.growthRate);
setPicture(engine, xpos, ypos);
if (infoPane != null) {
mainPane.remove(infoPane);
infoPane = null;
}
JPanel p = new JPanel(new GridBagLayout());
mainPane.add(p, BorderLayout.CENTER);
infoPane = p;
GridBagConstraints c1 = new GridBagConstraints();
GridBagConstraints c2 = new GridBagConstraints();
c1.gridx = 0;
c2.gridx = 1;
c1.gridy = c2.gridy = 0;
c1.anchor = GridBagConstraints.WEST;
c2.anchor = GridBagConstraints.WEST;
c1.insets = new Insets(0,0,0,8);
c2.weightx = 1.0;
p.add(new JLabel(strings.getString("notification.zone_lbl")), c1);
p.add(new JLabel(buildingStr), c2);
c1.gridy = ++c2.gridy;
p.add(new JLabel(strings.getString("notification.density_lbl")), c1);
p.add(new JLabel(popDensityStr), c2);
c1.gridy = ++c2.gridy;
p.add(new JLabel(strings.getString("notification.value_lbl")), c1);
p.add(new JLabel(landValueStr), c2);
c1.gridy = ++c2.gridy;
p.add(new JLabel(strings.getString("notification.crime_lbl")), c1);
p.add(new JLabel(crimeLevelStr), c2);
c1.gridy = ++c2.gridy;
p.add(new JLabel(strings.getString("notification.pollution_lbl")), c1);
p.add(new JLabel(pollutionStr), c2);
c1.gridy = ++c2.gridy;
p.add(new JLabel(strings.getString("notification.growth_lbl")), c1);
p.add(new JLabel(growthRateStr), c2);
c1.gridy++;
c1.gridwidth = 2;
c1.weighty = 1.0;
p.add(new JLabel(), c1);
setVisible(true);
}
}