package view.componentes;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import util.Data;
import controller.operating.Strings;
public class StatusBar extends JPanel {
private static final long serialVersionUID = 2604907680947049228L;
private JLabel lblHora;
private JlabelLink jLabelLink = null;
private static final DateFormat FORMATO = new SimpleDateFormat("HH:mm:ss");
private JPanel cantinhoRiscado = null;
private JPanel jPanel = null;
private JPanel status = null;
private JLabel jLabelDescricaoAtividade = null; // @jve:decl-index=0:visual-constraint="374,91"
public StatusBar() {
// Iniciamos um timer para atualizar o rel�gio
Timer t = new Timer("ClockTimer", true);
// Pedimos para ele disparar a cada 1 segundo.
t.schedule(new ClockTask(), 0, 1000);
setLayout(new BorderLayout());
setPreferredSize(new Dimension(16, 23));
add(getLabelLink(), BorderLayout.WEST);
add(getNotification(), BorderLayout.EAST);
add(getVazio(), BorderLayout.CENTER);
setBackground(new Color(240, 240, 240));
}
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
graphics.setColor(Color.gray);
graphics.drawLine(0, 0, getWidth(), 0);
int r = 150, g = 150, b = 150;
for(int y = 1; y < 6; y++){
graphics.setColor(new Color(r, g, b));
graphics.drawLine(0, y, getWidth(), y);
r = r + 20;
g = g + 20;
b = b + 20;
}
}
private JPanel getCantinhoRiscado() {
if (cantinhoRiscado == null) {
cantinhoRiscado = new JPanel(new BorderLayout());
cantinhoRiscado.add(new JLabel(new AngledLinesWindowsCornerIcon()),
BorderLayout.SOUTH);
cantinhoRiscado.setOpaque(false);
}
return cantinhoRiscado;
}
private JPanel getVazio() {
if (status == null) {
status = new JPanel();
status.setLayout(null);
status.setOpaque(false);
status.add(getJLabelDescricaoAtividade(), null);
//TODO
}
return status;
}
/**
* This method initializes jLabelEditorAtivoDescricao
*
* @return javax.swing.JLabel
*/
private JLabel getJLabelDescricaoAtividade() {
if (jLabelDescricaoAtividade == null) {
jLabelDescricaoAtividade = new JLabel();
jLabelDescricaoAtividade.setText(Strings.release);
jLabelDescricaoAtividade.setBounds(new Rectangle(345, 4, 105, 14));
}
return jLabelDescricaoAtividade;
}
public void setLabelEditorAtivo(String atividade) {
jLabelDescricaoAtividade.setText(atividade);
}
private JPanel getNotification() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new BorderLayout());
jPanel.add(getLabelHora(), BorderLayout.WEST);
jPanel.add(getCantinhoRiscado());
jPanel.setOpaque(false);
}
return jPanel;
}
private JLabel getLabelHora() {
if (lblHora == null) {
lblHora = new JLabel();
Data data = new Data();
lblHora.setToolTipText(data.getData());
lblHora.setIcon(new ImageIcon(getClass().getResource("/view/images/barrinha.PNG")));
}
return lblHora;
}
private JlabelLink getLabelLink() {
if (jLabelLink == null) {
jLabelLink = new JlabelLink("http://www.fagoc.br/");
}
return jLabelLink;
}
public void setHora(Date date) {
getLabelHora().setText(FORMATO.format(date));
}
private class ClockTask extends TimerTask {
@Override
public void run() {
EventQueue.invokeLater(new Runnable() {
public void run() {
setHora(new Date());
}
});
}
}
}
class AngledLinesWindowsCornerIcon implements Icon {
private static final Color WHITE_LINE_COLOR = new Color(255, 255, 255);
private static final Color GRAY_LINE_COLOR = new Color(172, 168, 153);
private static final int WIDTH = 13;
private static final int HEIGHT = 13;
public int getIconHeight() {
return WIDTH;
}
public int getIconWidth() {
return HEIGHT;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
g.setColor(WHITE_LINE_COLOR);
g.drawLine(0, 12, 12, 0);
g.drawLine(5, 12, 12, 5);
g.drawLine(10, 12, 12, 10);
g.setColor(GRAY_LINE_COLOR);
g.drawLine(1, 12, 12, 1);
g.drawLine(2, 12, 12, 2);
g.drawLine(3, 12, 12, 3);
g.drawLine(6, 12, 12, 6);
g.drawLine(7, 12, 12, 7);
g.drawLine(8, 12, 12, 8);
g.drawLine(11, 12, 12, 11);
g.drawLine(12, 12, 12, 12);
}
}