178 lines
5.4 KiB
Java
178 lines
5.4 KiB
Java
/*
|
|
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
|
|
* 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/>.
|
|
*/
|
|
package org.dclermonte.siba.gui;
|
|
|
|
import java.awt.Cursor;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.ResourceBundle;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextField;
|
|
|
|
import org.dclermonte.siba.SibaException;
|
|
import org.dclermonte.siba.model.SibaManager;
|
|
|
|
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;
|
|
|
|
/**
|
|
* This class is the panel for Check.
|
|
*
|
|
* @author dclermonte
|
|
*/
|
|
public class CheckPanel extends JPanel
|
|
{
|
|
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
|
private static final long serialVersionUID = -1580485684838045920L;
|
|
private JTextField fileToCheckField;
|
|
private File choosenFile;
|
|
|
|
/**
|
|
* This is the constructor for this panel.
|
|
*/
|
|
public CheckPanel()
|
|
{
|
|
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, }));
|
|
|
|
JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text")); //$NON-NLS-1$
|
|
add(lblNewLabel, "2, 2, left, center");
|
|
|
|
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$
|
|
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
File choosenFile;
|
|
btnNewButton.addActionListener(new ActionListener()
|
|
{
|
|
@Override
|
|
public void actionPerformed(final ActionEvent e)
|
|
{
|
|
try
|
|
{
|
|
CheckPanel.this.choosenFile = choosenDirectory();
|
|
|
|
}
|
|
catch (IOException e1)
|
|
{
|
|
// TODO Auto-generated catch block
|
|
e1.printStackTrace();
|
|
}
|
|
catch (NoSuchAlgorithmException e1)
|
|
{
|
|
// TODO Auto-generated catch block
|
|
e1.printStackTrace();
|
|
}
|
|
}
|
|
});
|
|
|
|
this.fileToCheckField = new JTextField();
|
|
add(this.fileToCheckField, "3, 2, fill, default");
|
|
this.fileToCheckField.setColumns(10);
|
|
add(btnNewButton, "4, 2, left, top");
|
|
|
|
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()
|
|
{
|
|
@Override
|
|
public void actionPerformed(final ActionEvent arg0)
|
|
{
|
|
try
|
|
{
|
|
File choosenFile = CheckPanel.this.choosenFile;
|
|
if ((choosenFile != null) && choosenFile.exists())
|
|
{
|
|
boolean check = SibaManager.check(choosenFile);
|
|
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
|
|
if (check)
|
|
{
|
|
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"),
|
|
choosenFile.getName());
|
|
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
|
|
}
|
|
else
|
|
{
|
|
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"),
|
|
choosenFile.getName());
|
|
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);
|
|
}
|
|
}
|
|
|
|
catch (SibaException exception)
|
|
{
|
|
// TODO Auto-generated catch block
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
}
|
|
});
|
|
add(btnNewButton_1, "3, 4");
|
|
}
|
|
|
|
public File choosenDirectory() throws IOException, NoSuchAlgorithmException
|
|
{
|
|
File result;
|
|
|
|
File choosenFile = CheckDirectorySelector.showSelectorDialog(null, null);
|
|
if ((choosenFile != null) && choosenFile.exists())
|
|
{
|
|
this.fileToCheckField.setText(choosenFile.getName());
|
|
result = choosenFile;
|
|
}
|
|
else
|
|
{
|
|
result = null;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void setFileToCheck(final String sourceDirectory)
|
|
{
|
|
this.fileToCheckField.setText(sourceDirectory);
|
|
}
|
|
}
|