Added FileChooser + externalisation

This commit is contained in:
Didier Clermonté 2016-04-26 23:02:26 +02:00
parent f3fa3a8691
commit e52c320b59
14 changed files with 487 additions and 254 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *
@ -21,6 +21,7 @@ package org.dclermonte.siba.gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
@ -29,9 +30,7 @@ import java.util.ResourceBundle;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -48,10 +47,16 @@ import com.jgoodies.forms.layout.RowSpec;
public class BackupPanel extends JPanel public class BackupPanel extends JPanel
{ {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ /**
*
*/
private static final long serialVersionUID = 4714383090458639282L;
/**
*
*/
static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private JTextField textField; private JTextField textField;
public JTextField textField_1; private JTextField textField_1;
private final ButtonGroup buttonGroup = new ButtonGroup();
/** /**
* Create the panel. * Create the panel.
@ -59,6 +64,7 @@ public class BackupPanel extends JPanel
public BackupPanel() public BackupPanel()
{ {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
JPanel panel_4 = new JPanel(); JPanel panel_4 = new JPanel();
@ -67,9 +73,6 @@ public class BackupPanel extends JPanel
JLabel lblNewLabel_2 = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text")); //$NON-NLS-1$ JLabel lblNewLabel_2 = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text")); //$NON-NLS-1$
panel_4.add(lblNewLabel_2); panel_4.add(lblNewLabel_2);
JLabel lblLeRepertoire = new JLabel(BUNDLE.getString("BackupPanel.lblLeRepertoire.text")); //$NON-NLS-1$
panel_4.add(lblLeRepertoire);
JPanel panel = new JPanel(); JPanel panel = new JPanel();
add(panel); add(panel);
panel.setLayout(new FormLayout( panel.setLayout(new FormLayout(
@ -90,20 +93,18 @@ public class BackupPanel extends JPanel
this.textField.setColumns(10); this.textField.setColumns(10);
JButton btnNewButton = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text")); //$NON-NLS-1$ JButton btnNewButton = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text")); //$NON-NLS-1$
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnNewButton.addActionListener(new ActionListener() btnNewButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
final JFileChooser fc = new JFileChooser(); File file = SourceDirectorySelector.showSelectorDialog(null, null);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (file == null)
int returnVal = fc.showDialog(BackupPanel.this,
BUNDLE.getString("BackupPanel.sourceFileChooserButton.text"));
if (returnVal == JFileChooser.APPROVE_OPTION)
{ {
File file = fc.getSelectedFile(); return;
BackupPanel.this.textField.setText(file.getPath());
} }
BackupPanel.this.textField.setText(file.getPath());
} }
}); });
panel.add(btnNewButton, "6, 2"); panel.add(btnNewButton, "6, 2");
@ -118,20 +119,20 @@ public class BackupPanel extends JPanel
this.textField_1.setColumns(10); this.textField_1.setColumns(10);
JButton btnNewButton_1 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$ JButton btnNewButton_1 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$
btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnNewButton_1.addActionListener(new ActionListener() btnNewButton_1.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
final JFileChooser fc1 = new JFileChooser();
fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File file = TargetDirectorySelector.showSelectorDialog(null, null);
int returnVal = fc1.showDialog(BackupPanel.this, if (file == null)
BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
if (returnVal == JFileChooser.APPROVE_OPTION)
{ {
File file = fc1.getSelectedFile(); return;
BackupPanel.this.textField_1.setText(file.getPath());
} }
BackupPanel.this.textField_1.setText(file.getPath());
} }
}); });
panel.add(btnNewButton_1, "6, 4"); panel.add(btnNewButton_1, "6, 4");
@ -139,6 +140,7 @@ public class BackupPanel extends JPanel
btnNewButton_1.setHorizontalAlignment(SwingConstants.RIGHT); btnNewButton_1.setHorizontalAlignment(SwingConstants.RIGHT);
JPanel panel_2 = new JPanel(); JPanel panel_2 = new JPanel();
add(panel_2, BorderLayout.SOUTH); add(panel_2, BorderLayout.SOUTH);
panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS)); panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS));
@ -153,6 +155,7 @@ public class BackupPanel extends JPanel
panel_1.add(horizontalGlue); panel_1.add(horizontalGlue);
JButton btnNewButton_2 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text")); //$NON-NLS-1$ JButton btnNewButton_2 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text")); //$NON-NLS-1$
btnNewButton_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
panel_1.add(btnNewButton_2); panel_1.add(btnNewButton_2);
Component horizontalGlue_1 = Box.createHorizontalGlue(); Component horizontalGlue_1 = Box.createHorizontalGlue();
@ -169,8 +172,13 @@ public class BackupPanel extends JPanel
{ {
File output1 = SibaManager.backup(new File(BackupPanel.this.textField.getText()), File output1 = SibaManager.backup(new File(BackupPanel.this.textField.getText()),
BackupPanel.this.textField_1.getText()); BackupPanel.this.textField_1.getText());
String message = "Votre répertoire a été sauvegardé \n dans le fichier :\n " + output1.getName(); if (output1 == null)
JOptionPane.showMessageDialog(null, message, "Sauvegarde faite", JOptionPane.INFORMATION_MESSAGE); {
return;
}
String message = BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + output1.getName();
String titre = BUNDLE.getString("BackupPanel.confirmDialogTitle.text");
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
} }
catch (ArchiveException | IOException e1) catch (ArchiveException | IOException e1)
{ {

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.dclermonte.siba.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class CheckDialog extends JDialog
{
/**
*
*/
private static final long serialVersionUID = 5266741894791360568L;
public static Object lblNewLabel;
public static String message;
/**
* Launch the application.
*/
public static void main(final String string)
{
message = string;
try
{
CheckDialog dialog = new CheckDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private final JPanel contentPanel = new JPanel();
/**
* Create the dialog.
*/
public CheckDialog()
{
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
this.contentPanel.setLayout(new FlowLayout());
this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(this.contentPanel, BorderLayout.CENTER);
{
JLabel lblNewLabel = new JLabel(message);
this.contentPanel.add(lblNewLabel);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
{
setVisible(false);
dispose();
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
}
}
}

View File

@ -0,0 +1,138 @@
package org.dclermonte.siba.gui;
import java.awt.Color;
import java.awt.Component;
import java.io.File;
import java.util.ResourceBundle;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.apache.commons.lang3.StringUtils;
public class CheckDirectorySelector extends JFileChooser
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L;
/**
* This method is the main one of the selector.
*
* @param parent
* @return
*/
public static File showSelectorDialog(final Component parent, final File targetFile)
{
File result;
//
CheckDirectorySelector selector = new CheckDirectorySelector(targetFile);
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
result = selector.getSelectedFile();
}
else
{
//
result = null;
}
//
return result;
}
/**
*
*/
public CheckDirectorySelector(final File targetFile)
{
super();
setBackground(new Color(152, 251, 152));
//
File file;
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{
file = null;
}
else if (targetFile.isFile())
{
file = targetFile.getParentFile();
}
else
{
file = targetFile;
}
//
setSelectedFile(file);
setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5");
setAcceptAllFileFilterUsed(false);
addChoosableFileFilter(filter);
setApproveButtonText(BackupPanel.BUNDLE.getString("BackupPanel.checkFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG);
}
/**
*
*/
@Override
public void approveSelection()
{
//
// File targetFile = getSelectedFile();
super.approveSelection();
}
/**
*
*/
@Override
public void cancelSelection()
{
//
super.cancelSelection();
}
/**
*
*/
@Override
public void setSelectedFile(final File file)
{
//
super.setSelectedFile(file);
System.out.println("==== SET SELECTED FILE=================");
System.out.println("SELECED FILE " + file);
}
/**
*
*/
@Override
public void setVisible(final boolean visible)
{
//
super.setVisible(visible);
if (!visible)
{
//
resetChoosableFileFilters();
}
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *
@ -19,6 +19,7 @@
*/ */
package org.dclermonte.siba.gui; package org.dclermonte.siba.gui;
import java.awt.Cursor;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
@ -27,20 +28,19 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ResourceBundle;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.jgoodies.forms.layout.ColumnSpec; import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout; import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.FormSpecs; import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.Sizes; import com.jgoodies.forms.layout.Sizes;
import java.util.ResourceBundle;
/** /**
* *
@ -76,6 +76,7 @@ public class CheckPanel extends JPanel
add(lblNewLabel, "2, 2, left, center"); add(lblNewLabel, "2, 2, left, center");
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$ JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnNewButton.addActionListener(new ActionListener() btnNewButton.addActionListener(new ActionListener()
{ {
@Override @Override
@ -104,6 +105,7 @@ public class CheckPanel extends JPanel
add(btnNewButton, "4, 2, left, top"); add(btnNewButton, "4, 2, left, top");
JButton btnNewButton_1 = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$ JButton btnNewButton_1 = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$
btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnNewButton_1.addActionListener(new ActionListener() btnNewButton_1.addActionListener(new ActionListener()
{ {
@Override @Override
@ -176,15 +178,20 @@ public class CheckPanel extends JPanel
hashString.append(hex.substring(hex.length() - 2)); hashString.append(hex.substring(hex.length() - 2));
} }
} }
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
String yourFile = BUNDLE.getString("CheckPanel.confirmDialogYourString.text");
if (md5String.equals(hashString.toString())) if (md5String.equals(hashString.toString()))
{ {
CheckDialog.main("Vérification OK"); String message = yourFile + fileToCheck1.getName() + " "
+ BUNDLE.getString("CheckPanel.confirmDialogGood.text");
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
} }
else else
{ {
CheckDialog.main("Il y a une erreur"); String message = yourFile + fileToCheck1.getName() + " "
+ BUNDLE.getString("CheckPanel.confirmDialogBad.text");
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
} }
} }
@ -195,19 +202,14 @@ public class CheckPanel extends JPanel
*/ */
final void choosenDirectory() throws IOException, NoSuchAlgorithmException final void choosenDirectory() throws IOException, NoSuchAlgorithmException
{ {
final JFileChooser fc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5");
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(filter);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = fc.showDialog(CheckPanel.this, "Sauvegarde à vérifier"); this.choosenFile = CheckDirectorySelector.showSelectorDialog(null, null);
if (this.choosenFile == null)
if (returnVal == JFileChooser.APPROVE_OPTION)
{ {
this.choosenFile = fc.getSelectedFile(); return;
this.textField.setText(this.choosenFile.getName());
} }
this.textField.setText(this.choosenFile.getName());
// }
} }
} }

View File

@ -22,9 +22,11 @@ package org.dclermonte.siba.gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Font; import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Locale; import java.util.Locale;
@ -37,13 +39,36 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dclermonte.siba.gui.utils.GUIToolBox; import org.dclermonte.siba.gui.utils.GUIToolBox;
public class SibaGUI public class SibaGUI
{ {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
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. * Launch the application.
@ -54,8 +79,14 @@ public class SibaGUI
/** /**
* Create the application. * Create the application.
*
* @throws UnsupportedLookAndFeelException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ClassNotFoundException
*/ */
public SibaGUI() public SibaGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{ {
// Set default GUI catch. // Set default GUI catch.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
@ -69,9 +100,7 @@ public class SibaGUI
String message; String message;
if (exception instanceof OutOfMemoryError) if (exception instanceof OutOfMemoryError)
{ {
message = "Java ran out of memory!\n\n To fix this problem, run GeneaQuilts from the command " message = "Java ran out of memory!\n\n";
+ "line:\njava -jar -Xms256m geneaquilt-x.x.x.jar\n\nIf you still "
+ "get the same error, increase the value 256 above.";
} }
else else
{ {
@ -116,6 +145,7 @@ public class SibaGUI
System.out.println("Failed to set the system LookAndFeel."); System.out.println("Failed to set the system LookAndFeel.");
} }
} }
/* UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel"); */
System.out.println("Activated lookAndFeel: " + UIManager.getLookAndFeel().getName()); System.out.println("Activated lookAndFeel: " + UIManager.getLookAndFeel().getName());
// Set default locale. // Set default locale.
@ -132,19 +162,24 @@ public class SibaGUI
private void initialize() private void initialize()
{ {
this.frmSimpleBackup = new JFrame(); this.frmSimpleBackup = new JFrame();
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400)); this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47)); this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47));
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER); this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JPanel panel = new BackupPanel(); JPanel panel = new BackupPanel();
panel.setBackground(new Color(152, 251, 152)); panel.setBackground(new Color(0, 255, 0));
tabbedPane.addTab("BackUp", null, panel, null); String backup = BackupPanel.BUNDLE.getString("BackupPanel.TitleBackupPanel.text");
tabbedPane.addTab(backup, null, panel, null);
JPanel panel_1 = new CheckPanel(); JPanel panel_1 = new CheckPanel();
panel_1.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
panel_1.setBackground(new Color(144, 238, 144)); panel_1.setBackground(new Color(144, 238, 144));
tabbedPane.addTab("Check", null, panel_1, null); String check = BackupPanel.BUNDLE.getString("BackupPanel.TitleCheckPanel.text");
tabbedPane.addTab(check, null, panel_1, null);
this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12)); this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
this.frmSimpleBackup.setForeground(new Color(0, 100, 0)); this.frmSimpleBackup.setForeground(new Color(0, 100, 0));
this.frmSimpleBackup.setBackground(new Color(102, 205, 170)); this.frmSimpleBackup.setBackground(new Color(102, 205, 170));
@ -153,9 +188,14 @@ public class SibaGUI
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar(); JMenuBar menuBar = new JMenuBar();
menuBar.setBackground(new Color(152, 251, 152));
this.frmSimpleBackup.setJMenuBar(menuBar); this.frmSimpleBackup.setJMenuBar(menuBar);
JMenuItem mntmNewMenuItem_1 = new JMenuItem("Sortir"); JMenuItem mntmNewMenuItem_1 = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_1.text")); //$NON-NLS-1$
mntmNewMenuItem_1.setMaximumSize(new Dimension(100, 32767));
mntmNewMenuItem_1.setHorizontalTextPosition(SwingConstants.LEFT);
mntmNewMenuItem_1.setHorizontalAlignment(SwingConstants.LEFT);
mntmNewMenuItem_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmNewMenuItem_1.addActionListener(new ActionListener() mntmNewMenuItem_1.addActionListener(new ActionListener()
{ {
@Override @Override
@ -166,12 +206,18 @@ public class SibaGUI
}); });
menuBar.add(mntmNewMenuItem_1); menuBar.add(mntmNewMenuItem_1);
JMenu mnNewMenu = new JMenu("Help"); JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$
mnNewMenu.setLocation(new Point(500, 0));
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mnNewMenu.setForeground(new Color(0, 0, 0));
mnNewMenu.setBackground(new Color(127, 255, 212)); mnNewMenu.setBackground(new Color(127, 255, 212));
mnNewMenu.setOpaque(true); mnNewMenu.setOpaque(true);
menuBar.add(mnNewMenu); menuBar.add(mnNewMenu);
JMenuItem mntmNewMenuItem_2 = new JMenuItem("About"); JMenuItem mntmNewMenuItem_2 = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
mntmNewMenuItem_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmNewMenuItem_2.addActionListener(new ActionListener() mntmNewMenuItem_2.addActionListener(new ActionListener()
{ {
@Override @Override
@ -201,24 +247,4 @@ public class SibaGUI
ResourceBundle.clearCache(); ResourceBundle.clearCache();
} }
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();
}
}
});
}
} }

View File

@ -1,11 +1,13 @@
package org.dclermonte.siba.gui; package org.dclermonte.siba.gui;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.io.File; import java.io.File;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.ResourceBundle;
/** /**
* *
@ -13,14 +15,46 @@ import org.apache.commons.lang3.StringUtils;
*/ */
public class SourceDirectorySelector extends JFileChooser public class SourceDirectorySelector extends JFileChooser
{ {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L; private static final long serialVersionUID = 3782597353602048214L;
/**
* This method is the main one of the selector.
*
* @param parent
* @return
*/
public static File showSelectorDialog(final Component parent, final File targetFile)
{
File result;
//
SourceDirectorySelector selector = new SourceDirectorySelector(targetFile);
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
result = selector.getSelectedFile();
}
else
{
//
result = null;
}
//
return result;
}
/** /**
* *
*/ */
public SourceDirectorySelector(final File targetFile) public SourceDirectorySelector(final File targetFile)
{ {
super(); super();
setBackground(new Color(152, 251, 152));
// //
File file; File file;
@ -40,10 +74,10 @@ public class SourceDirectorySelector extends JFileChooser
// //
setSelectedFile(file); setSelectedFile(file);
setDialogTitle("Database directory"); setDialogTitle(BUNDLE.getString("SourceDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
setAcceptAllFileFilterUsed(false); setAcceptAllFileFilterUsed(false);
setApproveButtonText("Select"); setApproveButtonText(BackupPanel.BUNDLE.getString("BackupPanel.sourceFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG); setDialogType(CUSTOM_DIALOG);
} }
@ -97,34 +131,4 @@ public class SourceDirectorySelector extends JFileChooser
resetChoosableFileFilters(); resetChoosableFileFilters();
} }
} }
/**
* This method is the main one of the selector.
*
* @param parent
* @return
*/
public static File showSelectorDialog(final Component parent, final File targetFile)
{
File result;
//
SourceDirectorySelector selector = new SourceDirectorySelector(targetFile);
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
result = selector.getSelectedFile();
}
else
{
//
result = null;
}
//
return result;
}
} }

View File

@ -0,0 +1,134 @@
package org.dclermonte.siba.gui;
import java.awt.Color;
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
import org.apache.commons.lang3.StringUtils;
import java.util.ResourceBundle;
/**
*
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/
public class TargetDirectorySelector extends JFileChooser
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static final long serialVersionUID = 3782597353602048214L;
/**
* This method is the main one of the selector.
*
* @param parent
* @return
*/
public static File showSelectorDialog(final Component parent, final File targetFile)
{
File result;
//
TargetDirectorySelector selector = new TargetDirectorySelector(targetFile);
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
result = selector.getSelectedFile();
}
else
{
//
result = null;
}
//
return result;
}
/**
*
*/
public TargetDirectorySelector(final File targetFile)
{
super();
setBackground(new Color(152, 251, 152));
//
File file;
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{
file = null;
}
else if (targetFile.isFile())
{
file = targetFile.getParentFile();
}
else
{
file = targetFile;
}
//
setSelectedFile(file);
setDialogTitle(BUNDLE.getString("TargetDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
setAcceptAllFileFilterUsed(false);
setApproveButtonText(BackupPanel.BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG);
}
/**
*
*/
@Override
public void approveSelection()
{
//
// File targetFile = getSelectedFile();
super.approveSelection();
}
/**
*
*/
@Override
public void cancelSelection()
{
//
super.cancelSelection();
}
/**
*
*/
@Override
public void setSelectedFile(final File file)
{
//
super.setSelectedFile(file);
System.out.println("==== SET SELECTED FILE=================");
System.out.println("SELECED FILE " + file);
}
/**
*
*/
@Override
public void setVisible(final boolean visible)
{
//
super.setVisible(visible);
if (!visible)
{
//
resetChoosableFileFilters();
}
}
}

View File

@ -1,17 +1,28 @@
#Field ResourceBundle: BUNDLE #Field ResourceBundle: BUNDLE
#Thu Apr 21 22:53:27 CEST 2016 #Tue Apr 26 16:39:35 CEST 2016
BackupPanel.TitleBackupPanel.text=Backup
BackupPanel.TitleCheckPanel.text=Check
BackupPanel.btnNewButton.text=\u2026 BackupPanel.btnNewButton.text=\u2026
BackupPanel.btnNewButton_1.text=\u2026 BackupPanel.btnNewButton_1.text=\u2026
BackupPanel.btnNewButton_2.text=Backup BackupPanel.btnNewButton_2.text=Backup
BackupPanel.lblLeRepertoire.text=- le repertoire \u00E0 compresser BackupPanel.lblNewLabel_2.text=<html><p style\="margin-bottom\: 0cm; line-height\: 100%">Choose&nbsp;\:</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 1&nbsp;\: The directory to backup</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 2&nbsp;\: The directory where you want to put the backup</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 3&nbsp;\: Click Backup</p></html>
BackupPanel.lblNewLabel_1.text=Date Format BackupPanel.lblSourceDirectory.text=Source Directory :
BackupPanel.lblNewLabel_2.text=<html><p style\="margin-bottom\: 0cm; line-height\: 100%">Choisissez&nbsp;\:</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 1&nbsp;\: le r\u00E9pertoire que vous souhaitez sauvegarder</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 2&nbsp;\: le r\u00E9pertoire dans lequel vous souhaitez placer la sauvegarde</p><p style\="margin-bottom\: 0cm; line-height\: 100%">- 3&nbsp;\: Cliquez sur Backup</p></html> BackupPanel.lblTargetDirectory.text=Target Directory :
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.sourceFileChooserButton.text=Source Directory
BackupPanel.targetFileChooserButton.text=Target Directory BackupPanel.targetFileChooserButton.text=Target Directory
CheckPanel.btnNewButton.text=... CheckDirectorySelector.this.dialogTitle=Directory where is the backup
CheckPanel.btnNewButton.text=\u2026
CheckPanel.btnNewButton_1.text=Check CheckPanel.btnNewButton_1.text=Check
CheckPanel.lblNewLabel.text=Sauvegarde \u00E0 v\u00E9rifier CheckPanel.lblNewLabel.text=File to be Checked
SibaGUI.mnNewMenu.text=Help
SibaGUI.mntmNewMenuItem_1.text=End
SibaGUI.mntmNewMenuItem_2.text=About
SourceDirectorySelector.this.dialogTitle=Directory to backup
TargetDirectorySelector.this.dialogTitle=Directory for the backup
BackupPanel.checkFileChooserButton.text= File to check
BackupPanel.confirmDialogTitle.text = Backup done
BackupPanel.confirmDialogMessage.text = Your directory has been backup \n in the file :\n
CheckPanel.confirmDialogTitle.text = Check done
CheckPanel.confirmDialogYourString.text = Your File
CheckPanel.confirmDialogGood.text = has been check and is good
CheckPanel.confirmDialogBad.text = is corrupted

View File

@ -2,17 +2,27 @@
#Tue Apr 19 12:21:42 CEST 2016 #Tue Apr 19 12:21:42 CEST 2016
BackupPanel.btnNewButton.text=\u2026 BackupPanel.btnNewButton.text=\u2026
BackupPanel.btnNewButton_1.text=\u2026 BackupPanel.btnNewButton_1.text=\u2026
BackupPanel.btnNewButton_2.text=Backup BackupPanel.btnNewButton_2.text=Sauvegarde
BackupPanel.lblLeRepertoire.text=- le repertoire \u00E0 compresser BackupPanel.lblNewLabel_2.text=<html><p style="margin-bottom: 0cm; line-height: 100%">Choisissez&nbsp;:</p><p style="margin-bottom: 0cm; line-height: 100%">- 1&nbsp;: le répertoire que vous souhaitez sauvegarder</p><p style="margin-bottom: 0cm; line-height: 100%">- 2&nbsp;: le répertoire dans lequel vous souhaitez placer la sauvegarde</p><p style="margin-bottom: 0cm; line-height: 100%">- 3&nbsp;: Cliquez sur Sauvegarde</p></html>
BackupPanel.lblSourceDirectory.text=Répertoire origine BackupPanel.lblSourceDirectory.text=Répertoire \u00E0 sauvegarder :
BackupPanel.lblNewLabel_1.text=Date Format BackupPanel.lblTargetDirectory.text=Répertoire de destination :
BackupPanel.lblNewLabel_2.text=<html><p style="margin-bottom: 0cm; line-height: 100%">Choisissez&nbsp;:</p><p style="margin-bottom: 0cm; line-height: 100%">- 1&nbsp;: le répertoire que vous souhaitez sauvegarder</p><p style="margin-bottom: 0cm; line-height: 100%">- 2&nbsp;: le répertoire dans lequel vous souhaitez placer la sauvegarde</p><p style="margin-bottom: 0cm; line-height: 100%">- 3&nbsp;: Cliquez sur Backup</p></html> BackupPanel.sourceFileChooserButton.text= Répertoire à sauvegarder
BackupPanel.lblSourceDirectory.text=Répertoire origine BackupPanel.targetFileChooserButton.text=Répertoire destination
BackupPanel.lblTargetDirectory.text=Répertoire de destination BackupPanel.TitleCheckPanel.text = Vérification
BackupPanel.rdbtnNewRadioButton.text=(iso8601) YYYY-MM-dd BackupPanel.TitleBackupPanel.text = Sauvegarde
BackupPanel.rdbtnNewRadioButton_1.text=Human CheckDirectorySelector.this.dialogTitle=Emplacement de la sauvegarde
BackupPanel.sourceFileChooserButton.text=Source Directory CheckPanel.btnNewButton.text=\u2026
BackupPanel.targetFileChooserButton.text=Target Directory
CheckPanel.btnNewButton.text=...
CheckPanel.btnNewButton_1.text=Vérifier CheckPanel.btnNewButton_1.text=Vérifier
CheckPanel.lblNewLabel.text=Sauvegarde \u00E0 v\u00E9rifier CheckPanel.lblNewLabel.text=Sauvegarde \u00E0 v\u00E9rifier
SibaGUI.mnNewMenu.text=Aide
SibaGUI.mntmNewMenuItem_1.text=Sortir
SibaGUI.mntmNewMenuItem_2.text=A propos
SourceDirectorySelector.this.dialogTitle=Choix du répertoire à sauvegarder
TargetDirectorySelector.this.dialogTitle=Choix du répertoire de destination
BackupPanel.checkFileChooserButton.text= Fichier à vérifier
BackupPanel.confirmDialogTitle.text = Sauvegarde faite
BackupPanel.confirmDialogMessage.text = Votre répertoire a été sauvegardé \n dans le fichier :\n
CheckPanel.confirmDialogTitle.text = Vérification faite
CheckPanel.confirmDialogYourString.text = Votre fichier
CheckPanel.confirmDialogGood.text = a été vérifié et ne comporte pas d'erreurs
CheckPanel.confirmDialogBad.text = comporte des erreurs

View File

@ -1 +0,0 @@

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr> * Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
* Didier Clermonté <dclermonte@april.org>
* *
* This file is part of Siba. * This file is part of Siba.
* *
@ -19,6 +19,7 @@
*/ */
package org.dclermonte.siba.model; package org.dclermonte.siba.model;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -35,10 +36,10 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.IOUtils;
@ -46,40 +47,37 @@ public class SibaManager
{ {
public static int pathLength; public static int pathLength;
public static File backup(final File toto, final String target) throws ArchiveException, IOException public static File backup(final File fileToSave, final String target) throws ArchiveException, IOException
{ {
File result; File result;
pathLength = toto.getParentFile().getAbsolutePath().length(); if ((fileToSave == null) || (new File(target) == null))
{
return null;
}
pathLength = fileToSave.getParentFile().getAbsolutePath().length();
/* String outputFileNameWithoutExtension = toto.getName()+"-"+ LocalDateTime.now(); */
LocalDateTime date = LocalDateTime.now(); LocalDateTime date = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'H'h'm'mn's's'"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'H'h'm'mn's's'");
String text = date.format(formatter); String text = date.format(formatter);
String outputFileNameWithoutExtension = toto.getName() + "-" + text; String outputFileNameWithoutExtension = fileToSave.getName() + "-" + text;
String outputFileName = outputFileNameWithoutExtension + ".tar";
File output = new File(target + "/" + outputFileName);
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz"); result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
final OutputStream out = new FileOutputStream(target + "/" + outputFileName); OutputStream gzipOutputStream = new GzipCompressorOutputStream(
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, out); new BufferedOutputStream(new FileOutputStream(result)));
directoryToSave(toto, os); TarArchiveOutputStream out = new TarArchiveOutputStream(gzipOutputStream);
os.close(); directoryToSave(fileToSave, out);
final OutputStream out1 = new FileOutputStream(target + "/" + outputFileNameWithoutExtension + ".tgz"); out.close();
final GzipCompressorOutputStream gzCompress = new GzipCompressorOutputStream(out1);
byte[] fileTar = new byte[(int) output.length()];
FileInputStream fileReader = new FileInputStream(output);
fileReader.read(fileTar);
gzCompress.write(fileTar);
gzCompress.close();
output.delete();
md5(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5"); md5(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
// //
return result; return result;
} }
public static void directoryToSave(final File directory, final ArchiveOutputStream outputStream) throws IOException public static void directoryToSave(final File directory, final TarArchiveOutputStream outputStream)
throws IOException
{ {
for (File file : directory.listFiles()) for (File file : directory.listFiles())
{ {
@ -90,13 +88,13 @@ public class SibaManager
} }
else else
{ {
TarArchiveEntry tae = new TarArchiveEntry(file); TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength); String pathPartiel = file.getPath().substring(pathLength);
tae.setName(pathPartiel); tarArchiveEntry.setName(pathPartiel);
/* outputStream.putArchiveEntry(new TarArchiveEntry(file)); */ outputStream.putArchiveEntry(tarArchiveEntry);
outputStream.putArchiveEntry(tae);
IOUtils.copy(new FileInputStream(file), outputStream); IOUtils.copy(new FileInputStream(file), outputStream);
outputStream.closeArchiveEntry(); outputStream.closeArchiveEntry();
} }
} }
@ -193,4 +191,6 @@ public class SibaManager
return result; return result;
} }
public GzipCompressorOutputStream gzCompress;
} }