Package net.sf.cannagrower.util

Source Code of net.sf.cannagrower.util.DateChooser

package net.sf.cannagrower.util;

import javax.swing.JDialog;
import javax.swing.JPanel;
import java.util.Date;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Dimension;
import java.awt.BorderLayout;

import net.sf.cannagrower.i18n.Messages;

import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import org.jfree.ui.DateChooserPanel;

import net.sf.orexio.common.ui.Tools;

public class DateChooser extends JPanel {

  private static final long serialVersionUID = 1L;
 
  private Date date=null//  @jve:decl-index=0:
 
  private JTextField jTextField = null;
  private JButton jButton = null;
  private JDialog jDialogCalendar = null//  @jve:decl-index=0:visual-constraint="325,11"
  private JPanel jPanel = null;
  private JPanel jPanelSouth = null;
  private JButton jButtonOk = null;
  private JButton jButtonCancel = null;

  private JPanel jPanelButton = null;

  private DateChooserPanel dateChooserPanel = null;

  /**
   * This is the default constructor
   */
  public DateChooser() {
    super();
    initialize();
  }

  /**
   * This method initializes this
   *
   * @return void
   */
  private void initialize() {
    this.setSize(300, 200);
    this.setLayout(new BorderLayout());
    this.add(getJTextField(), BorderLayout.CENTER);
    this.add(getJPanelButton(), BorderLayout.EAST);
  }
 
  public Date getDate(){
    return date;
  }
 
  public void setDate(Date date){setDate(date,true);}
  public void setDate(Date date,boolean fireProperty){
    Date oldDate=this.date;
    this.date=date;
    if(date!=null){getJTextField().setText(dateToString(date));}
    else{getJTextField().setText("-");}
    if(fireProperty){firePropertyChange("date", oldDate, date);}
  }
 
  protected String dateToString(Date date){
    return java.text.DateFormat.getDateInstance().format(date);
  }

  /**
   * This method initializes jTextField 
   *  
   * @return javax.swing.JTextField 
   */
  private JTextField getJTextField() {
    if (jTextField == null) {
      jTextField = new JTextField();
      jTextField.setEditable(false);
      jTextField.setHorizontalAlignment(JTextField.CENTER);
      jTextField.setPreferredSize(new Dimension(120,0));
    }
    return jTextField;
  }

  /**
   * This method initializes jButton 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButton() {
    if (jButton == null) {
      jButton = new JButton();
      jButton.setIcon(new ImageIcon(DateChooser.class.getResource("/net/sf/cannagrower/util/date_16.gif")));
      jButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          jDialogCalendar=null;
          getJDialogCalendar().setVisible(true);
        }
      });
    }
    return jButton;
  }

  /**
   * This method initializes dateChooserCalendar 
   *  
   * @return net.sf.cannagrower.util.DateChooserCalendar 
   */
  private JDialog getJDialogCalendar() {   
    if (jDialogCalendar == null) {
      jDialogCalendar = new JDialog(Tools.getFrame(this));
      jDialogCalendar.setModal(true);
      jDialogCalendar.setUndecorated(true);
      jDialogCalendar.setContentPane(getJPanel());
      jDialogCalendar.setSize(240, 240);
      jDialogCalendar.setLocationRelativeTo(getJButton());
      doLoad();
    }
    return jDialogCalendar;
  }
 
  protected void doLoad(){
    if(date!=null){this.getDateChooserPanel().setDate(date);}
  }

  /**
   * This method initializes jPanel 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanel() {
    if (jPanel == null) {
      jPanel = new JPanel();
      jPanel.setLayout(new BorderLayout());
      jPanel.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
      jPanel.add(getDateChooserPanel(), BorderLayout.CENTER);
      jPanel.add(getJPanelSouth(), BorderLayout.SOUTH);
    }
    return jPanel;
  }

  /**
   * This method initializes jPanelSouth 
   *  
   * @return javax.swing.JPanel 
   */
  protected JPanel getJPanelSouth() {
    if (jPanelSouth == null) {
      jPanelSouth = new JPanel();
      jPanelSouth.setLayout(new FlowLayout());
      jPanelSouth.add(getJButtonOk(), null);
      jPanelSouth.add(getJButtonCancel(), null);
    }
    return jPanelSouth;
  }

  /**
   * This method initializes jButtonOk 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonOk() {
    if (jButtonOk == null) {
      jButtonOk = new JButton();
      jButtonOk.setText(Messages.getMessage(Messages.messageOk));
      jButtonOk.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          doOk();
          doClose();
        }
      });
    }
    return jButtonOk;
  }

  protected void doOk(){
    setDate(getDateChooserPanel().getDate());
  }
 
  protected void doClose(){
    getJDialogCalendar().setVisible(false);
  }
  /**
   * This method initializes jButtonCancel 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonCancel() {
    if (jButtonCancel == null) {
      jButtonCancel = new JButton();
      jButtonCancel.setText(Messages.getMessage(Messages.messageCancel));
      jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          doClose();
        }
      });
    }
    return jButtonCancel;
  }

  /**
   * This method initializes jPanelButton 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelButton() {
    if (jPanelButton == null) {
      FlowLayout flowLayout = new FlowLayout();
      flowLayout.setHgap(0);
      flowLayout.setVgap(0);
      jPanelButton = new JPanel();
      jPanelButton.setLayout(flowLayout);
      jPanelButton.add(getJButton(), null);
    }
    return jPanelButton;
  }

  /**
   * This method initializes dateChooserPanel 
   *  
   * @return org.jfree.ui.DateChooserPanel 
   */
  protected DateChooserPanel getDateChooserPanel() {
    if (dateChooserPanel == null) {
      dateChooserPanel = new DateChooserPanel();
    }
    return dateChooserPanel;
  }
}
TOP

Related Classes of net.sf.cannagrower.util.DateChooser

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.