Package net.sf.cannagrower.gui

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

package net.sf.cannagrower.gui;

import net.sf.cannagrower.i18n.Messages;
import net.sf.cannagrower.data.Event;
import net.sf.cannagrower.data.event.DocumentPicture;
import net.sf.orexio.common.ui.PicturePanel;

import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;

public class PanelEventDocumentPicture extends PanelEvent {
  private static final long   serialVersionUID = 1L;
 
  public static JFileChooser fileChooser = new JFileChooser();
 
  private JPanel jPanelPicture = null;
  private PicturePanel jPanelPicturePanel=null;
  private JPanel jPanelPictureButtons = null;
  private JButton jButtonPictureChoose = null;
 
  public PanelEventDocumentPicture() {
    initialize();
  }

  /**
   * This method initializes this
   *
   */
  private void initialize() {
    this.add(getJPanelPicture(),BorderLayout.CENTER);
  }
 
  public void setEvent(Event event){
    DocumentPicture picture=(DocumentPicture)event;
   
    super.setEvent(event);
   
    try{
      if(picture.getFile().exists()){jPanelPicturePanel.setImage(picture.getFile());}
    }catch(IOException e){
      Messages.showException(e);
    }
  }

  /**
   * This method initializes jPanelPicture 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelPicture() {
    if (jPanelPicture == null) {
      jPanelPicture = new JPanel();
      jPanelPicture.setLayout(new BorderLayout());
      jPanelPicturePanel=new PicturePanel();
      jPanelPicture.add(jPanelPicturePanel,BorderLayout.CENTER);
      jPanelPicture.add(getJPanelPictureButtons(), BorderLayout.EAST);
    }
    return jPanelPicture;
  }

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

  /**
   * This method initializes jButtonPictureChoose 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonPictureChoose() {
    if (jButtonPictureChoose == null) {
      jButtonPictureChoose = new JButton();
      jButtonPictureChoose.setIcon(new ImageIcon(getClass().getResource("/net/sf/cannagrower/images/data/camera_16.png")));
      jButtonPictureChoose.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          pictureChoose();
        }
      });
    }
    return jButtonPictureChoose;
  }
 
  private void pictureChoose(){
    DocumentPicture picture=(DocumentPicture)getEvent();
   
    if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
      return;
    }
    // Copy file
    try{
      picture.setFile(fileChooser.getSelectedFile());
    }catch(IOException e){
      Messages.showException(e);
    }
   
    // Reload
    setEvent(getEvent());
  }
}
TOP

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

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.