/* * Copyright (C) 2016 Didier Clermonté * Copyright (C) 2016 Christian Pierre Momon * * 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 . */ 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 textField; 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)); 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.textField = new JTextField(); add(this.textField, "3, 2, fill, default"); this.textField.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 { if (!(CheckPanel.this.choosenFile == null) && CheckPanel.this.choosenFile.exists()) { boolean check = SibaManager.check(CheckPanel.this.choosenFile); String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text"); String yourFile = BUNDLE.getString("CheckPanel.confirmDialogYourString.text"); if (check) { String message = yourFile + CheckPanel.this.choosenFile.getName() + " " + BUNDLE.getString("CheckPanel.confirmDialogGood.text"); JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE); } else { String message = yourFile + CheckPanel.this.choosenFile.getName() + " " + BUNDLE.getString("CheckPanel.confirmDialogBad.text"); 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; this.choosenFile = CheckDirectorySelector.showSelectorDialog(null, null); if (!(CheckPanel.this.choosenFile == null) && CheckPanel.this.choosenFile.exists()) { this.textField.setText(this.choosenFile.getName()); result = this.choosenFile; } else { result = null; } return result; // } } }