/* * Copyright (C) 2016 Christian Pierre Momon * Didier Clermonté * * This file is part of Siba. * * Siba is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package org.dclermonte.siba.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Locale; import java.util.ResourceBundle; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.UIManager; import org.apache.commons.lang3.StringUtils; public class SibaGUI { public static void main(final String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { SibaGUI window = new SibaGUI(); window.frmSimpleBackup.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Launch the application. */ Locale locale; private JFrame frmSimpleBackup; /** * Create the application. */ public SibaGUI() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { /** * */ @Override public void uncaughtException(final Thread thread, final Throwable exception) { String message; if (exception instanceof OutOfMemoryError) { message = "Java ran out of memory!\n\nTo fix this problem, run GeneaQuilts from the command " + "line:\njava -jar -Xms256m geneaquilt-x.x.x.jar\n\nIf you still " + "get the same error, increase thevalue 256 above."; } else { message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")"; } JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); exception.printStackTrace(); } }); // Remove BOLD on default font. UIManager.put("swing.boldMetal", Boolean.TRUE); // Set LookAndFeel. System.out.println("System lookAndFeel property:" + System.getProperty("swing.defaultlaf")); System.out.println("Available lookAndFeel: " + UIManager.getInstalledLookAndFeels().toString()); System.out.println("System lookAndFeel: " + UIManager.getSystemLookAndFeelClassName()); System.out.println("Current lookAndFeel: " + UIManager.getLookAndFeel().getName()); if (!StringUtils.equals(UIManager.getSystemLookAndFeelClassName(), "javax.swing.plaf.metal.MetalLookAndFeel")) { try { System.out.println("Metal LAF setted and system LAF detected, try to set system LAF."); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (final Exception exception) { System.out.println("Failed to set the system LookAndFeel."); } } else if (UIManager.getInstalledLookAndFeels().toString().contains("GTK+")) { try { System.out.println("Metal LAF setted and GTK+ LAF detected, try to set GTK+ LAF."); UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } catch (final Exception exception) { System.out.println("Failed to set the system LookAndFeel."); } } System.out.println("Activated lookAndFeel: " + UIManager.getLookAndFeel().getName()); this.locale = Locale.getDefault(); updateLanguage(this.locale); System.out.println(this.locale.getDisplayLanguage()); initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { this.frmSimpleBackup = new JFrame(); this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400)); this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47)); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER); JPanel panel = new BackupPanel(); panel.setBackground(new Color(152, 251, 152)); tabbedPane.addTab("BackUp", null, panel, null); JPanel panel_1 = new CheckPanel(); panel_1.setBackground(new Color(144, 238, 144)); tabbedPane.addTab("Check", null, panel_1, null); this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12)); this.frmSimpleBackup.setForeground(new Color(0, 100, 0)); this.frmSimpleBackup.setBackground(new Color(102, 205, 170)); this.frmSimpleBackup.setTitle("Simple Backup"); this.frmSimpleBackup.setBounds(100, 100, 450, 300); this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); this.frmSimpleBackup.setJMenuBar(menuBar); JMenuItem mntmNewMenuItem_1 = new JMenuItem("Sortir"); mntmNewMenuItem_1.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { SibaGUI.this.frmSimpleBackup.dispose(); } }); menuBar.add(mntmNewMenuItem_1); JMenu mnNewMenu = new JMenu("Help"); mnNewMenu.setBackground(new Color(127, 255, 212)); mnNewMenu.setOpaque(true); menuBar.add(mnNewMenu); JMenuItem mntmNewMenuItem_2 = new JMenuItem("About"); mntmNewMenuItem_2.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { AboutDialog.main(""); } }); mnNewMenu.add(mntmNewMenuItem_2); } /** * */ public void updateLanguage(final Locale source) { // Change JVM default locale. java.util.Locale.setDefault(source); // Change LookAndFeel default locale. javax.swing.UIManager.getDefaults().setDefaultLocale(source); // Change new component default locale. javax.swing.JComponent.setDefaultLocale(source); // ResourceBundle.clearCache(); } }