+ *
+ * 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 java.awt.Color;
-import java.awt.Font;
-import javax.swing.JTabbedPane;
-import java.awt.BorderLayout;
-import javax.swing.JPanel;
+import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
-import javax.swing.JMenu;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-import javax.swing.JPopupMenu;
-import java.awt.Component;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.Dimension;
+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
{
- private JFrame frmSimpleBackup;
-
- /**
- * Launch the application.
- */
- public static void main(String[] args)
+ public static void main(final String[] args)
{
EventQueue.invokeLater(new Runnable()
{
+ @Override
public void run()
{
try
@@ -47,12 +64,82 @@ public class SibaGUI
});
}
+ /**
+ * 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();
+
}
/**
@@ -60,51 +147,74 @@ public class SibaGUI
*/
private void initialize()
{
- frmSimpleBackup = new JFrame();
- frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
- frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47));
-
+ 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);
- frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
-
-
+ 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);
- frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
- frmSimpleBackup.setForeground(new Color(0, 100, 0));
- frmSimpleBackup.setBackground(new Color(102, 205, 170));
- frmSimpleBackup.setTitle("Simple Backup");
- frmSimpleBackup.setBounds(100, 100, 450, 300);
- frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
+ 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();
- frmSimpleBackup.setJMenuBar(menuBar);
-
+ this.frmSimpleBackup.setJMenuBar(menuBar);
+
JMenuItem mntmNewMenuItem_1 = new JMenuItem("Sortir");
- mntmNewMenuItem_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- frmSimpleBackup.dispose();
+ 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() {
- public void actionPerformed(ActionEvent e) {
+ 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();
+ }
+
}
diff --git a/src/org/dclermonte/siba/gui/messages.properties b/src/org/dclermonte/siba/gui/messages.properties
index 7c802e1..cb49534 100644
--- a/src/org/dclermonte/siba/gui/messages.properties
+++ b/src/org/dclermonte/siba/gui/messages.properties
@@ -1,13 +1,15 @@
#Field ResourceBundle: BUNDLE
-#Thu Apr 07 21:33:48 CEST 2016
+#Tue Apr 19 12:21:42 CEST 2016
BackupPanel.btnNewButton.text=\u2026
BackupPanel.btnNewButton_1.text=\u2026
BackupPanel.btnNewButton_2.text=Backup
BackupPanel.lblLeRepertoire.text=- le repertoire \u00E0 compresser
-BackupPanel.lblNewLabel.text=Source Directory\:
+BackupPanel.lblSourceDirectory.text=Source Directory\:
BackupPanel.lblNewLabel_1.text=Date Format
-BackupPanel.lblNewLabel_2.text=Choisissez \:
\nblabla
\n
-BackupPanel.lblRpertoireDeDestination.text=Target Directory\:
+BackupPanel.lblNewLabel_2.text=Choisissez :
- 1 : le répertoire que vous souhaitez sauvegarder
- 2 : le répertoire dans lequel vous souhaitez placer la sauvegarde
- 3 : Cliquez sur Backup
+BackupPanel.lblSourceDirectory.text=Source Directory
+BackupPanel.lblTargetDirectory.text=Target Directory
BackupPanel.rdbtnNewRadioButton.text=(iso8601) YYYY-MM-dd
BackupPanel.rdbtnNewRadioButton_1.text=Human
+BackupPanel.sourceFileChooserButton.text=Source Directory
BackupPanel.targetFileChooserButton.text=Target Directory
diff --git a/src/org/dclermonte/siba/gui/messages_fr_FR.properties b/src/org/dclermonte/siba/gui/messages_fr_FR.properties
index 76cfd9f..5aff8d3 100644
--- a/src/org/dclermonte/siba/gui/messages_fr_FR.properties
+++ b/src/org/dclermonte/siba/gui/messages_fr_FR.properties
@@ -1,11 +1,15 @@
#Field ResourceBundle: BUNDLE
-#Thu Apr 07 21:33:48 CEST 2016
+#Tue Apr 19 12:21:42 CEST 2016
BackupPanel.btnNewButton.text=\u2026
-BackupPanel.btnNewButton_1.text=...
+BackupPanel.btnNewButton_1.text=\u2026
BackupPanel.btnNewButton_2.text=Backup
-BackupPanel.lblNewLabel.text=Source Directory\:
+BackupPanel.lblLeRepertoire.text=- le repertoire \u00E0 compresser
+BackupPanel.lblSourceDirectory.text=Répertoire origine
BackupPanel.lblNewLabel_1.text=Date Format
-BackupPanel.lblRpertoireDeDestination.text=Target Directory\:
+BackupPanel.lblNewLabel_2.text=Choisissez :
- 1 : le répertoire que vous souhaitez sauvegarder
- 2 : le répertoire dans lequel vous souhaitez placer la sauvegarde
- 3 : Cliquez sur Backup
+BackupPanel.lblSourceDirectory.text=Répertoire origine
+BackupPanel.lblTargetDirectory.text=Répertoire de destination
BackupPanel.rdbtnNewRadioButton.text=(iso8601) YYYY-MM-dd
BackupPanel.rdbtnNewRadioButton_1.text=Human
-BackupPanel.targetFileChooserButton.text=Target Directory
+BackupPanel.sourceFileChooserButton.text=Répertoire origine
+BackupPanel.targetFileChooserButton.text=Répertoire destination
diff --git a/src/org/dclermonte/siba/model/SibaManager.java b/src/org/dclermonte/siba/model/SibaManager.java
index 9144533..53d21c1 100644
--- a/src/org/dclermonte/siba/model/SibaManager.java
+++ b/src/org/dclermonte/siba/model/SibaManager.java
@@ -1,3 +1,22 @@
+/*
+ * 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.model;
import java.io.File;
@@ -29,16 +48,17 @@ public class SibaManager
public static File backup(final File toto, final String target) throws ArchiveException, IOException
{
+ File result;
pathLength = toto.getParentFile().getAbsolutePath().length();
/* String outputFileNameWithoutExtension = toto.getName()+"-"+ LocalDateTime.now(); */
LocalDateTime date = LocalDateTime.now();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'_'H'H_'m");
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'H'h'm'mn's's'");
String text = date.format(formatter);
String outputFileNameWithoutExtension = toto.getName() + "-" + text;
String outputFileName = outputFileNameWithoutExtension + ".tar";
File output = new File(target + "/" + outputFileName);
- File output1 = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
+ result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
final OutputStream out = new FileOutputStream(target + "/" + outputFileName);
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, out);
@@ -49,16 +69,11 @@ public class SibaManager
byte[] fileTar = new byte[(int) output.length()];
FileInputStream fileReader = new FileInputStream(output);
fileReader.read(fileTar);
- /* byte[] fileTarByte = new byte[fileTar.length];
- for (int i = 0; i < fileTarByte.length; i++)
- {
- fileTarByte[i] = (byte) fileTar[i];
- } */
gzCompress.write(fileTar);
gzCompress.close();
output.delete();
- md5(output1, target + "/" + outputFileNameWithoutExtension + ".md5");
- return output1;
+ md5(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
+ return result;
}
public static void directoryToSave(final File directory, final ArchiveOutputStream outputStream) throws IOException
@@ -131,7 +146,7 @@ public class SibaManager
public static File md5(final File directoryToSave, final String destination) throws IOException
{
- File saved = new File(destination);
+ File result = new File(destination);
try
{
byte[] bytedirectoryToSave = new byte[(int) directoryToSave.length()];
@@ -158,10 +173,12 @@ public class SibaManager
hashString.append(hex.substring(hex.length() - 2));
}
}
- FileWriter fileWriter = new FileWriter(saved);
+ FileWriter fileWriter = new FileWriter(result);
fileWriter.write(hashString.toString());
- fileWriter.append(" " + directoryToSave.getName());
+ String newLine = System.getProperty("line.separator");
+ fileWriter.append(" " + directoryToSave.getName() + newLine);
fileWriter.close();
+ fileInputStream.close();
}
catch (NoSuchAlgorithmException e)
{
@@ -169,6 +186,6 @@ public class SibaManager
e.printStackTrace();
}
- return saved;
+ return result;
}
}