Package net.sf.cannagrower.gui

Source Code of net.sf.cannagrower.gui.PanelHardware

package net.sf.cannagrower.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.JButton;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

import net.sf.cannagrower.data.Hardware;
import net.sf.cannagrower.i18n.Messages;
import net.sf.cannagrower.util.DateChooser;
import net.sf.orexio.common.ui.PropertiesTable;
import java.awt.GridLayout;


/**
* This class is a panel used to visualize and edit a hardware
*
* @author alois_cochard@users.sf.net
*
*/
public class PanelHardware extends JPanel {

  private static final long serialVersionUID = 1L;

  private JTable jTableProperties = null;

  private JScrollPane jScrollPaneProperties = null;

  private Hardware hardware;

  private JPanel jPanelHeader = null;

  private JLabel jLabelInstallation = null;

  private JPanel jPanelHeaderWest = null;

  private JLabel jLabelDeinstallation = null;

  private JPanel jPanelHeaderLabel = null;

  private JPanel jPanelHeaderValue = null;

  private JPanel jPanelInstallationDate = null;

  private JPanel jPanelDeinstallationDate = null;

  private DateChooser dateChooserInstallation = null;

  private DateChooser dateChooserUninstallation = null;

  private JButton jButtonUninstallationClean = null;

  private JButton jButtonEmpty = null;

  private JPanel jPanelHeaderNorth = null;

  private JLabel jLabelTitle = null;
 
  /**
   * This is the default constructor
   *
   * @param hardware
   *            hardware to edit
   */
  public PanelHardware(Hardware hardware) {
    super();
    this.hardware = hardware;
    initialize();
  }

  /**
   * This method initializes this
   *
   * @return void
   */
  private void initialize() {
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.add(getJScrollPaneProperties(), BorderLayout.CENTER);
    this.add(getJPanelHeader(), BorderLayout.NORTH);
  }

  private JTable getJTableProperties() {
    if (jTableProperties == null) {
      // Loading table model
      jTableProperties = new PropertiesTable(hardware.getProperties());
      jTableProperties.setCellSelectionEnabled(true);
      jTableProperties.setShowGrid(false);
      jTableProperties
          .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }
    return jTableProperties;
  }

  private JScrollPane getJScrollPaneProperties() {
    if (jScrollPaneProperties == null) {
      jScrollPaneProperties = new JScrollPane();
      jScrollPaneProperties.setViewportView(getJTableProperties());
    }
    return jScrollPaneProperties;
  }

  private JPanel getJPanelHeader() {
    if (jPanelHeader == null) {
      jPanelHeader = new JPanel();
      jPanelHeader.setLayout(new BorderLayout());
      jPanelHeader.add(getJPanelHeaderNorth(), BorderLayout.NORTH);
      jPanelHeader.add(getJPanelHeaderWest(), BorderLayout.WEST);     
    }
    return jPanelHeader;
  }

  private JPanel getJPanelHeaderWest() {
    if (jPanelHeaderWest == null) {
      jPanelHeaderWest = new JPanel();
      jPanelHeaderWest.setLayout(new BoxLayout(getJPanelHeaderWest(), BoxLayout.X_AXIS));
      jPanelHeaderWest.setBorder(BorderFactory.createEmptyBorder(0, 0,
          5, 0));
      jPanelHeaderWest.add(getJPanelHeaderLabel(), null);
      jPanelHeaderWest.add(getJPanelHeaderValue(), null);
    }
    return jPanelHeaderWest;
  }

  private JPanel getJPanelHeaderLabel() {
    if (jPanelHeaderLabel == null) {
      GridLayout gridLayout = new GridLayout();
      gridLayout.setRows(2);
      gridLayout.setColumns(1);
      jPanelHeaderLabel = new JPanel();
      jPanelHeaderLabel.setLayout(gridLayout);
      jLabelInstallation = new JLabel();
      jLabelInstallation.setText(Messages
          .getMessage(Messages.hardwareInstallation)+"   ");
      jPanelHeaderLabel.add(jLabelInstallation, null);
      jLabelDeinstallation = new JLabel();
      jLabelDeinstallation.setText(Messages
          .getMessage(Messages.hardwareUninstallation)+"   ");
      jPanelHeaderLabel.add(jLabelDeinstallation, null);
    }
    return jPanelHeaderLabel;
  }

  private JPanel getJPanelHeaderValue() {
    if (jPanelHeaderValue == null) {
      GridLayout gridLayout1 = new GridLayout();
      gridLayout1.setRows(2);
      gridLayout1.setColumns(1);
      jPanelHeaderValue = new JPanel();
      jPanelHeaderValue.setLayout(gridLayout1);
      jPanelHeaderValue.add(getJPanelInstallationDate(), null);
      jPanelHeaderValue.add(getJPanelDeinstallationDate(), null);
    }
    return jPanelHeaderValue;
  }

  private JPanel getJPanelInstallationDate() {
    if (jPanelInstallationDate == null) {
      FlowLayout flowLayout = new FlowLayout();
      flowLayout.setAlignment(FlowLayout.LEFT);
      flowLayout.setVgap(0);
      flowLayout.setHgap(0);
      jPanelInstallationDate = new JPanel();
      jPanelInstallationDate.setLayout(flowLayout);
      jPanelInstallationDate.add(getDateChooserInstallation(), null);
      jPanelInstallationDate.add(getJButtonEmpty(), null);
    }
    return jPanelInstallationDate;
  }

  private JPanel getJPanelDeinstallationDate() {
    if (jPanelDeinstallationDate == null) {
      FlowLayout flowLayout1 = new FlowLayout();
      flowLayout1.setHgap(0);
      flowLayout1.setAlignment(FlowLayout.LEFT);
      flowLayout1.setVgap(0);
      jPanelDeinstallationDate = new JPanel();
      jPanelDeinstallationDate.setLayout(flowLayout1);
      jPanelDeinstallationDate.add(getDateChooserUninstallation(), null);
      jPanelDeinstallationDate.add(getJButtonUninstallationClean(), null);
    }
    return jPanelDeinstallationDate;
  }

  /**
   * This method initializes jDateChooserInstallation 
   *  
   * @return com.toedter.calendar.JDateChooser 
   */
  private DateChooser getDateChooserInstallation() {
    if (dateChooserInstallation == null) {
      dateChooserInstallation = new DateChooser();
      dateChooserInstallation.setDate(hardware.getInstallation());
      dateChooserInstallation.addPropertyChangeListener("date",
          new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
              Date date=dateChooserInstallation.getDate();
              if (date == null) {
                JOptionPane.showMessageDialog(null,Messages.getMessage(Messages.messageDateInvalid),hardware.getClass().getSimpleName(),JOptionPane.OK_OPTION);
                dateChooserInstallation.setDate(hardware.getInstallation(),false);
                return;
              } else {
                hardware.setInstallation(date);
              }
            }
          });
    }
    return dateChooserInstallation;
  }

  /**
   * This method initializes jDateChooserUninstallation 
   *  
   * @return com.toedter.calendar.JDateChooser 
   */
  private DateChooser getDateChooserUninstallation() {
    if (dateChooserUninstallation == null) {
      dateChooserUninstallation = new DateChooser();
      dateChooserUninstallation.setDate(hardware.getUninstallation());
      dateChooserUninstallation.addPropertyChangeListener("date",
          new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
              Date date = dateChooserUninstallation.getDate();
              hardware.setUninstallation(date);
            }
          });
    }
    return dateChooserUninstallation;
  }

  /**
   * This method initializes jButtonUninstallationClean 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonUninstallationClean() {
    if (jButtonUninstallationClean == null) {
      jButtonUninstallationClean = new JButton();
      jButtonUninstallationClean.setMnemonic(KeyEvent.VK_UNDEFINED);
      jButtonUninstallationClean.setIcon(new ImageIcon(getClass().getResource("/net/sf/cannagrower/images/clear_left_16.png")));
      jButtonUninstallationClean
          .addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
              hardware.setUninstallation(null);
              dateChooserUninstallation.setDate(hardware.getUninstallation(),false);
            }
          });
    }
    return jButtonUninstallationClean;
  }

  public Hardware getHardware() {
    return hardware;
  }

  /**
   * This method initializes jButtonEmpty 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonEmpty() {
    if (jButtonEmpty == null) {
      jButtonEmpty = new JButton();
      jButtonEmpty.setIcon(new ImageIcon(getClass().getResource("/net/sf/cannagrower/images/clear_left_16.png")));
      jButtonEmpty.setEnabled(false);
    }
    return jButtonEmpty;
  }

  /**
   * This method initializes jPanelHeaderNorth 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelHeaderNorth() {   
    if (jPanelHeaderNorth == null) {
      jLabelTitle = new JLabel();
     
      jLabelTitle.setText("<html><b>"+Messages.getMessage(Hardware.class.getSimpleName().toLowerCase()+ "." + hardware.getClass().getSimpleName().toLowerCase())+"</b></html>");
      jLabelTitle.setIcon(Hardware.getIcon(hardware.getClass()));
       
      jPanelHeaderNorth = new JPanel();
      jPanelHeaderNorth.setLayout(new BorderLayout());
      jPanelHeaderNorth.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
      jPanelHeaderNorth.add(jLabelTitle, BorderLayout.WEST);
    }
    return jPanelHeaderNorth;
  }

}
TOP

Related Classes of net.sf.cannagrower.gui.PanelHardware

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.