Added SibaGUI.

This commit is contained in:
Didier Clermonté 2016-03-27 22:32:35 +02:00
parent 50f6ae3407
commit 0d192d9abf
11 changed files with 186 additions and 15 deletions

View File

@ -2,5 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-oracle"/>
<classpathentry kind="lib" path="jgoodies-forms-1.8.0.jar" sourcepath="jgoodies-forms-1.8.0-sources.jar"/>
<classpathentry kind="lib" path="/home/papou/workspace/Siba/commons-compress-1.10.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

BIN
Siba.jar Normal file

Binary file not shown.

BIN
commons-compress-1.10.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
jgoodies-forms-1.8.0.jar Normal file

Binary file not shown.

View File

@ -1,12 +0,0 @@
package SibaLauncher;
public class SibaLauncher
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
}
}

17
src/siba/Siba.java Normal file
View File

@ -0,0 +1,17 @@
package siba;
import siba.gui.SibaGUI;
public class Siba
{
public static void main(String[] args)
{
if (args.length==0) {
SibaGUI.main(args);;
}
}
}

View File

@ -1,6 +1,17 @@
package siba.gui;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.filechooser.*;
import javax.swing.plaf.basic.BasicFileChooserUI;
public class BackupPanel extends JPanel
{
@ -10,6 +21,42 @@ public class BackupPanel extends JPanel
*/
public BackupPanel()
{
JButton btnNewButton = new JButton("Choix du répertoire");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showDialog(BackupPanel.this,"Répertoire à sauvegarder");
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fc.getSelectedFile();
System.out.println("Répertoire chosi " + file.getPath());
}
}
});
JLabel lblNewLabel = new JLabel("Répertoire à sauvegarder");
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel.setVerticalAlignment(SwingConstants.TOP);
add(lblNewLabel);
add(btnNewButton);
JButton btnNewButton_1 = new JButton("Répertoire de destination");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e1) {
final JFileChooser fc1 = new JFileChooser();
fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc1.showDialog(BackupPanel.this,"Répertoire de destination");
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fc1.getSelectedFile();
System.out.println("Répertoire chosi " + file.getPath());
}
}
});
btnNewButton_1.setHorizontalAlignment(SwingConstants.LEADING);
add(btnNewButton_1);
}

View File

@ -1,6 +1,13 @@
package siba.gui;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
public class CheckPanel extends JPanel
{
@ -10,6 +17,24 @@ public class CheckPanel extends JPanel
*/
public CheckPanel()
{
JLabel lblNewLabel = new JLabel("Sauvegarde à vérifier");
add(lblNewLabel);
JButton btnNewButton = new JButton("Choix de la sauvegarde");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showDialog(CheckPanel.this,"Sauvegarde à vérifier");
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fc.getSelectedFile();
System.out.println("Répertoire chosi " + file.getPath());
}
}
});
add(btnNewButton);
}

View File

@ -56,11 +56,11 @@ public class SibaGUI
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
JPanel panel = new BackupPanel();
panel.setBackground(new Color(152, 251, 152));
tabbedPane.addTab("BackUp", null, panel, null);
JPanel panel_1 = new JPanel();
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));

View File

@ -1,6 +1,98 @@
package siba.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
public class SibaModel
{
public static File backup(File repertoireAsauvegarder){
File sauvegarde = new File("");
return sauvegarde;
}
public static File md5(File repertoireAsauvegarder) throws IOException{
File sauvegarde = new File(repertoireAsauvegarder.getName()+"md5");
try
{ byte[] byterepertoireAsauvegarder = repertoireAsauvegarder.toString().getBytes() ;
byte[] hash = null;
MessageDigest md = MessageDigest.getInstance("MD5");
hash = md.digest(byterepertoireAsauvegarder);
StringBuilder hashString = new StringBuilder();
for (int i = 0; i < hash.length; i++)
{
String hex = Integer.toHexString(hash[i]);
if (hex.length() == 1)
{
hashString.append('0');
hashString.append(hex.charAt(hex.length() - 1));
}
else
hashString.append(hex.substring(hex.length() - 2));
}
FileWriter ffw = new FileWriter(sauvegarde);
ffw.write(hashString.toString());
ffw.close();
}
catch (NoSuchAlgorithmException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return sauvegarde;
}
public static void extract(File repertoireAdecompresser, File destination) throws IOException, ArchiveException{
File file = destination;
final List<File> untaredFiles = new LinkedList<File>();
InputStream is;
try
{
is = new FileInputStream(repertoireAdecompresser);
final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
final File outputFile = new File(file, entry.getName());
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
} else {
final OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(debInputStream, outputFileStream);
outputFileStream.close();
}
untaredFiles.add(outputFile);
}
debInputStream.close(); }
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}