2016-03-29 23:25:18 +02:00
|
|
|
package org.dclermonte.siba.gui;
|
|
|
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JFileChooser;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
import javax.swing.SwingConstants;
|
|
|
|
|
|
|
|
import com.jgoodies.forms.layout.ColumnSpec;
|
|
|
|
import com.jgoodies.forms.layout.FormLayout;
|
|
|
|
import com.jgoodies.forms.layout.FormSpecs;
|
|
|
|
import com.jgoodies.forms.layout.RowSpec;
|
|
|
|
import com.jgoodies.forms.layout.Sizes;
|
|
|
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
|
import org.dclermonte.siba.model.*;
|
|
|
|
|
|
|
|
public class BackupPanel extends JPanel
|
|
|
|
{
|
|
|
|
private JTextField textField;
|
2016-04-01 00:08:32 +02:00
|
|
|
public JTextField textField_1;
|
2016-03-29 23:25:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the panel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public BackupPanel()
|
|
|
|
{
|
|
|
|
|
|
|
|
JButton btnNewButton = new JButton("...");
|
|
|
|
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();
|
|
|
|
textField.setText(file.getPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setLayout(new FormLayout(new ColumnSpec[] {
|
|
|
|
ColumnSpec.decode("center:2dlu"),
|
2016-04-01 00:08:32 +02:00
|
|
|
FormSpecs.DEFAULT_COLSPEC,
|
|
|
|
FormSpecs.RELATED_GAP_COLSPEC,
|
|
|
|
ColumnSpec.decode("default:grow"),
|
|
|
|
FormSpecs.RELATED_GAP_COLSPEC,
|
|
|
|
FormSpecs.DEFAULT_COLSPEC,},
|
2016-03-29 23:25:18 +02:00
|
|
|
new RowSpec[] {
|
|
|
|
RowSpec.decode("5dlu"),
|
|
|
|
RowSpec.decode("25px"),
|
|
|
|
FormSpecs.DEFAULT_ROWSPEC,
|
|
|
|
RowSpec.decode("25px"),
|
|
|
|
FormSpecs.RELATED_GAP_ROWSPEC,
|
|
|
|
FormSpecs.DEFAULT_ROWSPEC,
|
|
|
|
FormSpecs.RELATED_GAP_ROWSPEC,
|
2016-04-01 00:08:32 +02:00
|
|
|
FormSpecs.DEFAULT_ROWSPEC,
|
|
|
|
FormSpecs.RELATED_GAP_ROWSPEC,
|
2016-03-29 23:25:18 +02:00
|
|
|
FormSpecs.DEFAULT_ROWSPEC,}));
|
|
|
|
|
2016-04-01 00:08:32 +02:00
|
|
|
JLabel lblNewLabel = new JLabel("Source Directory:");
|
2016-03-29 23:25:18 +02:00
|
|
|
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
lblNewLabel.setVerticalAlignment(SwingConstants.TOP);
|
|
|
|
add(lblNewLabel, "2, 2, left, center");
|
|
|
|
|
|
|
|
textField = new JTextField();
|
2016-04-01 00:08:32 +02:00
|
|
|
add(textField, "4, 2, fill, default");
|
2016-03-29 23:25:18 +02:00
|
|
|
textField.setColumns(10);
|
2016-04-01 00:08:32 +02:00
|
|
|
add(btnNewButton, "6, 2, left, top");
|
2016-03-29 23:25:18 +02:00
|
|
|
|
|
|
|
JButton btnNewButton_1 = new JButton("...");
|
|
|
|
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();
|
|
|
|
textField_1.setText(file.getPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-01 00:08:32 +02:00
|
|
|
JLabel lblRpertoireDeDestination = new JLabel("Target Directory:");
|
2016-03-29 23:25:18 +02:00
|
|
|
lblRpertoireDeDestination.setVerticalAlignment(SwingConstants.TOP);
|
|
|
|
lblRpertoireDeDestination.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
add(lblRpertoireDeDestination, "2, 4, left, default");
|
|
|
|
|
|
|
|
textField_1 = new JTextField();
|
2016-04-01 00:08:32 +02:00
|
|
|
add(textField_1, "4, 4, fill, default");
|
2016-03-29 23:25:18 +02:00
|
|
|
textField_1.setColumns(10);
|
|
|
|
btnNewButton_1.setHorizontalAlignment(SwingConstants.RIGHT);
|
2016-04-01 00:08:32 +02:00
|
|
|
add(btnNewButton_1, "6, 4, left, top");
|
2016-03-29 23:25:18 +02:00
|
|
|
|
|
|
|
JButton btnNewButton_2 = new JButton("Backup");
|
|
|
|
btnNewButton_2.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
try
|
|
|
|
{
|
2016-04-01 00:08:32 +02:00
|
|
|
SibaManager.backup(new File(textField.getText()),textField_1.getText());
|
2016-03-29 23:25:18 +02:00
|
|
|
}
|
|
|
|
catch (ArchiveException | IOException e1)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-04-01 00:08:32 +02:00
|
|
|
add(btnNewButton_2, "4, 10");
|
2016-03-29 23:25:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|