Package net.sf.cannagrower.gui

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

package net.sf.cannagrower.gui;

import java.awt.BorderLayout;
import java.awt.Toolkit;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import java.awt.Dimension;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.KeyEvent;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JTabbedPane;
import javax.swing.JComboBox;
import javax.swing.LookAndFeel;
import javax.swing.UIManager.LookAndFeelInfo;
import java.util.Vector;
import java.util.Locale;
import javax.swing.BoxLayout;

import net.sf.cannagrower.CannaGrower;
import net.sf.cannagrower.CannaGrowerProperties;
import net.sf.cannagrower.i18n.Messages;

import net.sf.orexio.common.ui.LookAndFeelChooserPanel;
import net.sf.orexio.common.ui.LookAndFeelChooserPanelListener;

public class FrameSettings extends JFrame {

  private static final long serialVersionUID = 1L;
 
  private LookAndFeel      defaultLaf=javax.swing.UIManager.getLookAndFeel();;  //  @jve:decl-index=0:
  private LookAndFeel      choosedLaf=null//  @jve:decl-index=0:
  private Locale        choosedLocale=null;

  private JPanel jContentPane = null;

  private LookAndFeelChooserPanel lafChooserPanel = null;

  private JPanel jPanelLaf = null;

  private JPanel jPanelPreview = null;

  private JDesktopPane jDesktopPanePreview = null;

  private JInternalFrame jInternalFramePreview = null;

  private JMenuBar jJMenuBarPreview = null;

  private JMenu jMenuPreview = null;

  private JMenuItem jMenuItemPreview1 = null;

  private JPanel jPanelWindowPreview = null;

  private JLabel jLabelPreview = null;

  private JButton jButtonPreview = null;

  private JCheckBox jCheckBoxPreview = null;

  private JScrollPane jScrollPanePreview = null;

  private JList jListPreview = null;

  private JTabbedPane jTabbedPane = null;

  private JPanel jPanelPreviewTab1 = null;

  private JLabel jLabelPreviewTab = null;

  private JPanel jPanelLocale = null;

  private JComboBox jComboBoxLocale = null;

  private JPanel jPanelOptions = null;

  private JCheckBox jCheckBoxShowAtStartup = null;

  private JButton jButtonClose = null;

  private JPanel jPanelButtons = null;

  private JPanel jPanelCheckBox = null;

  private JCheckBox jCheckBoxShowDemo = null;

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

  /**
   * This method initializes this
   *
   * @return void
   */
  private void initialize() {
    // Centering on screen
    Dimension screen=this.getToolkit().getScreenSize();
    Double x,y;
    this.setSize(537, 422);
    x=(screen.getWidth()-this.getSize().getWidth())/2;
    y=(screen.getHeight()-this.getSize().getHeight())/2;
    this.setBounds(x.intValue(),y.intValue(),this.getWidth(),this.getHeight());
   
   
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(
        getClass().getResource(
            "/net/sf/cannagrower/images/cannagrower_32.png")));
    this.setContentPane(getJContentPane());
    this.setTitle(CannaGrower.class.getSimpleName()+" "+CannaGrower.getVersionFullName());
    this.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosing(java.awt.event.WindowEvent e) {
        close();
      }
    });
  }

  private void close(){
    LookAndFeelInfo lafInfo;
   
    // Save settings
    if(choosedLocale!=null){
      Locale.setDefault(choosedLocale);
      net.sf.cannagrower.CannaGrowerProperties.getProperties().setLocale(choosedLocale);
      Messages.changeLocale(choosedLocale);
    }
    if(choosedLaf!=null){
      lafInfo=new LookAndFeelInfo(javax.swing.UIManager.getLookAndFeel().getName(),javax.swing.UIManager.getLookAndFeel().getClass().getName());
      net.sf.cannagrower.CannaGrowerProperties.getProperties().setLaf(lafInfo);
    }
    net.sf.cannagrower.CannaGrowerProperties.getProperties().setShowSettings(getJCheckBoxShowAtStartup().isSelected());
    net.sf.cannagrower.CannaGrowerProperties.getProperties().setShowDemo(jCheckBoxShowDemo.isSelected());
    CannaGrower.launch();
  }

  private void update(){
    if(choosedLaf==null && javax.swing.UIManager.getLookAndFeel().getClass().equals(defaultLaf.getClass())){return;}
    choosedLaf=javax.swing.UIManager.getLookAndFeel();
    javax.swing.SwingUtilities.updateComponentTreeUI(this);
  }
 
  private void updateLocale(){
    Language language=(Language)getJComboBoxLocale().getSelectedItem();
    choosedLocale=language.locale;
  }
 
  /**
   * This method initializes jContentPane
   *
   * @return javax.swing.JPanel
   */
  private JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(new BorderLayout());
      jContentPane.add(getJPanelLaf(), BorderLayout.CENTER);
      jContentPane.add(getJPanelLocale(), BorderLayout.NORTH);
      jContentPane.add(getJPanelOptions(), BorderLayout.SOUTH);
    }
    return jContentPane;
  }

  /**
   * This method initializes lafChooserPanel 
   *  
   * @return net.sf.cannagrower.util.LookAndFeelChooserPanel 
   */
  private LookAndFeelChooserPanel getLafChooserPanel() {
    if (lafChooserPanel == null) {
      lafChooserPanel = new LookAndFeelChooserPanel(new LookAndFeelChooserPanelListener(){
        public void lafChanged(){
          SwingUtilities.invokeLater(new Runnable(){     
            public void run(){
              update();
            }
          });
        };
      });
    }
    return lafChooserPanel;
  }

  /**
   * This method initializes jPanelLaf 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelLaf() {
    if (jPanelLaf == null) {
      jPanelLaf = new JPanel();
      jPanelLaf.setLayout(new BorderLayout());
      jPanelLaf.setBorder(BorderFactory.createTitledBorder(null, Messages.getMessage(Messages.settingsLooks), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
      jPanelLaf.add(getLafChooserPanel(), BorderLayout.CENTER);
      jPanelLaf.add(getJPanelPreview(), BorderLayout.EAST);
    }
    return jPanelLaf;
  }

  /**
   * This method initializes jPanelPreview 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelPreview() {
    if (jPanelPreview == null) {
      jPanelPreview = new JPanel();
      jPanelPreview.setLayout(new BorderLayout());
      jPanelPreview.add(getJDesktopPanePreview(), BorderLayout.CENTER);
    }
    return jPanelPreview;
  }

  /**
   * This method initializes jDesktopPanePreview 
   *  
   * @return javax.swing.JDesktopPane 
   */
  private JDesktopPane getJDesktopPanePreview() {
    if (jDesktopPanePreview == null) {
      jDesktopPanePreview = new JDesktopPane();
      jDesktopPanePreview.setPreferredSize(new Dimension(300, 1));
      jDesktopPanePreview.add(getJInternalFramePreview(), null);
    }
    return jDesktopPanePreview;
  }

  /**
   * This method initializes jInternalFramePreview 
   *  
   * @return javax.swing.JInternalFrame 
   */
  private JInternalFrame getJInternalFramePreview() {
    if (jInternalFramePreview == null) {
      jInternalFramePreview = new JInternalFrame();
      jInternalFramePreview.setBounds(new Rectangle(30, 5, 243, 223));
      jInternalFramePreview.setJMenuBar(getJJMenuBarPreview());
      jInternalFramePreview.setContentPane(getJPanelWindowPreview());
      jInternalFramePreview.setVisible(true);
     
    }
    return jInternalFramePreview;
  }

  public void setVisilbe(boolean visible){
    super.setVisible(visible);
  }

  /**
   * This method initializes jJMenuBarPreview 
   *  
   * @return javax.swing.JMenuBar 
   */
  private JMenuBar getJJMenuBarPreview() {
    if (jJMenuBarPreview == null) {
      jJMenuBarPreview = new JMenuBar();
      jJMenuBarPreview.add(getJMenuPreview());
    }
    return jJMenuBarPreview;
  }

  /**
   * This method initializes jMenuPreview 
   *  
   * @return javax.swing.JMenu 
   */
  private JMenu getJMenuPreview() {
    if (jMenuPreview == null) {
      jMenuPreview = new JMenu();
      jMenuPreview.setText("Preview");
      jMenuPreview.add(getJMenuItemPreview1());
    }
    return jMenuPreview;
  }

  /**
   * This method initializes jMenuItemPreview1 
   *  
   * @return javax.swing.JMenuItem 
   */
  private JMenuItem getJMenuItemPreview1() {
    if (jMenuItemPreview1 == null) {
      jMenuItemPreview1 = new JMenuItem();
      jMenuItemPreview1.setText("Preview");
    }
    return jMenuItemPreview1;
  }

  /**
   * This method initializes jPanelWindowPreview 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelWindowPreview() {
    if (jPanelWindowPreview == null) {
      jLabelPreview = new JLabel();
      jLabelPreview.setText("Preview");
      jPanelWindowPreview = new JPanel();
      jPanelWindowPreview.setLayout(new FlowLayout());
      jPanelWindowPreview.add(jLabelPreview, null);
      jPanelWindowPreview.add(getJButtonPreview(), null);
      jPanelWindowPreview.add(getJCheckBoxPreview(), null);
      jPanelWindowPreview.add(getJScrollPanePreview(), null);
      jPanelWindowPreview.add(getJTabbedPane(), null);
    }
    return jPanelWindowPreview;
  }

  /**
   * This method initializes jButtonPreview 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonPreview() {
    if (jButtonPreview == null) {
      jButtonPreview = new JButton();
      jButtonPreview.setMnemonic(KeyEvent.VK_UNDEFINED);
      jButtonPreview.setText("Preview");
    }
    return jButtonPreview;
  }

  /**
   * This method initializes jCheckBoxPreview 
   *  
   * @return javax.swing.JCheckBox 
   */
  private JCheckBox getJCheckBoxPreview() {
    if (jCheckBoxPreview == null) {
      jCheckBoxPreview = new JCheckBox();
      jCheckBoxPreview.setText("Preview");
      jCheckBoxPreview.setSelected(true);
    }
    return jCheckBoxPreview;
  }

  /**
   * This method initializes jScrollPanePreview 
   *  
   * @return javax.swing.JScrollPane 
   */
  private JScrollPane getJScrollPanePreview() {
    if (jScrollPanePreview == null) {
      jScrollPanePreview = new JScrollPane();
      jScrollPanePreview.setViewportView(getJListPreview());
      jScrollPanePreview.setPreferredSize(new Dimension(80, 80));
    }
    return jScrollPanePreview;
  }

  /**
   * This method initializes jListPreview 
   *  
   * @return javax.swing.JList 
   */
  private JList getJListPreview() {
    if (jListPreview == null) {
      java.util.Vector<String> values=new java.util.Vector<String>();
      values.add("Preview1");
      values.add("Preview2");
      values.add("Preview3");
      values.add("Preview4");
      values.add("Preview5");
      jListPreview = new JList(values);
      jListPreview.setPreferredSize(new Dimension(80, 80));
    }
    return jListPreview;
  }

  /**
   * This method initializes jTabbedPane 
   *  
   * @return javax.swing.JTabbedPane 
   */
  private JTabbedPane getJTabbedPane() {
    if (jTabbedPane == null) {
      jTabbedPane = new JTabbedPane();
      jTabbedPane.addTab("Tab1", null, getJPanelPreviewTab1(), null);
      jPanelPreviewTab1=null;
      jTabbedPane.addTab("Tab2", null, getJPanelPreviewTab1(), null);
      jPanelPreviewTab1=null;
      jTabbedPane.addTab("Tab3", null, getJPanelPreviewTab1(), null);
   
    }
    return jTabbedPane;
  }

  /**
   * This method initializes jPanelPreviewTab1 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelPreviewTab1() {
    if (jPanelPreviewTab1 == null) {
      jLabelPreviewTab = new JLabel();
      jLabelPreviewTab.setText("Preview");
      jPanelPreviewTab1 = new JPanel();
      jPanelPreviewTab1.setLayout(new FlowLayout());
      jPanelPreviewTab1.add(jLabelPreviewTab, null);
    }
    return jPanelPreviewTab1;
  }

  /**
   * This method initializes jPanelLocale 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelLocale() {
    if (jPanelLocale == null) {
      jPanelLocale = new JPanel();
      jPanelLocale.setLayout(new BorderLayout());
      jPanelLocale.setBorder(BorderFactory.createTitledBorder(null, Messages.getMessage(Messages.settingsLanguages), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
      jPanelLocale.add(getJComboBoxLocale(), BorderLayout.CENTER);
    }
    return jPanelLocale;
  }

  /**
   * This method initializes jComboBoxLocale 
   *  
   * @return javax.swing.JComboBox 
   */
  private JComboBox getJComboBoxLocale() {
    Language      language;
    Language      languageDefault=null;
    Language      languageEnglish=null;
    Vector<Language>   languages;
    if (jComboBoxLocale == null) {
      languages=new Vector<Language>();
     
      for(Locale locale:Messages.getAvaibleLanguages()){
        language=new Language(locale);
        if(locale.getLanguage().equals(Locale.getDefault().getLanguage())){languageDefault=language;}
        if(locale.equals(Locale.ENGLISH)){languageEnglish=language;}
        languages.add(language);
      }
     
      jComboBoxLocale = new JComboBox(languages);
     
      if(languageDefault==null){
        jComboBoxLocale.getModel().setSelectedItem(languageEnglish);
      }else{
        jComboBoxLocale.getModel().setSelectedItem(languageDefault)
      }
     
      jComboBoxLocale.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent e) {
          updateLocale();
        }
      });
    }
    return jComboBoxLocale;
  }

  /**
   * This method initializes jPanelOptions 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelOptions() {
    if (jPanelOptions == null) {
      jPanelOptions = new JPanel();
      jPanelOptions.setLayout(new BorderLayout());
      jPanelOptions.add(getJPanelButtons(), BorderLayout.CENTER);
      jPanelOptions.add(getJPanelCheckBox(), BorderLayout.NORTH);
    }
    return jPanelOptions;
  }

  /**
   * This method initializes jCheckBoxShowAtStartup 
   *  
   * @return javax.swing.JCheckBox 
   */
  private JCheckBox getJCheckBoxShowAtStartup() {
    if (jCheckBoxShowAtStartup == null) {
      jCheckBoxShowAtStartup = new JCheckBox();
      jCheckBoxShowAtStartup.setText(Messages.getMessage(Messages.settingsShowThis));
      jCheckBoxShowAtStartup.setSelected(true);
    }
    return jCheckBoxShowAtStartup;
  }

  /**
   * This method initializes jButtonClose 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonClose() {
    if (jButtonClose == null) {
      jButtonClose = new JButton();
      jButtonClose.setText(Messages.getMessage(Messages.messageOk));
      jButtonClose.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          close();
          setVisible(false);
        }
      });
    }
    return jButtonClose;
  }

  /**
   * This method initializes jPanelButtons 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelButtons() {
    if (jPanelButtons == null) {
      jPanelButtons = new JPanel();
      jPanelButtons.setLayout(new FlowLayout());
      jPanelButtons.add(getJButtonClose(), null);
    }
    return jPanelButtons;
  }

  /**
   * This method initializes jPanelCheckBox 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelCheckBox() {
    if (jPanelCheckBox == null) {
      jPanelCheckBox = new JPanel();
      jPanelCheckBox.setLayout(new BoxLayout(getJPanelCheckBox(), BoxLayout.Y_AXIS));
      jPanelCheckBox.add(getJCheckBoxShowAtStartup(), null);
      jPanelCheckBox.add(getJCheckBoxShowDemo(), null);
    }
    return jPanelCheckBox;
  }

  /**
   * This method initializes jCheckBoxShowDemo 
   *  
   * @return javax.swing.JCheckBox 
   */
  private JCheckBox getJCheckBoxShowDemo() {
    if (jCheckBoxShowDemo == null) {
      jCheckBoxShowDemo = new JCheckBox();
      jCheckBoxShowDemo.setText(Messages.getMessage(Messages.settingsShowDemo));
      jCheckBoxShowDemo.setSelected(CannaGrowerProperties.getProperties().getShowDemo());
    }
    return jCheckBoxShowDemo;
  }
//  @jve:decl-index=0:visual-constraint="10,10"

class Language{
  java.util.Locale locale;
  Language(java.util.Locale locale){
    this.locale=locale;
  }
  public String toString(){return locale.getDisplayLanguage();}
}
TOP

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

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.