package com.ledruide.druidecave.gui;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.ledruide.druidecave.helpers.DruideCaveProps;
import com.ledruide.druidecave.helpers.I18nScreens;
import com.ledruide.druidegui.SwapFrame;
import com.ledruide.druidegui.helpers.KeyValueBean;
import com.ledruide.druidegui.helpers.Session;
import com.ledruide.druidegui.helpers.SessionConstants;
import com.ledruide.druidegui.helpers.i18n.DruideGUII18n;
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 java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.Locale;
public class Languages extends DruideJPanel
{
JComboBox comboLanguages = new JComboBox();
JButton buttonValidate = new JButton();
JLabel labelTitle = new JLabel();
/**
* Default constructor
*/
public Languages()
{
initializePanel();
}
public JPanel createPanel()
{
JPanel jpanel1 = new JPanel();
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:42PX:NONE,FILL:84PX:NONE,FILL:42PX:NONE,FILL: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);
comboLanguages.setName("comboLanguages");
jpanel1.add(comboLanguages,cc.xywh(2,6,3,1));
buttonValidate.setActionCommand("OK");
buttonValidate.setFont(new Font("Tahoma",Font.BOLD,11));
buttonValidate.setName("buttonValidate");
buttonValidate.setOpaque(false);
buttonValidate.setText("screen.languages.button");
jpanel1.add(buttonValidate,cc.xy(3,9));
labelTitle.setFont(new Font("Tahoma",Font.BOLD,12));
labelTitle.setName("labelTitle");
labelTitle.setText("screen.languages.subtitle");
labelTitle.setHorizontalAlignment(JLabel.CENTER);
jpanel1.add(labelTitle,cc.xywh(2,2,3,2));
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10 });
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 |
|_____________________________________________________________________|
*/
/**
* Permet de personaliser l'initialisation des champs...<br>
* N'est appel� qu'une seule fois lors de l'initialisation de la
* fenetre. N'est plus jamais appel� ensuite...
*/
public void initFirst() {
buttonValidate.addActionListener(this);
}
/**
* Optionnal.<br>
* Cette m�thode permet de changer le libell� des champs par la
* traduction i18n
*/
public void initI18n() {
labelTitle.setText(I18nScreens.getInstance().get(labelTitle.getText()));
buttonValidate.setText(I18nScreens.getInstance().get(buttonValidate.getText()));
}
public void initEach() {
// i18n
// changement des labels dans une m�thode abstract initI18n ?
comboLanguages.removeAllItems();
addLanguages(comboLanguages);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(buttonValidate)) {
String choosenLanguage = ComponentTools.getClefFromCombo(comboLanguages);
DruideGUII18n.getInstance().init(choosenLanguage);
Session.getInstance().setAttribute(SessionConstants.LANGUAGE_USED, choosenLanguage);
SwapFrame.getInstance().init((Class) Session.getInstance().getAttribute(SessionConstants.ECRAN_RESERVE));
} else {
System.out.println("Ce boutton n'existe pas !");
}
}
public int getPanelWidth() {
return 250;
}
public int getPanelHeight() {
return 250;
}
public String getPanelTitle() {
return DruideGUII18n.getInstance().get("screen.languages.title");
}
/**
* Permet d'initialiser la liste des pays. Sans blanc en 1er
* @param combo
*/
private void addLanguages(JComboBox combo) {
List liste = DruideCaveProps.getInstance().getListeSimple(DruideCaveProps.LANGUAGES);
if (liste != null && liste.size() > 0) {
for (int i = 0; i < liste.size(); i++) {
Locale locale = new Locale((String) liste.get(i));
combo.addItem(new KeyValueBean(locale.getLanguage(), locale.getDisplayLanguage(locale)));
}
}
else {
String[] langages = DruideGUII18n.DRUIDEGUI_LOCALES_AVAILABLE;
for (int i = 0; i < langages.length; i++) {
Locale locale = new Locale(langages[i]);
combo.addItem(new KeyValueBean(locale.getLanguage(), locale.getDisplayLanguage(locale)));
}
}
}
}