package user;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import main.ILanguage;
import database.DbwDBConnection;
public class PanelTop extends JPanel implements IPanelTop, ILanguage{
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel mainTitle;
private JLabel mainWelcomeMessage;
private JLabel newPrivateMessage;
private JLabel newPublicMessage;
private JLabel labelUserName;
private String userName;
private DbwDBConnection databaseConnection;
public PanelTop(String userName){
this.userName=userName;
this.mainTitle=new JLabel();
this.mainWelcomeMessage=new JLabel();
this.newPrivateMessage=new JLabel();
this.newPublicMessage=new JLabel();
this.labelUserName= new JLabel();
this.databaseConnection = new DbwDBConnection();
this.createLabels();
}
@Override
public int setNewMessageNumber(String userName, int messageType) {
return databaseConnection.getNewMessagesNumber(userName,messageType);
}
public void createLabels(){
this.mainTitle.setText(MAIN_TITLE);
this.mainWelcomeMessage.setText(WELCOME_MESSAGE);
this.labelUserName.setText(this.userName+",");
this.labelUserName.setForeground(Color.RED);
this.newPrivateMessage.setText(NEW_MESSAGE_TEXT_1 + this.setNewMessageNumber(userName,1) + NEW_MESSAGE_TEXT_PRIVATE);
System.out.println(newPrivateMessage.getText());
this.newPublicMessage.setText(NEW_MESSAGE_TEXT_1 + this.setNewMessageNumber(userName,0) + NEW_MESSAGE_TEXT_PUBLIC);
System.out.println(newPublicMessage.getText());
this.mainTitle.setForeground(Color.BLUE);
Font fontTitre = new Font(this.mainTitle.getText(),Font.BOLD,35);
this.mainTitle.setFont(fontTitre);
JPanel panelTitle = new JPanel();
panelTitle.add(mainTitle);
JPanel panelName=new JPanel(new GridLayout(1,2));
panelName.add(mainWelcomeMessage);
panelName.add(labelUserName);
JPanel panelWelcomeMessages = new JPanel(new GridLayout(3,1));
panelWelcomeMessages.add(panelName);
panelWelcomeMessages.add(newPrivateMessage);
panelWelcomeMessages.add(newPublicMessage);
this.setLayout(new BorderLayout());
this.add(panelTitle, BorderLayout.PAGE_START);
this.add(panelWelcomeMessages, BorderLayout.WEST);
}
public static void main (String [] args){
JFrame test= new JFrame ("test");
Container pane = test.getContentPane();
pane.add(new PanelTop("dupont"));
test.setVisible(true);
//test.setSize(700, 300);
test.pack();
}
}