package net.sf.cannagrower.gui;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import net.sf.cannagrower.data.Event;
import net.sf.cannagrower.util.DateTimeChooser;
import net.sf.cannagrower.i18n.Messages;
import net.sf.orexio.common.ui.PropertiesTable;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
public class PanelEvent extends javax.swing.JPanel{
static final long serialVersionUID = 1L;
private Event event; // @jve:decl-index=0:
private DateTimeChooser dateTimeChooser = null;
private JPanel jPanelHeader = null;
private JScrollPane jScrollPaneProperties = null;
private PropertiesTable jTableProperties = null;
private JLabel jLabelTitle = null;
private JPanel jPanelHeaderLabel = null;
private JPanel jPanelProperties = null;
/**
* This method initializes
*
*/
public PanelEvent() {
super();
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.add(getJPanelHeader(), BorderLayout.NORTH);
//this.add(getJPanelProperties(), BorderLayout.CENTER);
}
public void setEvent(Event event){
this.event=event;
getJLabelTitle().setText("<html><b>"+Messages.getMessage(Event.class.getSimpleName().toLowerCase()+"."+event.getClass().getSimpleName().toLowerCase())+"</b></html>");
getJLabelTitle().setIcon(Event.getIcon(event.getClass()));
getDateTimeChooser().setDate(event.getDate());
if(event.getProperties()!=null && !event.getProperties().isEmpty()){
this.add(getJPanelProperties(),BorderLayout.CENTER);
getJTableProperties().setProperties(event.getProperties());
}else{
this.remove(getJPanelProperties());
getJPanelProperties().setVisible(false);
}
}
/**
* This method initializes jTextFieldDateEditor
*
* @return com.toedter.calendar.JTextFieldDateEditor
*/
private DateTimeChooser getDateTimeChooser() {
if (dateTimeChooser == null) {
dateTimeChooser = new DateTimeChooser();
dateTimeChooser.addPropertyChangeListener("date",
new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent e) {
event.setDate(dateTimeChooser.getDate());
}
});
}
return dateTimeChooser;
}
/**
* This method initializes jPanelHeader
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelHeader() {
if (jPanelHeader == null) {
jPanelHeader = new JPanel();
jPanelHeader.setLayout(new BoxLayout(getJPanelHeader(),BoxLayout.Y_AXIS));
jPanelHeader.add(getJPanelHeaderLabel());
jPanelHeader.add(getDateTimeChooser());
}
return jPanelHeader;
}
public Event getEvent() {
return event;
}
/**
* This method initializes jScrollPaneProperties
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPaneProperties() {
if (jScrollPaneProperties == null) {
jScrollPaneProperties = new JScrollPane();
jScrollPaneProperties.setViewportView(getJTableProperties());
}
return jScrollPaneProperties;
}
/**
* This method initializes jTableProperties
*
* @return javax.swing.JTable
*/
private PropertiesTable getJTableProperties(){
if (jTableProperties == null) {
jTableProperties = new PropertiesTable();
}
return jTableProperties;
}
/**
* This method initializes jLabelTitle
*
* @return javax.swing.JLabel
*/
private JLabel getJLabelTitle() {
if (jLabelTitle == null) {
jLabelTitle = new JLabel();
}
return jLabelTitle;
}
/**
* This method initializes jPanelHeaderLabel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelHeaderLabel() {
if (jPanelHeaderLabel == null) {
jPanelHeaderLabel = new JPanel();
jPanelHeaderLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
jPanelHeaderLabel.setLayout(new BorderLayout());
jPanelHeaderLabel.add(getJLabelTitle(), BorderLayout.WEST);
}
return jPanelHeaderLabel;
}
/**
* This method initializes jPanelProperties
*
* @return javax.swing.JPanel
*/
protected JPanel getJPanelProperties() {
if (jPanelProperties == null) {
jPanelProperties = new JPanel();
jPanelProperties.setLayout(new BorderLayout());
jPanelProperties.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
jPanelProperties.add(getJScrollPaneProperties(), BorderLayout.CENTER);
}
return jPanelProperties;
}
}