|
|
@@ -6,40 +6,30 @@ import java.awt.Font;
|
|
|
import java.awt.Graphics2D;
|
|
|
import java.awt.Point;
|
|
|
import java.awt.Rectangle;
|
|
|
-import java.awt.Window;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseListener;
|
|
|
import java.awt.geom.GeneralPath;
|
|
|
-import java.awt.geom.Rectangle2D;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.GregorianCalendar;
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
+import javax.swing.JDialog;
|
|
|
|
|
|
public class Topbar implements MouseListener {
|
|
|
- private int oldwidth, people;
|
|
|
+ private int oldwidth;
|
|
|
private GeneralPath background;
|
|
|
- BufferedImage t1,t2,t3,t4,t5;
|
|
|
private GregorianCalendar time;
|
|
|
private Rectangle[] buttons;
|
|
|
+ private boolean[] buttonsState;
|
|
|
private Terrain terrain;
|
|
|
+ private SimulatorPane simulator;
|
|
|
|
|
|
- public Topbar(Terrain terrain){
|
|
|
+ public Topbar(Terrain terrain, SimulatorPane simulator){
|
|
|
background = new GeneralPath();
|
|
|
time = new GregorianCalendar();
|
|
|
buttons = new Rectangle[5];
|
|
|
+ buttonsState = new boolean[5];
|
|
|
this.terrain = terrain;
|
|
|
- try {
|
|
|
- t2 = ImageIO.read(Window.class.getResource("/topbar/play.png"));
|
|
|
- t1 = ImageIO.read(Window.class.getResource("/topbar/stop.png"));
|
|
|
- t3 = ImageIO.read(Window.class.getResource("/topbar/faster.png"));
|
|
|
- t4 = ImageIO.read(Window.class.getResource("/topbar/grid.png"));
|
|
|
- t5 = ImageIO.read(Window.class.getResource("/topbar/people.png"));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ this.simulator = simulator;
|
|
|
}
|
|
|
|
|
|
public void draw(Graphics2D g2, int screenwidth){
|
|
|
@@ -66,25 +56,22 @@ public class Topbar implements MouseListener {
|
|
|
g2.draw(background);
|
|
|
|
|
|
|
|
|
- g2.drawImage(t1, screenwidth/4 + 40, 7, null );
|
|
|
- g2.drawImage(t2, screenwidth/4 + 90, 7, null );
|
|
|
- g2.drawImage(t3, screenwidth/4 + 130, 7, null );
|
|
|
+ g2.drawImage(Images.getImage(Images.ImageType.TopbarStopButton), screenwidth/4 + 40, 7, null );
|
|
|
+ g2.drawImage(Images.getImage((!buttonsState[1]) ? Images.ImageType.TopbarPlayButton : Images.ImageType.TopbarPauzeButton), screenwidth/4 + 90, 7, null );
|
|
|
+ g2.drawImage(Images.getImage(Images.ImageType.TopbarFasterButton), screenwidth/4 + 130, 7, null );
|
|
|
|
|
|
g2.setFont(new Font("Sans-serif", Font.BOLD, 22));
|
|
|
g2.drawString(time.get(Calendar.HOUR_OF_DAY) + ":" + time.get(Calendar.MINUTE), screenwidth/2-10 , 28);
|
|
|
|
|
|
- g2.drawImage(t4, screenwidth/4*3 -60, 7, null );
|
|
|
+ g2.drawImage(Images.getImage(Images.ImageType.TopbarGridButton), screenwidth/4*3 -60, 7, null );
|
|
|
|
|
|
- g2.drawImage(t5, screenwidth/4*3 -150, 7, null );
|
|
|
+ g2.drawImage(Images.getImage(Images.ImageType.TopbarPeopleButton), screenwidth/4*3 -150, 7, null );
|
|
|
g2.setFont(new Font("Sans-serif", Font.PLAIN, 18));
|
|
|
- g2.drawString(people + "", screenwidth/4*3 - 120, 27);
|
|
|
+ g2.drawString(terrain.getMaxVisitors() + "", screenwidth/4*3 - 120, 27);
|
|
|
}
|
|
|
public void setTime(GregorianCalendar t){
|
|
|
time = t;
|
|
|
}
|
|
|
- public void setPeople(int p){
|
|
|
- people = p;
|
|
|
- }
|
|
|
public Rectangle[] getButtons(){
|
|
|
return buttons;
|
|
|
}
|
|
|
@@ -93,7 +80,22 @@ public class Topbar implements MouseListener {
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
int button = clickedButton(e.getPoint());
|
|
|
if(button >=0){
|
|
|
- if(button == 3) terrain.toggleGrid();
|
|
|
+ if(button == 3){
|
|
|
+ terrain.toggleGrid();
|
|
|
+ }else if(button == 0){
|
|
|
+ simulator.changeSpeed(SimulatorPane.Time.STOP);
|
|
|
+ time.setTimeInMillis(System.currentTimeMillis());
|
|
|
+ buttonsState[1] = false;
|
|
|
+ }else if(button == 1) {
|
|
|
+ simulator.changeSpeed((!buttonsState[1] ? SimulatorPane.Time.PLAY : SimulatorPane.Time.PAUZE));
|
|
|
+ buttonsState[1] = !buttonsState[1];
|
|
|
+ }else if(button == 2){
|
|
|
+ simulator.changeSpeed((!buttonsState[2] ? SimulatorPane.Time.FASTER : SimulatorPane.Time.FASTEST));
|
|
|
+ }else if(button == 4){
|
|
|
+ JDialog dialog = new VisitorsDialogPanel(terrain);
|
|
|
+ dialog.pack();
|
|
|
+ dialog.setVisible(true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
@@ -125,5 +127,7 @@ public class Topbar implements MouseListener {
|
|
|
public GeneralPath getBackground() {
|
|
|
return background;
|
|
|
}
|
|
|
-
|
|
|
+ public void recalculate(){
|
|
|
+ time.setTimeInMillis(time.getTimeInMillis()+10000);
|
|
|
+ }
|
|
|
}
|