From 163851eb09cb853c1857ece4c325f3f434a96b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Clermont=C3=A9?= Date: Sat, 25 Jun 2016 00:13:45 +0200 Subject: [PATCH] Issue#32 Refactored CheckPanel and removed class variable choosenDirectory --- src/org/dclermonte/siba/gui/CheckPanel.java | 91 ++++++++++++------- .../dclermonte/siba/gui/messages.properties | 6 +- .../siba/gui/messages_fr_FR.properties | 2 +- 3 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/org/dclermonte/siba/gui/CheckPanel.java b/src/org/dclermonte/siba/gui/CheckPanel.java index 3977552..7584171 100644 --- a/src/org/dclermonte/siba/gui/CheckPanel.java +++ b/src/org/dclermonte/siba/gui/CheckPanel.java @@ -17,8 +17,11 @@ * 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.BorderLayout; +import java.awt.Component; import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -27,11 +30,14 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.ResourceBundle; +import javax.swing.Box; +import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.SwingConstants; import org.dclermonte.siba.SibaException; import org.dclermonte.siba.model.SibaManager; @@ -45,41 +51,46 @@ import com.jgoodies.forms.layout.RowSpec; import com.jgoodies.forms.layout.Sizes; /** - * This class is the panel for Check. * - * @author dclermonte + * @author Didier Clermonté (dclermonte@april.org) + * */ + public class CheckPanel extends JPanel { - private static final long serialVersionUID = -1580485684838045920L; + private static final long serialVersionUID = 4495957907349664847L; 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( + setLayout(new BorderLayout(0, 0)); + + JPanel choosePanel = new JPanel(); + add(choosePanel, BorderLayout.CENTER); + choosePanel.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)), + Sizes.bounded(Sizes.PREFERRED, Sizes.constant("120dlu", true), + Sizes.constant("160dlu", true)), 1), ColumnSpec.decode("30dlu"), }, - new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, - FormSpecs.DEFAULT_ROWSPEC, })); + new RowSpec[] { RowSpec.decode("25px"), FormSpecs.DEFAULT_ROWSPEC, })); JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text")); //$NON-NLS-1$ - add(lblNewLabel, "2, 2, left, center"); + lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT); + choosePanel.add(lblNewLabel, "2, 2, left, center"); + + this.fileToCheckField = new JTextField(); + choosePanel.add(this.fileToCheckField, "3, 2, fill, default"); + this.fileToCheckField.setColumns(10); + JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$ - btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnNewButton.addActionListener(new ActionListener() { @Override @@ -87,7 +98,7 @@ public class CheckPanel extends JPanel { try { - CheckPanel.this.choosenFile = choosenDirectory(); + CheckPanel.this.fileToCheckField.setText(choosenDirectory()); } catch (IOException exception) { @@ -99,38 +110,47 @@ public class CheckPanel extends JPanel } } }); + btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + choosePanel.add(btnNewButton, "4, 2, left, top"); - this.fileToCheckField = new JTextField(); - add(this.fileToCheckField, "3, 2, fill, default"); - this.fileToCheckField.setColumns(10); - add(btnNewButton, "4, 2, left, top"); + JPanel actionPanel = new JPanel(); + add(actionPanel, BorderLayout.SOUTH); + actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS)); + Component verticalStrut = Box.createVerticalStrut(20); + actionPanel.add(verticalStrut); + + JPanel panel = new JPanel(); + actionPanel.add(panel); + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); + + Component horizontalGlue = Box.createHorizontalGlue(); + panel.add(horizontalGlue); JButton btnNewButton_1 = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$ - btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + panel.add(btnNewButton_1); btnNewButton_1.addActionListener(new ActionListener() { @Override - public void actionPerformed(final ActionEvent arg0) + public void actionPerformed(final ActionEvent e) { try { - // File choosenFile = new - // File(CheckPanel.this.fileToCheckField.getText()); - if ((CheckPanel.this.choosenFile != null) && CheckPanel.this.choosenFile.exists()) + File choosenFile = new File(CheckPanel.this.fileToCheckField.getText()); + if ((choosenFile != null) && choosenFile.exists()) { - boolean check = SibaManager.check(CheckPanel.this.choosenFile); + boolean check = SibaManager.check(choosenFile); String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text"); if (check) { String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"), - CheckPanel.this.choosenFile.getName()); + 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()); + choosenFile.getName()); JOptionPane.showMessageDialog(CheckPanel.this, message, titre, JOptionPane.INFORMATION_MESSAGE); } @@ -147,9 +167,15 @@ public class CheckPanel extends JPanel { logger.error("SibaException ", exception); } + } }); - add(btnNewButton_1, "3, 4"); + btnNewButton_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + Component horizontalGlue_1 = Box.createHorizontalGlue(); + panel.add(horizontalGlue_1); + Component verticalStrut_1 = Box.createVerticalStrut(20); + actionPanel.add(verticalStrut_1); } /** @@ -158,15 +184,16 @@ public class CheckPanel extends JPanel * @throws IOException * @throws NoSuchAlgorithmException */ - public File choosenDirectory() throws IOException, NoSuchAlgorithmException + public String choosenDirectory() throws IOException, NoSuchAlgorithmException { - File result; + String result; File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null); if ((choosenFile != null) && choosenFile.exists()) { - this.fileToCheckField.setText(choosenFile.getName()); - result = choosenFile; + this.fileToCheckField.setText(choosenFile.getAbsolutePath()); + this.fileToCheckField.setCaretPosition(this.fileToCheckField.getText().length()); + result = choosenFile.getAbsolutePath(); } else { diff --git a/src/org/dclermonte/siba/gui/messages.properties b/src/org/dclermonte/siba/gui/messages.properties index 8cfe936..94dcf19 100644 --- a/src/org/dclermonte/siba/gui/messages.properties +++ b/src/org/dclermonte/siba/gui/messages.properties @@ -1,5 +1,5 @@ #Field ResourceBundle: BUNDLE -#Mon Jun 06 22:22:23 CEST 2016 +#Fri Jun 24 19:36:24 CEST 2016 BackupPanel.TitleBackupPanel.text=Backup BackupPanel.TitleCheckPanel.text=Check BackupPanel.TitleWarning.text=Warning @@ -17,11 +17,13 @@ BackupPanel.sourceFileChooserButton.text=Source Directory BackupPanel.targetFileChooserButton.text=Target Directory CheckDirectorySelector.this.dialogTitle=Directory where is the backup CheckPanel.btnNewButton.text=\u2026 +CheckPanel.btnNewButton.text_1=New button CheckPanel.btnNewButton_1.text=Check +CheckPanel.btnNewButton_1.text_1=New button CheckPanel.confirmDialogBad.text=Your File %s is corrupted CheckPanel.confirmDialogGood.text=Your File %s has been check and is good CheckPanel.confirmDialogTitle.text=Check done -CheckPanel.lblNewLabel.text=File to be Checked +CheckPanel.lblNewLabel.text=File to be Checked \: SibaGUI.mnFile.text=File SibaGUI.mnNewMenu.text=Help SibaGUI.mntmBackup.text=Backup\u2026 diff --git a/src/org/dclermonte/siba/gui/messages_fr_FR.properties b/src/org/dclermonte/siba/gui/messages_fr_FR.properties index 5ed695d..9d64b86 100644 --- a/src/org/dclermonte/siba/gui/messages_fr_FR.properties +++ b/src/org/dclermonte/siba/gui/messages_fr_FR.properties @@ -13,7 +13,7 @@ BackupPanel.TitleBackupPanel.text = Sauvegarder CheckDirectorySelector.this.dialogTitle=Emplacement de la sauvegarde CheckPanel.btnNewButton.text=\u2026 CheckPanel.btnNewButton_1.text=Vérifier -CheckPanel.lblNewLabel.text=Sauvegarde \u00E0 v\u00E9rifier +CheckPanel.lblNewLabel.text=Sauvegarde \u00E0 v\u00E9rifier : SibaGUI.mnNewMenu.text=Aide SibaGUI.mntmNewMenuItem_2.text=A propos SourceDirectorySelector.this.dialogTitle=Choix du répertoire à sauvegarder