2016-04-19 22:34:25 +02:00
|
|
|
/*
|
2016-04-26 23:02:26 +02:00
|
|
|
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
|
2016-04-19 22:34:25 +02:00
|
|
|
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2016-03-29 23:25:18 +02:00
|
|
|
package org.dclermonte.siba.gui;
|
|
|
|
|
2016-04-26 23:02:26 +02:00
|
|
|
import java.awt.Cursor;
|
2016-04-09 11:33:15 +02:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2016-03-29 23:25:18 +02:00
|
|
|
import java.io.File;
|
2016-04-07 00:54:03 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
2016-04-26 23:02:26 +02:00
|
|
|
import java.util.ResourceBundle;
|
2016-04-07 00:54:03 +02:00
|
|
|
|
2016-04-09 11:33:15 +02:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JLabel;
|
2016-04-26 23:02:26 +02:00
|
|
|
import javax.swing.JOptionPane;
|
2016-04-09 11:33:15 +02:00
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
2016-05-22 21:47:41 +02:00
|
|
|
import org.dclermonte.siba.SibaException;
|
2016-05-02 22:28:35 +02:00
|
|
|
import org.dclermonte.siba.model.SibaManager;
|
|
|
|
|
2016-03-29 23:25:18 +02:00
|
|
|
import com.jgoodies.forms.layout.ColumnSpec;
|
2016-04-09 11:33:15 +02:00
|
|
|
import com.jgoodies.forms.layout.FormLayout;
|
2016-03-29 23:25:18 +02:00
|
|
|
import com.jgoodies.forms.layout.FormSpecs;
|
|
|
|
import com.jgoodies.forms.layout.RowSpec;
|
|
|
|
import com.jgoodies.forms.layout.Sizes;
|
|
|
|
|
2016-04-09 11:33:15 +02:00
|
|
|
/**
|
2016-05-19 18:40:00 +02:00
|
|
|
* This class is the panel for Check.
|
|
|
|
*
|
2016-05-22 21:47:41 +02:00
|
|
|
* @author dclermonte
|
2016-04-09 11:33:15 +02:00
|
|
|
*/
|
2016-03-29 23:25:18 +02:00
|
|
|
public class CheckPanel extends JPanel
|
|
|
|
{
|
2016-04-23 17:50:13 +02:00
|
|
|
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
2016-04-09 11:33:15 +02:00
|
|
|
private static final long serialVersionUID = -1580485684838045920L;
|
2016-05-31 18:50:56 +02:00
|
|
|
static File choosenFile;
|
|
|
|
static JTextField textField;
|
2016-03-29 23:25:18 +02:00
|
|
|
|
|
|
|
/**
|
2016-05-19 18:40:00 +02:00
|
|
|
* This is the constructor for this panel.
|
2016-03-29 23:25:18 +02:00
|
|
|
*/
|
|
|
|
public CheckPanel()
|
|
|
|
{
|
2016-04-09 11:33:15 +02:00
|
|
|
setLayout(new FormLayout(
|
|
|
|
new ColumnSpec[] { ColumnSpec.decode("2dlu"),
|
|
|
|
new ColumnSpec(ColumnSpec.LEFT,
|
|
|
|
Sizes.bounded(Sizes.PREFERRED, Sizes.constant("50dlu", true),
|
|
|
|
Sizes.constant("60dlu", true)),
|
|
|
|
1),
|
|
|
|
new ColumnSpec(ColumnSpec.LEFT,
|
|
|
|
Sizes.bounded(Sizes.PREFERRED, Sizes.constant("50dlu", true),
|
|
|
|
Sizes.constant("100dlu", true)),
|
|
|
|
1),
|
|
|
|
ColumnSpec.decode("30dlu"), },
|
|
|
|
new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC,
|
|
|
|
FormSpecs.DEFAULT_ROWSPEC, }));
|
|
|
|
|
2016-04-23 17:50:13 +02:00
|
|
|
JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text")); //$NON-NLS-1$
|
2016-03-29 23:25:18 +02:00
|
|
|
add(lblNewLabel, "2, 2, left, center");
|
2016-04-09 11:33:15 +02:00
|
|
|
|
2016-04-23 17:50:13 +02:00
|
|
|
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$
|
2016-04-26 23:02:26 +02:00
|
|
|
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
2016-04-19 22:34:25 +02:00
|
|
|
btnNewButton.addActionListener(new ActionListener()
|
2016-04-09 11:33:15 +02:00
|
|
|
{
|
2016-03-29 23:25:18 +02:00
|
|
|
@Override
|
2016-04-19 22:34:25 +02:00
|
|
|
public void actionPerformed(final ActionEvent e)
|
2016-04-09 11:33:15 +02:00
|
|
|
{
|
2016-04-07 00:54:03 +02:00
|
|
|
try
|
|
|
|
{
|
2016-06-07 00:21:31 +02:00
|
|
|
CheckPanel.choosenFile = choosenDirectory();
|
2016-05-02 22:28:35 +02:00
|
|
|
|
2016-04-07 00:54:03 +02:00
|
|
|
}
|
|
|
|
catch (IOException e1)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (NoSuchAlgorithmException e1)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2016-03-29 23:25:18 +02:00
|
|
|
}
|
|
|
|
});
|
2016-04-09 11:33:15 +02:00
|
|
|
|
2016-06-07 00:21:31 +02:00
|
|
|
CheckPanel.textField = new JTextField();
|
|
|
|
add(CheckPanel.textField, "3, 2, fill, default");
|
|
|
|
CheckPanel.textField.setColumns(10);
|
2016-03-29 23:25:18 +02:00
|
|
|
add(btnNewButton, "4, 2, left, top");
|
2016-04-09 11:33:15 +02:00
|
|
|
|
2016-04-23 17:50:13 +02:00
|
|
|
JButton btnNewButton_1 = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$
|
2016-04-26 23:02:26 +02:00
|
|
|
btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
2016-04-09 11:33:15 +02:00
|
|
|
btnNewButton_1.addActionListener(new ActionListener()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(final ActionEvent arg0)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-05-02 22:28:35 +02:00
|
|
|
|
2016-06-07 00:21:31 +02:00
|
|
|
if (!(CheckPanel.choosenFile == null) && CheckPanel.choosenFile.exists())
|
2016-05-02 22:28:35 +02:00
|
|
|
{
|
2016-06-07 00:21:31 +02:00
|
|
|
boolean check = SibaManager.check(CheckPanel.choosenFile);
|
2016-05-02 22:28:35 +02:00
|
|
|
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
|
|
|
|
if (check)
|
|
|
|
{
|
2016-06-07 00:21:31 +02:00
|
|
|
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"),
|
|
|
|
CheckPanel.choosenFile.getName());
|
2016-05-02 22:28:35 +02:00
|
|
|
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-07 00:21:31 +02:00
|
|
|
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"),
|
|
|
|
CheckPanel.choosenFile.getName());
|
2016-05-02 22:28:35 +02:00
|
|
|
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
|
|
|
|
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
|
|
|
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
}
|
2016-04-09 11:33:15 +02:00
|
|
|
}
|
2016-05-22 21:47:41 +02:00
|
|
|
catch (SibaException exception)
|
2016-04-09 11:33:15 +02:00
|
|
|
{
|
|
|
|
// TODO Auto-generated catch block
|
2016-05-22 21:47:41 +02:00
|
|
|
exception.printStackTrace();
|
2016-04-09 11:33:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-29 23:25:18 +02:00
|
|
|
add(btnNewButton_1, "3, 4");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-02 22:28:35 +02:00
|
|
|
public File choosenDirectory() throws IOException, NoSuchAlgorithmException
|
2016-04-09 11:33:15 +02:00
|
|
|
{
|
2016-05-02 22:28:35 +02:00
|
|
|
File result;
|
2016-04-12 00:41:43 +02:00
|
|
|
|
2016-06-07 00:21:31 +02:00
|
|
|
CheckPanel.choosenFile = CheckDirectorySelector.showSelectorDialog(null, null);
|
|
|
|
if (!(CheckPanel.choosenFile == null) && CheckPanel.choosenFile.exists())
|
2016-04-12 00:41:43 +02:00
|
|
|
{
|
2016-06-07 00:21:31 +02:00
|
|
|
CheckPanel.textField.setText(CheckPanel.choosenFile.getName());
|
|
|
|
result = CheckPanel.choosenFile;
|
2016-04-09 11:33:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-02 22:28:35 +02:00
|
|
|
result = null;
|
2016-03-29 23:25:18 +02:00
|
|
|
}
|
2016-05-02 22:28:35 +02:00
|
|
|
return result;
|
2016-04-26 23:02:26 +02:00
|
|
|
// }
|
2016-03-29 23:25:18 +02:00
|
|
|
}
|
|
|
|
|
2016-04-09 11:33:15 +02:00
|
|
|
}
|