package gui;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.NumberFormat;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JLabel;
import javax.swing.JPanel;
import data.Clock;
import data.ExhibitionState;
import data.HourAdjustState;
import data.MinuteAdjustState;
@SuppressWarnings("serial")
public class DrawClock extends JPanel implements Observer{
private JLabel hour;
private JLabel colon;
private JLabel minute;
private Font fontNormal = new Font("Arial", Font.BOLD, 40);
private Font fontEditing = new Font("Arial", Font.BOLD, 50);
private NumberFormat format;
public DrawClock() {
hour = new JLabel("00");
colon = new JLabel(":");
minute = new JLabel("00");
hour.setFont(fontNormal);
minute.setFont(fontNormal);
colon.setFont(fontNormal);
format = NumberFormat.getInstance();
format.setMinimumIntegerDigits(2);
this.setLayout(new FlowLayout());
this.add(hour);
this.add(colon);
this.add(minute);
this.repaint();
}
@Override
public void update(Observable o, Object arg) {
if(arg instanceof Clock) {
Clock clock = (Clock) arg;
hour.setText(String.valueOf(format.format(clock.getHours())));
minute.setText(String.valueOf(format.format(clock.getMinutes())));
} else if(arg instanceof HourAdjustState) {
hour.setForeground(Color.GRAY);
hour.setFont(fontEditing);
} else if(arg instanceof MinuteAdjustState) {
hour.setForeground(Color.BLACK);
hour.setFont(fontNormal);
minute.setForeground(Color.GRAY);
minute.setFont(fontEditing);
} else if(arg instanceof ExhibitionState) {
minute.setForeground(Color.BLACK);
minute.setFont(fontNormal);
}
this.repaint();
}
}