/* * 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 org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 long serialVersionUID = -1580485684838045920L; private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ public static final Logger logger = LoggerFactory.getLogger(CheckPanel.class); 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)); btnNewButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { CheckPanel.this.choosenFile = choosenDirectory(); } catch (IOException exception) { logger.error("IOexception ", exception); } catch (NoSuchAlgorithmException exception) { logger.error("NoSuchAlgorithm ", exception); } } }); 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 = new // File(CheckPanel.this.fileToCheckField.getText()); if ((CheckPanel.this.choosenFile != null) && CheckPanel.this.choosenFile.exists()) { boolean check = SibaManager.check(CheckPanel.this.choosenFile); String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text"); if (check) { String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"), CheckPanel.this.choosenFile.getName()); JOptionPane.showMessageDialog(CheckPanel.this, message, titre, JOptionPane.INFORMATION_MESSAGE); } else { String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"), CheckPanel.this.choosenFile.getName()); JOptionPane.showMessageDialog(CheckPanel.this, message, titre, JOptionPane.INFORMATION_MESSAGE); } } else { String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); JOptionPane.showMessageDialog(CheckPanel.this, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE); } } catch (SibaException exception) { logger.error("SibaException ", exception); } } }); add(btnNewButton_1, "3, 4"); } /** * * @return * @throws IOException * @throws NoSuchAlgorithmException */ public File choosenDirectory() throws IOException, NoSuchAlgorithmException { File result; File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null); if ((choosenFile != null) && choosenFile.exists()) { this.fileToCheckField.setText(choosenFile.getName()); result = choosenFile; } else { result = null; } // return result; } /** * * @param sourceDirectory */ public void setFileToCheck(final String sourceDirectory) { this.fileToCheckField.setText(sourceDirectory); } }