Siba/src/org/dclermonte/siba/gui/BackupPanel.java

184 lines
6.1 KiB
Java
Raw Normal View History

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.*;
2016-04-07 00:54:03 +02:00
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import java.awt.FlowLayout;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.util.ResourceBundle;
2016-03-29 23:25:18 +02:00
public class BackupPanel extends JPanel
{
2016-04-07 00:54:03 +02:00
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
2016-03-29 23:25:18 +02:00
private JTextField textField;
2016-04-01 00:08:32 +02:00
public JTextField textField_1;
2016-04-07 00:54:03 +02:00
private JRadioButton rdbtnNewRadioButton_1;
private final ButtonGroup buttonGroup = new ButtonGroup();
2016-03-29 23:25:18 +02:00
/**
* Create the panel.
*/
public BackupPanel()
{
2016-04-07 00:54:03 +02:00
setLayout(new BorderLayout(0, 0));
2016-03-29 23:25:18 +02:00
2016-04-07 00:54:03 +02:00
JPanel panel_4 = new JPanel();
add(panel_4, BorderLayout.NORTH);
JLabel lblNewLabel_2 = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text")); //$NON-NLS-1$
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();
add(panel);
panel.setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC,
2016-04-01 00:08:32 +02:00
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"),
FormSpecs.RELATED_GAP_COLSPEC,
2016-04-09 11:33:15 +02:00
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,},
2016-03-29 23:25:18 +02:00
new RowSpec[] {
2016-04-07 00:54:03 +02:00
FormSpecs.RELATED_GAP_ROWSPEC,
2016-03-29 23:25:18 +02:00
FormSpecs.DEFAULT_ROWSPEC,
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-07 00:54:03 +02:00
JLabel lblNewLabel = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel.text")); //$NON-NLS-1$
panel.add(lblNewLabel, "2, 2");
2016-03-29 23:25:18 +02:00
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel.setVerticalAlignment(SwingConstants.TOP);
textField = new JTextField();
2016-04-07 00:54:03 +02:00
panel.add(textField, "4, 2");
2016-03-29 23:25:18 +02:00
textField.setColumns(10);
2016-04-07 00:54:03 +02:00
JButton btnNewButton = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text")); //$NON-NLS-1$
panel.add(btnNewButton, "6, 2");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
2016-04-09 11:33:15 +02:00
int returnVal = fc.showDialog(BackupPanel.this,BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
2016-04-07 00:54:03 +02:00
if (returnVal == JFileChooser.APPROVE_OPTION){
File file = fc.getSelectedFile();
textField.setText(file.getPath());
}
}
});
JLabel lblRpertoireDeDestination = new JLabel(BUNDLE.getString("BackupPanel.lblRpertoireDeDestination.text")); //$NON-NLS-1$
panel.add(lblRpertoireDeDestination, "2, 4");
lblRpertoireDeDestination.setVerticalAlignment(SwingConstants.TOP);
lblRpertoireDeDestination.setHorizontalAlignment(SwingConstants.LEFT);
textField_1 = new JTextField();
panel.add(textField_1, "4, 4");
textField_1.setColumns(10);
JButton btnNewButton_1 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$
panel.add(btnNewButton_1, "6, 4");
2016-03-29 23:25:18 +02:00
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-07 00:54:03 +02:00
btnNewButton_1.setHorizontalAlignment(SwingConstants.RIGHT);
2016-03-29 23:25:18 +02:00
2016-04-07 00:54:03 +02:00
JLabel lblNewLabel_1 = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_1.text")); //$NON-NLS-1$
panel.add(lblNewLabel_1, "2, 6, right, top");
2016-03-29 23:25:18 +02:00
2016-04-07 00:54:03 +02:00
JPanel panel_3 = new JPanel();
panel.add(panel_3, "4, 6, fill, fill");
panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.Y_AXIS));
JRadioButton rdbtnNewRadioButton = new JRadioButton(BUNDLE.getString("BackupPanel.rdbtnNewRadioButton.text")); //$NON-NLS-1$
buttonGroup.add(rdbtnNewRadioButton);
rdbtnNewRadioButton.setSelected(true);
panel_3.add(rdbtnNewRadioButton);
rdbtnNewRadioButton_1 = new JRadioButton(BUNDLE.getString("BackupPanel.rdbtnNewRadioButton_1.text")); //$NON-NLS-1$
buttonGroup.add(rdbtnNewRadioButton_1);
panel_3.add(rdbtnNewRadioButton_1);
JPanel panel_2 = new JPanel();
add(panel_2, BorderLayout.SOUTH);
panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS));
Component verticalStrut_1 = Box.createVerticalStrut(5);
panel_2.add(verticalStrut_1);
JPanel panel_1 = new JPanel();
panel_2.add(panel_1);
panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
Component horizontalGlue = Box.createHorizontalGlue();
panel_1.add(horizontalGlue);
JButton btnNewButton_2 = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text")); //$NON-NLS-1$
panel_1.add(btnNewButton_2);
Component horizontalGlue_1 = Box.createHorizontalGlue();
panel_1.add(horizontalGlue_1);
2016-03-29 23:25:18 +02:00
2016-04-07 00:54:03 +02:00
Component verticalStrut = Box.createVerticalStrut(20);
panel_2.add(verticalStrut);
2016-03-29 23:25:18 +02:00
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-04-07 00:54:03 +02:00
2016-03-29 23:25:18 +02:00
}
catch (ArchiveException | IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
}