Package user

Source Code of user.PanelPrivateMessage

package user;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import main.ILanguage;
import database.DbwDBConnection;

public class PanelPrivateMessage extends JPanel implements IPanelPrivateMessage, ILanguage {

  /**
   *
   */
  private static final long serialVersionUID = 3911197893051810730L;
  private String       userName;
  private DbwDBConnection dataBaseConenction;
  private JLabel      senderTitle;
  private JLabel      sender;
  private JLabel      dateTitle;
  private JLabel      date;
  private JLabel      subjectTitle;
  private JLabel      subject;
  private JLabel      messageIDTitle;
  private JLabel      messageID;
  private JLabel      messageContentTitle;
  private JTextArea    messageContent;
  private JPanel      panelMessage;
  private JLabel      newMessage;
  private JButton      delete;
  private JButton      read;
  private PanelBottom    pb;

  public PanelPrivateMessage(PanelBottom pb, String userName){
    this.pb=pb;
    this.userName=userName;
    this.dataBaseConenction=new DbwDBConnection();

    createComponents();

  }
  public void createComponents(){

    Vector messagesNumber=new Vector<Integer>();
    messagesNumber=dataBaseConenction.getAllMessagesNumber(userName, 1);
   
    this.setLayout(new GridLayout(messagesNumber.size(),1));
    for(int i=0; i<messagesNumber.size();i++){
      if(!((Integer)messagesNumber.get(i)==0)){
        //this.add(panelMessage(userName,(Integer)messagesNumber.get(i)));
        this.add(new PanelMessage(pb,userName,(Integer)messagesNumber.get(i),1));
      }
      else{
        this.add(new JLabel(NO_PRIVATE_MESSAGE));
      }
    }

    //this.setPreferredSize(new Dimension(100,100));
  }


  public JPanel panelMessage(final String userName, final int messageNumber){
    this.senderTitle=new JLabel(SENDER);
    this.dateTitle=new JLabel(DATE);
    this.subjectTitle=new JLabel(SUBJECT);
    this.messageIDTitle=new JLabel(MESSAGE_ID);
    this.messageContentTitle=new JLabel(CONTENT);
    this.newMessage=new JLabel(NEW_MESSAGE);
    this.newMessage.setForeground(Color.RED);

    String message=dataBaseConenction.getMessage(userName, messageNumber);
    //String message="pascale#salut#27-09-2009#coucou chou, je t'aime...coucou chou, je t'aime...coucou chou, je t'aime...coucou chou, je t'aime...coucou chou, je t'aime...";
    this.sender=new JLabel(SENDER+message.split(SEPARATOR)[0]);
    this.subject=new JLabel(SUBJECT+message.split(SEPARATOR)[1]);
    this.date=new JLabel(DATE+message.split(SEPARATOR)[2]);
    this.messageContent=new JTextArea(message.split(SEPARATOR)[3]);
    this.messageContent.setEditable(false);

    this.messageID=new JLabel(MESSAGE_ID+SEPARATOR+messageNumber);

    this.delete=new JButton(DELETE_MESSAGE);
    this.delete.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        System.out.println("message number "+Integer.parseInt((PanelPrivateMessage.this.messageID.getText().split(SEPARATOR)[1])));
        System.out.println("user name  "+userName);
        System.out.println(dataBaseConenction);

        System.out.println(Integer.parseInt(messageID.getText().split(SEPARATOR)[1]));
        PanelPrivateMessage.this.dataBaseConenction.deleteMessage(Integer.parseInt(messageID.getText().split(SEPARATOR)[1]), userName);
        PanelPrivateMessage.this.repaint();
        PanelPrivateMessage.this.revalidate();

      }

    });


    this.read=new JButton(READ_MESSAGE);
    read.setEnabled(false);
    this.read.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        PanelPrivateMessage.this.dataBaseConenction.changeNewMessageToOld(userName, Integer.parseInt(messageID.getText().split(SEPARATOR)[1]));
        System.out.println( Integer.parseInt(messageID.getText().split(SEPARATOR)[1]));

        PanelPrivateMessage.this.messageContent.setForeground(Color.BLACK);
        PanelPrivateMessage.this.read.setEnabled(false);
        PanelPrivateMessage.this.repaint();

      }

    });


    if(dataBaseConenction.isNewMessage(userName, Integer.parseInt(messageID.getText().split(SEPARATOR)[1]))){
      //panelMessage.add(newMessage);
      read.setEnabled(true);
      messageContent.setForeground(Color.RED);

    }
    panelMessage=new JPanel(new GridLayout(7,1));

    JPanel panelButtons=new JPanel(new FlowLayout());
    panelButtons.add(read);
    panelButtons.add(delete);

    //panelMessage.add(senderTitle);
    panelMessage.add(sender);
    //panelMessage.add(subjectTitle);
    panelMessage.add(subject);
    //panelMessage.add(dateTitle);
    panelMessage.add(date);
    //panelMessage.add(messageIDTitle);
    panelMessage.add(messageID);
    panelMessage.add(messageContentTitle);
    panelMessage.add(messageContent);
    panelMessage.add(panelButtons);

    return panelMessage;
  }
  public static void main (String [] args){
    JFrame test= new JFrame ("test");

    Container pane = test.getContentPane();

    /*JScrollPane scrollPane = new JScrollPane(new PanelPrivateMessage("imad"));

    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    pane.add(scrollPane);
    test.setVisible(true);
    test.setSize(100, 50);
    //test.pack();*/
  }
}
TOP

Related Classes of user.PanelPrivateMessage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.