/**
* Copyright (C) 2007 Julien Revault d'Allonnes
*
* This file is part of DruideCave.
*
* DruideCave is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DruideCave is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DruideCave; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.ledruide.druidecave.gui;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.ledruide.druidecave.business.BottlesProxy;
import com.ledruide.druidecave.dao.Bottle;
import com.ledruide.druidecave.dao.Tasting;
import com.ledruide.druidecave.helpers.I18nScreens;
import com.ledruide.druidegui.Stop;
import com.ledruide.druidegui.SwapFrame;
import com.ledruide.druidegui.helpers.DateOperator;
import com.ledruide.druidegui.helpers.TextTools;
import com.ledruide.druidegui.tools.DruideJPanel;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.Date;
public class BottleTastingSimple extends DruideJPanel
{
JButton buttonQuit = new JButton();
JButton buttonHome = new JButton();
JLabel labelTitle = new JLabel();
JTextField fieldDate = new JTextField();
JTextField fieldYear = new JTextField();
JTextField fieldNote = new JTextField();
JLabel labelNote = new JLabel();
JLabel labelYear = new JLabel();
JTextField fieldName = new JTextField();
JLabel labelName = new JLabel();
JLabel labelDate = new JLabel();
JLabel labelComment = new JLabel();
JButton buttonSave = new JButton();
JButton buttonCancel = new JButton();
JEditorPane fieldComment = new JEditorPane();
/**
* Default constructor
*/
public BottleTastingSimple()
{
initializePanel();
}
public JPanel createPanel()
{
JPanel jpanel1 = new JPanel();
FormLayout formlayout1 = new FormLayout("FILL:10PX:NONE,FILL:75PX:NONE,FILL:50PX:NONE,FILL:70PX:NONE,FILL:59PX:NONE,FILL:72PX:NONE,FILL:32PX:NONE,FILL:50PX:NONE,FILL:46PX:NONE,FILL:75PX:NONE,FILL:10PX:NONE","CENTER:17PX:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
CellConstraints cc = new CellConstraints();
jpanel1.setLayout(formlayout1);
buttonQuit.setActionCommand("Quitter");
buttonQuit.setFont(new Font("Dialog",Font.BOLD,10));
buttonQuit.setName("buttonQuit");
buttonQuit.setOpaque(false);
buttonQuit.setText("screen.button.quit");
jpanel1.add(buttonQuit,cc.xy(2,1));
buttonHome.setActionCommand("Quitter");
buttonHome.setFont(new Font("Dialog",Font.BOLD,10));
buttonHome.setName("buttonHome");
buttonHome.setOpaque(false);
buttonHome.setText("screen.button.home");
jpanel1.add(buttonHome,cc.xy(10,1));
labelTitle.setFont(new Font("Tahoma",Font.BOLD,12));
labelTitle.setForeground(new Color(204,0,51));
labelTitle.setName("labelTitle");
labelTitle.setText("screen.bottle.tasting.simple.title");
labelTitle.setHorizontalAlignment(JLabel.CENTER);
jpanel1.add(labelTitle,cc.xywh(3,1,7,2));
fieldDate.setName("fieldDate");
jpanel1.add(fieldDate,cc.xywh(5,6,2,1));
JLabel jlabel1 = new JLabel();
jlabel1.setIcon(loadImage("img/glass1.png"));
jlabel1.setHorizontalAlignment(JLabel.CENTER);
jpanel1.add(jlabel1,cc.xywh(2,8,4,15));
fieldYear.setBackground(new Color(240,245,250));
fieldYear.setEditable(false);
fieldYear.setName("fieldYear");
jpanel1.add(fieldYear,cc.xy(10,4));
fieldNote.setName("fieldNote");
jpanel1.add(fieldNote,cc.xy(10,6));
labelNote.setName("labelNote");
labelNote.setText("screen.bottle.tasting.simple.note");
labelNote.setHorizontalAlignment(JLabel.RIGHT);
jpanel1.add(labelNote,cc.xywh(7,6,3,1));
labelYear.setName("labelYear");
labelYear.setText("screen.bottle.tasting.simple.year");
labelYear.setHorizontalAlignment(JLabel.RIGHT);
jpanel1.add(labelYear,cc.xywh(7,4,3,1));
fieldName.setBackground(new Color(240,245,250));
fieldName.setEditable(false);
fieldName.setName("fieldName");
jpanel1.add(fieldName,cc.xywh(4,4,3,1));
labelName.setName("labelName");
labelName.setText("screen.bottle.tasting.simple.name");
labelName.setHorizontalAlignment(JLabel.RIGHT);
jpanel1.add(labelName,cc.xywh(2,4,2,1));
labelDate.setName("labelDate");
labelDate.setText("screen.bottle.tasting.simple.date");
labelDate.setHorizontalAlignment(JLabel.RIGHT);
jpanel1.add(labelDate,cc.xywh(2,6,3,1));
labelComment.setName("labelComment");
labelComment.setText("screen.bottle.tasting.simple.comment");
labelComment.setHorizontalAlignment(JLabel.CENTER);
jpanel1.add(labelComment,cc.xywh(6,8,5,1));
buttonSave.setActionCommand("Enregistrer");
buttonSave.setFont(new Font("Tahoma",Font.BOLD,11));
buttonSave.setName("buttonSave");
buttonSave.setOpaque(false);
buttonSave.setText("screen.bottle.tasting.simple.button.save");
jpanel1.add(buttonSave,cc.xywh(7,24,4,1));
buttonCancel.setActionCommand("Enregistrer");
buttonCancel.setFont(new Font("Tahoma",Font.BOLD,11));
buttonCancel.setName("buttonCancel");
buttonCancel.setOpaque(false);
buttonCancel.setText("screen.bottle.tasting.simple.button.cancel");
jpanel1.add(buttonCancel,cc.xywh(2,24,3,1));
fieldComment.setName("fieldComment");
JScrollPane jscrollpane1 = new JScrollPane();
jscrollpane1.setViewportView(fieldComment);
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jpanel1.add(jscrollpane1,cc.xywh(6,9,5,14));
addFillComponents(jpanel1,new int[]{ 1,4,5,6,7,8,9,11 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 });
return jpanel1;
}
/**
* Initializer
*/
protected void initializePanel()
{
setLayout(new BorderLayout());
add(createPanel(), BorderLayout.CENTER);
}
/* _____________________________________________________________________
| |
| IMPLEMENTATION DES METHODES QUI PERMETTENT |
| DE S'INSERER FACILEMENT DANS L'ARCHITECTURE GLOBALE |
|_____________________________________________________________________|
*/
public void initFirst() throws Exception {
buttonQuit.addActionListener(this);
buttonHome.addActionListener(this);
buttonSave.addActionListener(this);
buttonCancel.addActionListener(this);
}
public void initI18n() {
labelTitle.setText(I18nScreens.getInstance().get(labelTitle.getText()));
buttonQuit.setText(I18nScreens.getInstance().get(buttonQuit.getText()));
buttonHome.setText(I18nScreens.getInstance().get(buttonHome.getText()));
labelName.setText(I18nScreens.getInstance().get(labelName.getText()));
labelYear.setText(I18nScreens.getInstance().get(labelYear.getText()));
labelDate.setText(I18nScreens.getInstance().get(labelDate.getText()));
labelNote.setText(I18nScreens.getInstance().get(labelNote.getText()));
labelComment.setText(I18nScreens.getInstance().get(labelComment.getText()));
buttonCancel.setText(I18nScreens.getInstance().get(buttonCancel.getText()));
buttonSave.setText(I18nScreens.getInstance().get(buttonSave.getText()));
}
public void initEach() throws Exception {
Bottle bouteille = BottlesProxy.getSessionBouteilleFromID();
fieldName.setText(bouteille.getName());
fieldYear.setText(bouteille.getYear());
fieldDate.setText(DateOperator.transformDate(new Date(), 3));
fieldNote.setText("");
fieldComment.setText("");
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(buttonQuit)) {
Stop.close();
}
else if (e.getSource().equals(buttonHome)) {
SwapFrame.getInstance().init(Home.class);
}
else if (e.getSource().equals(buttonCancel)) {
SwapFrame.getInstance().init(BottleTastingList.class);
}
else if (e.getSource().equals(buttonSave)) {
try {
// SI le commentaire est vide on enregistre rien
if (!TextTools.isNullOrEmpty(fieldComment.getText())) {
Bottle bouteille = BottlesProxy.getSessionBouteilleFromID();
Tasting degust = new Tasting();
degust.setBoltle_id(bouteille.getId());
degust.setDate(fieldDate.getText());
degust.setNote(fieldNote.getText());
degust.setComment(fieldComment.getText());
degust.setType("Simple");
degust.save();
SwapFrame.getInstance().init(BottleTastingList.class);
}
}
catch (Exception e1) {
e1.printStackTrace();
}
}
}
public int getPanelHeight() {
return 340;
}
}