Package com.ledruide.druidecave.gui

Source Code of com.ledruide.druidecave.gui.BottleDetail

/**
* 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.business.CombosProxy;
import com.ledruide.druidecave.business.VigneronProxy;
import com.ledruide.druidecave.business.lists.ClassificationProxy;
import com.ledruide.druidecave.business.lists.ColorProxy;
import com.ledruide.druidecave.business.lists.CountryProxy;
import com.ledruide.druidecave.business.lists.DenominationProxy;
import com.ledruide.druidecave.business.lists.FormatProxy;
import com.ledruide.druidecave.business.lists.RegionProxy;
import com.ledruide.druidecave.dao.Bottle;
import com.ledruide.druidecave.dao.BottlePeer;
import com.ledruide.druidecave.helpers.I18nScreens;
import com.ledruide.druidegui.Stop;
import com.ledruide.druidegui.SwapFrame;
import com.ledruide.druidegui.tools.ComponentTools;
import com.ledruide.druidegui.tools.DruideJPanel;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;


public class BottleDetail extends DruideJPanel
{
   JLabel labelTitle = new JLabel();
   JButton buttonQuit = new JButton();
   JButton buttonHome = new JButton();
   JLabel labelCountry = new JLabel();
   JLabel labelRegion = new JLabel();
   JLabel labelDenomination = new JLabel();
   JLabel labelClassification = new JLabel();
   JLabel labelName = new JLabel();
   JLabel labelVigneron = new JLabel();
   JLabel image = new JLabel();
   JLabel labelYear = new JLabel();
   JTextField fieldYear = new JTextField();
   JLabel labelAwakening = new JLabel();
   JTextField fieldAwakening = new JTextField();
   JLabel labelQuantity = new JLabel();
   JTextField fieldPrice = new JTextField();
   JLabel labelColor = new JLabel();
   JLabel labelFormat = new JLabel();
   JButton buttonValidate = new JButton();
   JButton buttonDelete = new JButton();
   JButton buttonCancel = new JButton();
   JButton buttonTastings = new JButton();
   JComboBox comboCountry = new JComboBox();
   JComboBox comboRegion = new JComboBox();
   JComboBox comboDenomination = new JComboBox();
   JComboBox comboClassification = new JComboBox();
   JTextField fieldName = new JTextField();
   JComboBox comboVigneron = new JComboBox();
   JLabel labelPrice = new JLabel();
   JTextField fieldQuantity = new JTextField();
   JComboBox comboColor = new JComboBox();
   JComboBox comboFormat = new JComboBox();

   /**
    * Default constructor
    */
   public BottleDetail()
   {
      initializePanel();
   }

   public JPanel createPanel()
   {
      JPanel jpanel1 = new JPanel();
      FormLayout formlayout1 = new FormLayout("FILL:10PX:NONE,FILL:75PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX: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:20PX: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);

      labelTitle.setFont(new Font("Tahoma",Font.BOLD,11));
      labelTitle.setForeground(new Color(204,0,51));
      labelTitle.setName("labelTitle");
      labelTitle.setText("screen.bottle.detail.title");
      labelTitle.setHorizontalAlignment(JLabel.CENTER);
      jpanel1.add(labelTitle,cc.xywh(3,1,10,2));

      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(13,1));

      labelCountry.setName("labelCountry");
      labelCountry.setText("screen.bottle.detail.country");
      labelCountry.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelCountry,cc.xywh(6,4,3,1));

      labelRegion.setName("labelRegion");
      labelRegion.setText("screen.bottle.detail.region");
      labelRegion.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelRegion,cc.xywh(6,6,3,1));

      labelDenomination.setName("labelDenomination");
      labelDenomination.setText("screen.bottle.detail.denomination");
      labelDenomination.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelDenomination,cc.xywh(6,8,3,1));

      labelClassification.setName("labelClassification");
      labelClassification.setText("screen.bottle.detail.class");
      labelClassification.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelClassification,cc.xywh(6,10,3,1));

      labelName.setName("labelName");
      labelName.setText("screen.bottle.detail.name");
      labelName.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelName,cc.xywh(6,12,3,1));

      labelVigneron.setName("labelVigneron");
      labelVigneron.setText("screen.bottle.detail.vigneron");
      labelVigneron.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelVigneron,cc.xywh(6,14,3,1));

      image.setIcon(loadImage("img/bottles1.png"));
      image.setName("image");
      image.setText("JLabel");
      image.setHorizontalAlignment(JLabel.CENTER);
      jpanel1.add(image,cc.xywh(2,3,4,20));

      labelYear.setName("labelYear");
      labelYear.setText("screen.bottle.detail.year");
      labelYear.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelYear,cc.xywh(6,16,2,1));

      fieldYear.setName("fieldYear");
      jpanel1.add(fieldYear,cc.xywh(8,16,2,1));

      labelAwakening.setName("labelAwakening");
      labelAwakening.setText("screen.bottle.detail.awakening");
      labelAwakening.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelAwakening,cc.xywh(10,16,3,1));

      fieldAwakening.setName("fieldAwakening");
      jpanel1.add(fieldAwakening,cc.xy(13,16));

      labelQuantity.setName("labelQuantity");
      labelQuantity.setText("screen.bottle.detail.quantity");
      labelQuantity.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelQuantity,cc.xywh(6,18,3,1));

      fieldPrice.setName("fieldPrice");
      jpanel1.add(fieldPrice,cc.xy(13,18));

      labelColor.setName("labelColor");
      labelColor.setText("screen.bottle.detail.color");
      labelColor.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelColor,cc.xywh(6,20,3,1));

      labelFormat.setName("labelFormat");
      labelFormat.setText("screen.bottle.detail.format");
      labelFormat.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelFormat,cc.xywh(6,22,3,1));

      buttonValidate.setActionCommand("Valider");
      buttonValidate.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonValidate.setName("buttonValidate");
      buttonValidate.setOpaque(false);
      buttonValidate.setText("screen.bottle.detail.button.validate");
      jpanel1.add(buttonValidate,cc.xywh(11,26,3,1));

      buttonDelete.setActionCommand("Valider");
      buttonDelete.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonDelete.setName("buttonDelete");
      buttonDelete.setOpaque(false);
      buttonDelete.setText("screen.bottle.detail.button.delete");
      jpanel1.add(buttonDelete,cc.xywh(2,26,3,1));

      buttonCancel.setActionCommand("Valider");
      buttonCancel.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonCancel.setName("buttonCancel");
      buttonCancel.setOpaque(false);
      buttonCancel.setText("screen.bottle.detail.button.cancel");
      jpanel1.add(buttonCancel,cc.xywh(6,26,4,1));

      buttonTastings.setActionCommand("Liste des d�gustations");
      buttonTastings.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonTastings.setName("buttonTastings");
      buttonTastings.setOpaque(false);
      buttonTastings.setText("screen.bottle.detail.button.tastings");
      jpanel1.add(buttonTastings,cc.xywh(8,24,5,1));

      comboCountry.setName("comboCountry");
      jpanel1.add(comboCountry,cc.xywh(9,4,5,1));

      comboRegion.setName("comboRegion");
      jpanel1.add(comboRegion,cc.xywh(9,6,5,1));

      comboDenomination.setName("comboDenomination");
      jpanel1.add(comboDenomination,cc.xywh(9,8,5,1));

      comboClassification.setName("comboClassification");
      jpanel1.add(comboClassification,cc.xywh(9,10,5,1));

      fieldName.setName("fieldName");
      jpanel1.add(fieldName,cc.xywh(9,12,5,1));

      comboVigneron.setName("comboVigneron");
      jpanel1.add(comboVigneron,cc.xywh(9,14,5,1));

      labelPrice.setName("labelPrice");
      labelPrice.setText("screen.bottle.detail.price");
      labelPrice.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelPrice,cc.xywh(10,18,3,1));

      fieldQuantity.setName("fieldQuantity");
      jpanel1.add(fieldQuantity,cc.xy(9,18));

      comboColor.setName("comboColor");
      jpanel1.add(comboColor,cc.xywh(9,20,5,1));

      comboFormat.setName("comboFormat");
      jpanel1.add(comboFormat,cc.xywh(9,22,5,1));

      addFillComponents(jpanel1,new int[]{ 1,4,5,6,7,8,9,10,11,12,14 },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,26,27 });
      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);
        buttonCancel.addActionListener(this);
        buttonValidate.addActionListener(this);
        buttonTastings.addActionListener(this);
        buttonDelete.addActionListener(this);
        comboCountry.addActionListener(this);
        comboRegion.addActionListener(this);
        comboDenomination.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()));
        labelCountry.setText(I18nScreens.getInstance().get(labelCountry.getText()));
        labelRegion.setText(I18nScreens.getInstance().get(labelRegion.getText()));
        labelDenomination.setText(I18nScreens.getInstance().get(labelDenomination.getText()));
        labelClassification.setText(I18nScreens.getInstance().get(labelClassification.getText()));
        labelName.setText(I18nScreens.getInstance().get(labelName.getText()));
        labelVigneron.setText(I18nScreens.getInstance().get(labelVigneron.getText()));
        labelYear.setText(I18nScreens.getInstance().get(labelYear.getText()));
        labelAwakening.setText(I18nScreens.getInstance().get(labelAwakening.getText()));
        labelQuantity.setText(I18nScreens.getInstance().get(labelQuantity.getText()));
        labelPrice.setText(I18nScreens.getInstance().get(labelPrice.getText()));
        labelColor.setText(I18nScreens.getInstance().get(labelColor.getText()));
        labelFormat.setText(I18nScreens.getInstance().get(labelFormat.getText()));
        buttonCancel.setText(I18nScreens.getInstance().get(buttonCancel.getText()));
        buttonValidate.setText(I18nScreens.getInstance().get(buttonValidate.getText()));
        buttonDelete.setText(I18nScreens.getInstance().get(buttonDelete.getText()));
        buttonTastings.setText(I18nScreens.getInstance().get(buttonTastings.getText()));
    }

    public void initEach() throws Exception {
        comboCountry.removeAllItems();
        comboRegion.removeAllItems();
        comboDenomination.removeAllItems();
        comboClassification.removeAllItems();
        comboFormat.removeAllItems();
        comboColor.removeAllItems();
        comboVigneron.removeAllItems();
        CombosProxy.add(comboFormat, FormatProxy.getKeyValueList(), false);
        CombosProxy.add(comboColor, ColorProxy.getKeyValueList(), false);
        CombosProxy.add(comboVigneron, VigneronProxy.getKeyValueList(ComponentTools.getClefFromCombo(comboCountry),
                                                                     ComponentTools.getClefFromCombo(comboRegion),
                                                                     ComponentTools.getClefFromCombo(comboDenomination)), true);
        CombosProxy.add(comboCountry, CountryProxy.getKeyValueList(), true);

        Bottle bouteille =  BottlesProxy.getSessionBouteilleFromID();
        ComponentTools.positionnerCombo(comboCountry, bouteille.getCountry_id());
        ComponentTools.positionnerCombo(comboRegion, bouteille.getRegion_id());
        ComponentTools.positionnerCombo(comboDenomination, bouteille.getDenomination_id());
        ComponentTools.positionnerCombo(comboClassification, bouteille.getClassification_id());
        ComponentTools.positionnerCombo(comboFormat, bouteille.getFormat_id());
        ComponentTools.positionnerCombo(comboColor, bouteille.getColor_id());
        ComponentTools.positionnerCombo(comboVigneron, bouteille.getVigneron_id());
        fieldYear.setText(bouteille.getYear());
        fieldAwakening.setText(bouteille.getAwakening());
        fieldQuantity.setText(bouteille.getQuantity());
        fieldPrice.setText(bouteille.getPrice());
        fieldName.setText(bouteille.getName());

    }

    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(BottleSearch.class);
        }
        else if (e.getSource().equals(buttonDelete)) {
            try {
                if (showQuestion(I18nScreens.getInstance().get("screen.bottle.detail.button.delete.warning"))) {
                    Bottle boutanche = BottlesProxy.getSessionBouteilleFromID();
                    BottlePeer.delete(boutanche);
                    SwapFrame.getInstance().init(BottleSearch.class);
                }
                else {
                    SwapFrame.getInstance().init(BottleDetail.class);
                }

            }
            catch (Exception ex) {
                System.out.println("Impossible d'enregistrer ce r�coltant : ");
                // ERREUR
                ex.printStackTrace();
            }
        }
        else if (e.getSource().equals(buttonValidate)) {
            // Il nous faut enregistrer la bouteille !

            try {
                Bottle boutanche =  BottlesProxy.getSessionBouteilleFromID();
                boutanche.setYear(fieldYear.getText());
                boutanche.setAwakening(fieldAwakening.getText());
                boutanche.setDenomination_id(ComponentTools.getClefFromCombo(comboDenomination));
                boutanche.setClassification_id(ComponentTools.getClefFromCombo(comboClassification));
                boutanche.setFormat_id(ComponentTools.getClefFromCombo(comboFormat));
                boutanche.setName(fieldName.getText());
                boutanche.setCountry_id(ComponentTools.getClefFromCombo(comboCountry));
                boutanche.setPrice(fieldPrice.getText());
                boutanche.setQuantity(fieldQuantity.getText());
                boutanche.setVigneron_id(ComponentTools.getClefFromCombo(comboVigneron));
                boutanche.setRegion_id(ComponentTools.getClefFromCombo(comboRegion));
                boutanche.setColor_id(ComponentTools.getClefFromCombo(comboColor));

                if (boutanche.save()) {
                    SwapFrame.getInstance().init(BottleSearch.class);
                }
            }
            catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        else if (e.getSource().equals(buttonTastings)) {
            SwapFrame.getInstance().init(BottleTastingList.class);
        }
        else if (e.getSource().equals(comboCountry)) {
            // ici on met � jour les r�gions
            try {
                comboRegion.removeAllItems();
                CombosProxy.add(comboRegion, RegionProxy.getKeyValueList(ComponentTools.getClefFromCombo(comboCountry)), true);
            } catch (Exception ex) { ex.printStackTrace(); }
        }
        else if (e.getSource().equals(comboRegion)) {
            // ici on met � jour les appellations
            try {
                comboDenomination.removeAllItems();
                CombosProxy.add(comboDenomination, DenominationProxy.getKeyValueList(ComponentTools.getClefFromCombo(comboCountry), ComponentTools.getClefFromCombo(comboRegion)), true);
            } catch (Exception ex) { ex.printStackTrace(); }
        }
        else if (e.getSource().equals(comboDenomination)) {
            // ici on met � jour les appellations
            try {
                comboClassification.removeAllItems();
                CombosProxy.add(comboClassification, ClassificationProxy.getKeyValueList(ComponentTools.getClefFromCombo(comboCountry), ComponentTools.getClefFromCombo(comboRegion), ComponentTools.getClefFromCombo(comboDenomination)), true);
            } catch (Exception ex) { ex.printStackTrace(); }
        }
    }

    public int getPanelHeight() {
        return 475;
    }
}
TOP

Related Classes of com.ledruide.druidecave.gui.BottleDetail

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.