com.squadd.javaBeans.ChatMessage.java Source code

Java tutorial

Introduction

Here is the source code for com.squadd.javaBeans.ChatMessage.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.squadd.javaBeans;

import com.squadd.managers.DBManager;
import com.squadd.views.ChatView;
import com.squadd.views.UserPageView;
import com.vaadin.event.MouseEvents;
import com.vaadin.event.MouseEvents.ClickListener;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
 *
 * @author Glebao
 */
public class ChatMessage {
    static DBManager man = new DBManager();
    /**
     *
     * @author Glebao
     */
    private Integer id;

    private Integer idFrom;

    private Integer idTo;

    private Date date;

    private String body;

    public ChatMessage() {
    }

    public ChatMessage(Integer id) {
        this.id = id;
    }

    public ChatMessage(Integer from, Integer to, Date date, String text) {
        this.idFrom = from;
        this.idTo = to;
        this.date = date;
        this.body = text;
    }

    public String getFormattedDate() {
        SimpleDateFormat formatedDate = new SimpleDateFormat("dd.MM.yyyy hh:mm");
        return formatedDate.format(this.date);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getIdFrom() {
        return idFrom;
    }

    public void setIdFrom(Integer idFrom) {
        this.idFrom = idFrom;
    }

    public Integer getIdTo() {
        return idTo;
    }

    public void setIdTo(Integer idTo) {
        this.idTo = idTo;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public static HorizontalLayout createChatLine2(ChatMessage message, ChatView view) {
        Integer from = message.getIdFrom();
        Integer to = message.getIdTo();
        String body = message.getBody();

        HorizontalLayout chatLine = new HorizontalLayout();

        String formattedDate = message.getFormattedDate();

        Label timeLabel = new Label(formattedDate);

        timeLabel.setWidth("10%");
        chatLine.addComponent(timeLabel);

        Label nameLabel = new Label(from + ": ");
        nameLabel.setWidth("15%");
        chatLine.addComponent(nameLabel);

        Label messageLabel = new Label(body);
        chatLine.addComponent(messageLabel);
        chatLine.setExpandRatio(messageLabel, 1);
        return chatLine;
    }

}