Replace tab by space and remove trailing comment

This commit is contained in:
Didier Clermonté 2016-08-17 23:38:04 +02:00
parent 8bc116734c
commit ee8abfbca8
14 changed files with 1480 additions and 1478 deletions

View File

@ -90,7 +90,7 @@ org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
@ -297,7 +297,7 @@ org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false

View File

@ -35,43 +35,43 @@ import org.slf4j.LoggerFactory;
*/ */
public final class Siba public final class Siba
{ {
private static Logger logger = LoggerFactory.getLogger(Siba.class); private static Logger logger = LoggerFactory.getLogger(Siba.class);
private Siba() private Siba()
{ {
} }
/** /**
* *
* @param args * @param args
* arguments * arguments
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
// Configure log. // Configure log.
File loggerConfig = new File("log4j.properties"); File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists()) if (loggerConfig.exists())
{ {
PropertyConfigurator.configure(loggerConfig.getAbsolutePath()); PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done."); logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile()); logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
} }
else else
{ {
BasicConfigurator.configure(); BasicConfigurator.configure();
logger.info("Basic log configuration done."); logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile()); logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
} }
// Run. // Run.
if (args.length == 0) if (args.length == 0)
{ {
SibaGUI.run(); SibaGUI.run();
} }
else else
{ {
SibaCLI.run(args); SibaCLI.run(args);
} }
} }
} }

View File

@ -27,45 +27,45 @@ package org.dclermonte.siba;
*/ */
public class SibaException extends Exception public class SibaException extends Exception
{ {
private static final long serialVersionUID = 2909630770291570845L; private static final long serialVersionUID = 2909630770291570845L;
/** /**
* *
*/ */
public SibaException() public SibaException()
{ {
super(); super();
} }
/** /**
* *
* @param message * @param message
* error message * error message
*/ */
public SibaException(final String message) public SibaException(final String message)
{ {
super(message); super(message);
} }
/** /**
* *
* @param message * @param message
* text * text
* @param cause * @param cause
* caused by * caused by
*/ */
public SibaException(final String message, final Throwable cause) public SibaException(final String message, final Throwable cause)
{ {
super(message, cause); super(message, cause);
} }
/** /**
* *
* @param cause * @param cause
* caused by * caused by
*/ */
public SibaException(final Throwable cause) public SibaException(final Throwable cause)
{ {
super(cause); super(cause);
} }
} }

View File

@ -37,191 +37,191 @@ import fr.devinsy.util.strings.StringList;
*/ */
public final class SibaCLI public final class SibaCLI
{ {
private static Logger logger = LoggerFactory.getLogger(SibaCLI.class); private static Logger logger = LoggerFactory.getLogger(SibaCLI.class);
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.cli.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.cli.messages"); //$NON-NLS-1$
private SibaCLI() private SibaCLI()
{ {
} }
public static void backup(final File directoryToSave) throws SibaException public static void backup(final File directoryToSave) throws SibaException
{ {
File result; File result;
result = SibaManager.backup(directoryToSave); result = SibaManager.backup(directoryToSave);
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$ System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName());
} }
/** /**
* *
* This method is called for Backup from CLI. * This method is called for Backup from CLI.
* *
* @param directoryToSave * @param directoryToSave
* The directory to save * The directory to save
* @param targetDirectory * @param targetDirectory
* where to put the generated file * where to put the generated file
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public static void backup(final File directoryToSave, final File targetDirectory) throws SibaException public static void backup(final File directoryToSave, final File targetDirectory) throws SibaException
{ {
File result; File result;
result = SibaManager.backup(directoryToSave, targetDirectory); result = SibaManager.backup(directoryToSave, targetDirectory);
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$ System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName());
} }
/** /**
* *
* This method is called for Check from CLI. anObject * This method is called for Check from CLI. anObject
* *
* @param fileToCheck * @param fileToCheck
* The file to be check * The file to be check
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public static void check(final File fileToCheck) throws SibaException public static void check(final File fileToCheck) throws SibaException
{ {
boolean result; boolean result;
result = SibaManager.check(fileToCheck); result = SibaManager.check(fileToCheck);
if (result) if (result)
{ {
String message = String.format(BUNDLE.getString("confirmDialogGood.text"), fileToCheck.getName()); String message = String.format(BUNDLE.getString("confirmDialogGood.text"), fileToCheck.getName());
System.out.println(message); System.out.println(message);
} }
else else
{ {
String message = String.format(BUNDLE.getString("confirmDialogBad.text"), fileToCheck.getName()); String message = String.format(BUNDLE.getString("confirmDialogBad.text"), fileToCheck.getName());
System.out.println(message); System.out.println(message);
} }
} }
/** /**
* This method send help response. * This method send help response.
* *
*/ */
public static void help() public static void help()
{ {
StringList message = new StringList(); StringList message = new StringList();
message.appendln("Usage:"); message.appendln("Usage:");
message.appendln(" siba [ -h | -help | --help ]"); message.appendln(" siba [ -h | -help | --help ]");
message.appendln(" siba backup directoryToSave [ target ]"); message.appendln(" siba backup directoryToSave [ target ]");
message.appendln(" siba check [ filename | filename.tgz | filename.tgz.md5 ]"); message.appendln(" siba check [ filename | filename.tgz | filename.tgz.md5 ]");
System.out.println(message.toString()); System.out.println(message.toString());
} }
/** /**
* *
*/ */
public static void manageSibaCLIException() public static void manageSibaCLIException()
{ {
// Set default CLI catch. // Set default CLI catch.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{ {
@Override @Override
public void uncaughtException(final Thread thread, final Throwable exception) public void uncaughtException(final Thread thread, final Throwable exception)
{ {
String message; String message;
if (exception instanceof OutOfMemoryError) if (exception instanceof OutOfMemoryError)
{ {
message = "Java ran out of memory!\n\n"; message = "Java ran out of memory!\n\n";
} }
else else
{ {
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")"; message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
} }
logger.error("uncaughtException ", exception); logger.error("uncaughtException ", exception);
logger.error(message); logger.error(message);
logger.info(BUNDLE.getString("UnexpectedError.text")); logger.info(BUNDLE.getString("UnexpectedError.text"));
} }
}); });
} }
/** /**
* *
* This method launch CLI. * This method launch CLI.
* *
* @param args * @param args
* necessary arguments * necessary arguments
*/ */
public static void run(final String[] args) public static void run(final String[] args)
{ {
try try
{ {
manageSibaCLIException(); manageSibaCLIException();
// This part implements an automate. // This part implements an automate.
int parameterCount = args.length; int parameterCount = args.length;
if (parameterCount == 0) if (parameterCount == 0)
{ {
help(); help();
} }
else if (StringUtils.equals(args[0], "-h") || StringUtils.equals(args[0], "-help") else if (StringUtils.equals(args[0], "-h") || StringUtils.equals(args[0], "-help")
|| StringUtils.equals(args[0], "--help")) || StringUtils.equals(args[0], "--help"))
{ {
help(); help();
} }
else if (StringUtils.equals(args[0], "backup")) else if (StringUtils.equals(args[0], "backup"))
{ {
if (parameterCount == 1) if (parameterCount == 1)
{ {
backup(null, null); backup(null, null);
} }
else if (parameterCount == 2) else if (parameterCount == 2)
{ {
backup(new File(args[1])); backup(new File(args[1]));
} }
else if (parameterCount == 3) else if (parameterCount == 3)
{ {
backup(new File(args[1]), new File(args[2])); backup(new File(args[1]), new File(args[2]));
} }
else else
{ {
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("ToManyParameter.text"));
} }
} }
else if (StringUtils.equals(args[0], "check")) else if (StringUtils.equals(args[0], "check"))
{ {
if (parameterCount == 1) if (parameterCount == 1)
{ {
check(null); check(null);
} }
else if (parameterCount == 2) else if (parameterCount == 2)
{ {
String fileToCheckName; String fileToCheckName;
if (!args[1].endsWith("tgz") && !args[1].endsWith("md5")) if (!args[1].endsWith("tgz") && !args[1].endsWith("md5"))
{ {
fileToCheckName = args[1].concat(".tgz.md5"); fileToCheckName = args[1].concat(".tgz.md5");
} }
else if (args[1].endsWith("tgz")) else if (args[1].endsWith("tgz"))
{ {
fileToCheckName = args[1].concat(".md5"); fileToCheckName = args[1].concat(".md5");
} }
else else
{ {
fileToCheckName = args[1]; fileToCheckName = args[1];
} }
File fileToCheck = new File(fileToCheckName); File fileToCheck = new File(fileToCheckName);
check(fileToCheck); check(fileToCheck);
} }
else else
{ {
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("ToManyParameter.text"));
} }
} }
else else
{ {
System.out.println(BUNDLE.getString("badUsage.text")); System.out.println(BUNDLE.getString("badUsage.text"));
help(); help();
} }
} }
catch (SibaException exception) catch (SibaException exception)
{ {
System.err.println("SibaException = " + exception.getMessage()); System.err.println("SibaException = " + exception.getMessage());
logger.error(exception.getMessage(), exception); logger.error(exception.getMessage(), exception);
help(); help();
} }
} }
} }

View File

@ -49,86 +49,86 @@ import org.dclermonte.siba.model.SibaUtils;
*/ */
public class AboutDialog extends JDialog public class AboutDialog extends JDialog
{ {
private static final long serialVersionUID = 8868109575782482455L; private static final long serialVersionUID = 8868109575782482455L;
/** /**
* This is the constructor for the dialog. * This is the constructor for the dialog.
* *
* @throws IOException * @throws IOException
* IOException * IOException
*/ */
public AboutDialog() throws IOException public AboutDialog() throws IOException
{ {
setMinimumSize(new Dimension(600, 350)); setMinimumSize(new Dimension(600, 350));
setMaximumSize(new Dimension(600, 500)); setMaximumSize(new Dimension(600, 500));
setIconImage(Toolkit.getDefaultToolkit() setIconImage(Toolkit.getDefaultToolkit()
.getImage(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png"))); .getImage(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
setBackground(Color.GREEN); setBackground(Color.GREEN);
getContentPane().setBackground(Color.GREEN); getContentPane().setBackground(Color.GREEN);
setBounds(100, 100, 450, 300); setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout());
{ {
JPanel buttonPane = new JPanel(); JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.GREEN); buttonPane.setBackground(Color.GREEN);
getContentPane().add(buttonPane, BorderLayout.SOUTH); getContentPane().add(buttonPane, BorderLayout.SOUTH);
{ {
JButton okButton = new JButton("OK"); JButton okButton = new JButton("OK");
okButton.setFocusTraversalKeysEnabled(false); okButton.setFocusTraversalKeysEnabled(false);
okButton.setFocusPainted(false); okButton.setFocusPainted(false);
okButton.setBackground(new Color(0, 128, 0)); okButton.setBackground(new Color(0, 128, 0));
okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
okButton.addActionListener(new ActionListener() okButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
setVisible(false); setVisible(false);
dispose(); dispose();
} }
}); });
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
{ {
Component horizontalGlue = Box.createHorizontalGlue(); Component horizontalGlue = Box.createHorizontalGlue();
buttonPane.add(horizontalGlue); buttonPane.add(horizontalGlue);
} }
okButton.setActionCommand("OK"); okButton.setActionCommand("OK");
buttonPane.add(okButton); buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton); getRootPane().setDefaultButton(okButton);
} }
{ {
Component horizontalGlue = Box.createHorizontalGlue(); Component horizontalGlue = Box.createHorizontalGlue();
buttonPane.add(horizontalGlue); buttonPane.add(horizontalGlue);
} }
} }
JPanel panel = new JPanel(); JPanel panel = new JPanel();
panel.setBackground(Color.GREEN); panel.setBackground(Color.GREEN);
getContentPane().add(panel, BorderLayout.CENTER); getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(new BorderLayout(0, 0)); panel.setLayout(new BorderLayout(0, 0));
JTextPane txtpnSimpleBackupDveloppeur = new JTextPane(); JTextPane txtpnSimpleBackupDveloppeur = new JTextPane();
txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN); txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN);
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14)); txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
txtpnSimpleBackupDveloppeur.setContentType("text/html"); txtpnSimpleBackupDveloppeur.setContentType("text/html");
String resource; String resource;
String locale = Locale.getDefault().toString(); String locale = Locale.getDefault().toString();
if (locale.equals("fr_FR")) if (locale.equals("fr_FR"))
{ {
resource = "/org/dclermonte/siba/gui/about_fr.html"; resource = "/org/dclermonte/siba/gui/about_fr.html";
} }
else else
{ {
resource = "/org/dclermonte/siba/gui/about_en.html"; resource = "/org/dclermonte/siba/gui/about_en.html";
} }
txtpnSimpleBackupDveloppeur.setText(SibaUtils.readResource(resource)); txtpnSimpleBackupDveloppeur.setText(SibaUtils.readResource(resource));
panel.add(txtpnSimpleBackupDveloppeur); panel.add(txtpnSimpleBackupDveloppeur);
{ {
JLabel lblNewLabel = new JLabel(""); JLabel lblNewLabel = new JLabel("");
lblNewLabel lblNewLabel
.setIcon(new ImageIcon(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo_256.png"))); .setIcon(new ImageIcon(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo_256.png")));
panel.add(lblNewLabel, BorderLayout.WEST); panel.add(lblNewLabel, BorderLayout.WEST);
} }
} }
} }

View File

@ -53,167 +53,167 @@ import com.jgoodies.forms.layout.RowSpec;
*/ */
public class BackupPanel extends JPanel public class BackupPanel extends JPanel
{ {
private static final long serialVersionUID = 4714383090458639282L; private static final long serialVersionUID = 4714383090458639282L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private JTextField sourceDirectoryField; private JTextField sourceDirectoryField;
private JTextField targetDirectoryField; private JTextField targetDirectoryField;
/** /**
* This is the constructor for this panel. * This is the constructor for this panel.
* *
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public BackupPanel() throws SibaException public BackupPanel() throws SibaException
{ {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
JPanel helpPanel = new JPanel(); JPanel helpPanel = new JPanel();
add(helpPanel, BorderLayout.NORTH); add(helpPanel, BorderLayout.NORTH);
JLabel lblHelp = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text")); //$NON-NLS-1$ JLabel lblHelp = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text"));
helpPanel.add(lblHelp); helpPanel.add(lblHelp);
JPanel choosePanel = new JPanel(); JPanel choosePanel = new JPanel();
add(choosePanel); add(choosePanel);
choosePanel.setLayout(new FormLayout( choosePanel.setLayout(new FormLayout(
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, }, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
JLabel lblSourceDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblSourceDirectory.text")); //$NON-NLS-1$ JLabel lblSourceDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblSourceDirectory.text"));
choosePanel.add(lblSourceDirectory, "2, 2"); choosePanel.add(lblSourceDirectory, "2, 2");
lblSourceDirectory.setHorizontalAlignment(SwingConstants.LEFT); lblSourceDirectory.setHorizontalAlignment(SwingConstants.LEFT);
lblSourceDirectory.setVerticalAlignment(SwingConstants.TOP); lblSourceDirectory.setVerticalAlignment(SwingConstants.TOP);
this.sourceDirectoryField = new JTextField(); this.sourceDirectoryField = new JTextField();
choosePanel.add(this.sourceDirectoryField, "4, 2"); choosePanel.add(this.sourceDirectoryField, "4, 2");
this.sourceDirectoryField.setColumns(10); this.sourceDirectoryField.setColumns(10);
JButton btnSourceDirectory = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text")); //$NON-NLS-1$ JButton btnSourceDirectory = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text"));
btnSourceDirectory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnSourceDirectory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnSourceDirectory.addActionListener(new ActionListener() btnSourceDirectory.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
File file = SourceDirectorySelector.showSelectorDialog(BackupPanel.this, null); File file = SourceDirectorySelector.showSelectorDialog(BackupPanel.this, null);
if (file != null) if (file != null)
{ {
BackupPanel.this.sourceDirectoryField.setText(file.getPath()); BackupPanel.this.sourceDirectoryField.setText(file.getPath());
} }
} }
}); });
choosePanel.add(btnSourceDirectory, "6, 2"); choosePanel.add(btnSourceDirectory, "6, 2");
JLabel lblTargetDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblTargetDirectory.text")); //$NON-NLS-1$ JLabel lblTargetDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblTargetDirectory.text"));
choosePanel.add(lblTargetDirectory, "2, 4"); choosePanel.add(lblTargetDirectory, "2, 4");
lblTargetDirectory.setVerticalAlignment(SwingConstants.TOP); lblTargetDirectory.setVerticalAlignment(SwingConstants.TOP);
lblTargetDirectory.setHorizontalAlignment(SwingConstants.LEFT); lblTargetDirectory.setHorizontalAlignment(SwingConstants.LEFT);
this.targetDirectoryField = new JTextField(); this.targetDirectoryField = new JTextField();
choosePanel.add(this.targetDirectoryField, "4, 4"); choosePanel.add(this.targetDirectoryField, "4, 4");
this.targetDirectoryField.setColumns(10); this.targetDirectoryField.setColumns(10);
JButton btnTarget = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$ JButton btnTarget = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text"));
btnTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnTarget.addActionListener(new ActionListener() btnTarget.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
File file = TargetDirectorySelector.showSelectorDialog(BackupPanel.this, null); File file = TargetDirectorySelector.showSelectorDialog(BackupPanel.this, null);
if (file != null) if (file != null)
{ {
BackupPanel.this.targetDirectoryField.setText(file.getPath()); BackupPanel.this.targetDirectoryField.setText(file.getPath());
} }
} }
}); });
choosePanel.add(btnTarget, "6, 4"); choosePanel.add(btnTarget, "6, 4");
btnTarget.setHorizontalAlignment(SwingConstants.RIGHT); btnTarget.setHorizontalAlignment(SwingConstants.RIGHT);
JPanel actionPanel = new JPanel(); JPanel actionPanel = new JPanel();
add(actionPanel, BorderLayout.SOUTH); add(actionPanel, BorderLayout.SOUTH);
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS)); actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
Component verticalStrut1 = Box.createVerticalStrut(5); Component verticalStrut1 = Box.createVerticalStrut(5);
actionPanel.add(verticalStrut1); actionPanel.add(verticalStrut1);
JPanel buttonActionPanel = new JPanel(); JPanel buttonActionPanel = new JPanel();
actionPanel.add(buttonActionPanel); actionPanel.add(buttonActionPanel);
buttonActionPanel.setLayout(new BoxLayout(buttonActionPanel, BoxLayout.X_AXIS)); buttonActionPanel.setLayout(new BoxLayout(buttonActionPanel, BoxLayout.X_AXIS));
Component horizontalGlue = Box.createHorizontalGlue(); Component horizontalGlue = Box.createHorizontalGlue();
buttonActionPanel.add(horizontalGlue); buttonActionPanel.add(horizontalGlue);
JButton btnBackup = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text")); //$NON-NLS-1$ JButton btnBackup = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text"));
btnBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonActionPanel.add(btnBackup); buttonActionPanel.add(btnBackup);
Component horizontalGlue1 = Box.createHorizontalGlue(); Component horizontalGlue1 = Box.createHorizontalGlue();
buttonActionPanel.add(horizontalGlue1); buttonActionPanel.add(horizontalGlue1);
Component verticalStrut = Box.createVerticalStrut(20); Component verticalStrut = Box.createVerticalStrut(20);
actionPanel.add(verticalStrut); actionPanel.add(verticalStrut);
btnBackup.addActionListener(new ActionListener() btnBackup.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
try try
{ {
File directoryToSave1 = new File(BackupPanel.this.sourceDirectoryField.getText()); File directoryToSave1 = new File(BackupPanel.this.sourceDirectoryField.getText());
File targetDirectory = new File(BackupPanel.this.targetDirectoryField.getText()); File targetDirectory = new File(BackupPanel.this.targetDirectoryField.getText());
if (directoryToSave1.exists() && targetDirectory.exists()) if (directoryToSave1.exists() && targetDirectory.exists())
{ {
File output1 = SibaManager.backup(directoryToSave1, targetDirectory); File output1 = SibaManager.backup(directoryToSave1, targetDirectory);
String message = BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + output1.getName(); String message = BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + output1.getName();
String titre = BUNDLE.getString("BackupPanel.confirmDialogTitle.text"); String titre = BUNDLE.getString("BackupPanel.confirmDialogTitle.text");
JOptionPane.showMessageDialog(BackupPanel.this, message, titre, JOptionPane.showMessageDialog(BackupPanel.this, message, titre,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
else else
{ {
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text"); String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning, JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
} }
catch (SibaException exception) catch (SibaException exception)
{ {
String dataMissing = exception.getMessage(); String dataMissing = exception.getMessage();
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning, JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
} }
}); });
} }
/** /**
* *
* @param sourceDirectory * @param sourceDirectory
* the source Directory * the source Directory
*/ */
public void setSourceDirectory(final String sourceDirectory) public void setSourceDirectory(final String sourceDirectory)
{ {
this.sourceDirectoryField.setText(sourceDirectory); this.sourceDirectoryField.setText(sourceDirectory);
} }
} }

View File

@ -19,103 +19,103 @@ import org.slf4j.LoggerFactory;
*/ */
public class CheckDirectorySelector extends JFileChooser public class CheckDirectorySelector extends JFileChooser
{ {
private static final long serialVersionUID = 3782597353602048214L; private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
private static Logger logger = LoggerFactory.getLogger(CheckDirectorySelector.class); private static Logger logger = LoggerFactory.getLogger(CheckDirectorySelector.class);
/** /**
* *
* @param targetFile * @param targetFile
* target file * target file
*/ */
public CheckDirectorySelector(final File targetFile) public CheckDirectorySelector(final File targetFile)
{ {
super(); super();
setBackground(new Color(152, 251, 152)); setBackground(new Color(152, 251, 152));
// //
File file; File file;
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath()))) if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{ {
file = null; file = null;
} }
else if (targetFile.isFile()) else if (targetFile.isFile())
{ {
file = targetFile.getParentFile(); file = targetFile.getParentFile();
} }
else else
{ {
file = targetFile; file = targetFile;
} }
// //
setSelectedFile(file); setSelectedFile(file);
setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle")); //$NON-NLS-1$ setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle"));
setFileSelectionMode(JFileChooser.FILES_ONLY); setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5"); FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5");
setAcceptAllFileFilterUsed(false); setAcceptAllFileFilterUsed(false);
addChoosableFileFilter(filter); addChoosableFileFilter(filter);
setApproveButtonText(BUNDLE.getString("BackupPanel.checkFileChooserButton.text")); setApproveButtonText(BUNDLE.getString("BackupPanel.checkFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG); setDialogType(CUSTOM_DIALOG);
} }
/** /**
* *
*/ */
@Override @Override
public final void setSelectedFile(final File file) public final void setSelectedFile(final File file)
{ {
// //
super.setSelectedFile(file); super.setSelectedFile(file);
logger.debug("==== SET SELECTED FILE================="); logger.debug("==== SET SELECTED FILE=================");
logger.debug("SELECED FILE {}", file); logger.debug("SELECED FILE {}", file);
} }
/** /**
* *
*/ */
@Override @Override
public void setVisible(final boolean visible) public void setVisible(final boolean visible)
{ {
// //
super.setVisible(visible); super.setVisible(visible);
if (!visible) if (!visible)
{ {
// //
resetChoosableFileFilters(); resetChoosableFileFilters();
} }
} }
/** /**
* This method is the main one of the selector. * This method is the main one of the selector.
* *
* @param parent * @param parent
* The parent's component * The parent's component
* @param targetFile * @param targetFile
* target file * target file
* @return the selected file * @return the selected file
*/ */
public static File showSelectorDialog(final Component parent, final File targetFile) public static File showSelectorDialog(final Component parent, final File targetFile)
{ {
File result; File result;
// //
CheckDirectorySelector selector = new CheckDirectorySelector(targetFile); CheckDirectorySelector selector = new CheckDirectorySelector(targetFile);
// //
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION) if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{ {
// //
result = selector.getSelectedFile(); result = selector.getSelectedFile();
} }
else else
{ {
// //
result = null; result = null;
} }
// //
return result; return result;
} }
} }

View File

@ -55,125 +55,125 @@ import com.jgoodies.forms.layout.RowSpec;
public class CheckPanel extends JPanel public class CheckPanel extends JPanel
{ {
private static final long serialVersionUID = 4495957907349664847L; private static final long serialVersionUID = 4495957907349664847L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static Logger logger = LoggerFactory.getLogger(CheckPanel.class); public static Logger logger = LoggerFactory.getLogger(CheckPanel.class);
private JTextField fileToCheckField; private JTextField fileToCheckField;
/** /**
* *
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public CheckPanel() throws SibaException public CheckPanel() throws SibaException
{ {
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
JPanel choosePanel = new JPanel(); JPanel choosePanel = new JPanel();
add(choosePanel, BorderLayout.CENTER); add(choosePanel, BorderLayout.CENTER);
choosePanel.setLayout(new FormLayout( choosePanel.setLayout(new FormLayout(
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, }, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text")); //$NON-NLS-1$ JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text"));
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT); lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
choosePanel.add(lblNewLabel, "2, 2, left, center"); choosePanel.add(lblNewLabel, "2, 2, left, center");
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$ JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text"));
btnNewButton.addActionListener(new ActionListener() btnNewButton.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null); File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null);
if ((choosenFile != null) && choosenFile.exists()) if ((choosenFile != null) && choosenFile.exists())
{ {
CheckPanel.this.fileToCheckField.setText(choosenFile.getAbsolutePath()); CheckPanel.this.fileToCheckField.setText(choosenFile.getAbsolutePath());
CheckPanel.this.fileToCheckField CheckPanel.this.fileToCheckField
.setCaretPosition(CheckPanel.this.fileToCheckField.getText().length()); .setCaretPosition(CheckPanel.this.fileToCheckField.getText().length());
} }
} }
}); });
this.fileToCheckField = new JTextField(); this.fileToCheckField = new JTextField();
choosePanel.add(this.fileToCheckField, "4, 2, fill, default"); choosePanel.add(this.fileToCheckField, "4, 2, fill, default");
this.fileToCheckField.setColumns(10); this.fileToCheckField.setColumns(10);
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
choosePanel.add(btnNewButton, "6, 2, left, top"); choosePanel.add(btnNewButton, "6, 2, left, top");
JPanel actionPanel = new JPanel(); JPanel actionPanel = new JPanel();
add(actionPanel, BorderLayout.SOUTH); add(actionPanel, BorderLayout.SOUTH);
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS)); actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
Component verticalStrut = Box.createVerticalStrut(20); Component verticalStrut = Box.createVerticalStrut(20);
actionPanel.add(verticalStrut); actionPanel.add(verticalStrut);
JPanel panel = new JPanel(); JPanel panel = new JPanel();
actionPanel.add(panel); actionPanel.add(panel);
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
Component horizontalGlue = Box.createHorizontalGlue(); Component horizontalGlue = Box.createHorizontalGlue();
panel.add(horizontalGlue); panel.add(horizontalGlue);
JButton btnCheck = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$ JButton btnCheck = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text"));
panel.add(btnCheck); panel.add(btnCheck);
btnCheck.addActionListener(new ActionListener() btnCheck.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
try try
{ {
File choosenFile = new File(CheckPanel.this.fileToCheckField.getText()); File choosenFile = new File(CheckPanel.this.fileToCheckField.getText());
if ((choosenFile != null) && choosenFile.exists()) if ((choosenFile != null) && choosenFile.exists())
{ {
boolean check = SibaManager.check(choosenFile); boolean check = SibaManager.check(choosenFile);
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text"); String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
if (check) if (check)
{ {
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"), String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"),
choosenFile.getName()); choosenFile.getName());
JOptionPane.showMessageDialog(CheckPanel.this, message, titre, JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
else else
{ {
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"), String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"),
choosenFile.getName()); choosenFile.getName());
JOptionPane.showMessageDialog(CheckPanel.this, message, titre, JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
} }
else else
{ {
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text"); String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(CheckPanel.this, dataMissing, titleWarning, JOptionPane.showMessageDialog(CheckPanel.this, dataMissing, titleWarning,
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
} }
} }
catch (SibaException exception) catch (SibaException exception)
{ {
logger.error("SibaException ", exception); logger.error("SibaException ", exception);
} }
} }
}); });
btnCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
Component horizontalGlue1 = Box.createHorizontalGlue(); Component horizontalGlue1 = Box.createHorizontalGlue();
panel.add(horizontalGlue1); panel.add(horizontalGlue1);
Component verticalStrut1 = Box.createVerticalStrut(20); Component verticalStrut1 = Box.createVerticalStrut(20);
actionPanel.add(verticalStrut1); actionPanel.add(verticalStrut1);
} }
/** /**
* *
* @param sourceDirectory * @param sourceDirectory
* the source directory * the source directory
*/ */
public void setFileToCheck(final String sourceDirectory) public void setFileToCheck(final String sourceDirectory)
{ {
this.fileToCheckField.setText(sourceDirectory); this.fileToCheckField.setText(sourceDirectory);
} }
} }

View File

@ -63,279 +63,279 @@ import org.slf4j.LoggerFactory;
*/ */
public final class SibaGUI public final class SibaGUI
{ {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static Logger logger = LoggerFactory.getLogger(SibaGUI.class); public static Logger logger = LoggerFactory.getLogger(SibaGUI.class);
private JFrame frmSimpleBackup; private JFrame frmSimpleBackup;
/** /**
* Launch the application. * Launch the application.
*/ */
private BackupPanel backupPanel; private BackupPanel backupPanel;
private CheckPanel checkPanel; private CheckPanel checkPanel;
/** /**
* This is the constructor of this application. * This is the constructor of this application.
* *
* @throws UnsupportedLookAndFeelException * @throws UnsupportedLookAndFeelException
* @throws IllegalAccessException * @throws IllegalAccessException
* @throws InstantiationException * @throws InstantiationException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
private SibaGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException, private SibaGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException, SibaException UnsupportedLookAndFeelException, SibaException
{ {
final Locale locale; final Locale locale;
// Set default GUI catch. // Set default GUI catch.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{ {
@Override @Override
public void uncaughtException(final Thread thread, final Throwable exception) public void uncaughtException(final Thread thread, final Throwable exception)
{ {
String message; String message;
if (exception instanceof OutOfMemoryError) if (exception instanceof OutOfMemoryError)
{ {
message = "Java ran out of memory!\n\n"; message = "Java ran out of memory!\n\n";
} }
else else
{ {
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")"; message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
} }
JOptionPane.showMessageDialog(SibaGUI.this.frmSimpleBackup, message, "Error", JOptionPane.showMessageDialog(SibaGUI.this.frmSimpleBackup, message, "Error",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
logger.error("uncaughtException ", exception); logger.error("uncaughtException ", exception);
} }
}); });
// Remove BOLD on default font. // Remove BOLD on default font.
UIManager.put("swing.boldMetal", Boolean.FALSE); UIManager.put("swing.boldMetal", Boolean.FALSE);
// Set LookAndFeel. // Set LookAndFeel.
logger.debug("System lookAndFeel property: {}", System.getProperty("swing.defaultlaf")); logger.debug("System lookAndFeel property: {}", System.getProperty("swing.defaultlaf"));
logger.debug("Available lookAndFeel: {} ", GUIToolBox.availableLookAndFeels().toString()); logger.debug("Available lookAndFeel: {} ", GUIToolBox.availableLookAndFeels().toString());
logger.debug("System lookAndFeel: {} ", UIManager.getSystemLookAndFeelClassName()); logger.debug("System lookAndFeel: {} ", UIManager.getSystemLookAndFeelClassName());
logger.debug("Current lookAndFeel: {} ", UIManager.getLookAndFeel().getName()); logger.debug("Current lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
if (!StringUtils.equals(UIManager.getSystemLookAndFeelClassName(), "javax.swing.plaf.metal.MetalLookAndFeel")) if (!StringUtils.equals(UIManager.getSystemLookAndFeelClassName(), "javax.swing.plaf.metal.MetalLookAndFeel"))
{ {
try try
{ {
logger.debug("Metal LAF setted and system LAF detected, try to set system LAF."); logger.debug("Metal LAF setted and system LAF detected, try to set system LAF.");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} }
catch (final Exception exception) catch (final Exception exception)
{ {
logger.debug("Failed to set the system LookAndFeel."); logger.debug("Failed to set the system LookAndFeel.");
} }
} }
else if (GUIToolBox.availableLookAndFeels().toString().contains("GTK+")) else if (GUIToolBox.availableLookAndFeels().toString().contains("GTK+"))
{ {
try try
{ {
logger.debug("Metal LAF setted and GTK+ LAF detected, try to set GTK+ LAF."); logger.debug("Metal LAF setted and GTK+ LAF detected, try to set GTK+ LAF.");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} }
catch (final Exception exception) catch (final Exception exception)
{ {
logger.debug("Failed to set the system LookAndFeel."); logger.debug("Failed to set the system LookAndFeel.");
} }
} }
logger.debug("Activated lookAndFeel: {} ", UIManager.getLookAndFeel().getName()); logger.debug("Activated lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
// Set default locale. // Set default locale.
locale = Locale.getDefault(); locale = Locale.getDefault();
updateLanguage(locale); updateLanguage(locale);
logger.debug(locale.getDisplayLanguage()); logger.debug(locale.getDisplayLanguage());
initialize(); initialize();
} }
/** /**
* Initialize the contents of the frame. * Initialize the contents of the frame.
* *
* @throws SibaException * @throws SibaException
*/ */
private void initialize() throws SibaException private void initialize() throws SibaException
{ {
this.frmSimpleBackup = new JFrame(); this.frmSimpleBackup = new JFrame();
this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit() this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit()
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png"))); .getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400)); this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN); this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBackground(Color.GREEN); tabbedPane.setBackground(Color.GREEN);
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER); this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
this.backupPanel = new BackupPanel(); this.backupPanel = new BackupPanel();
this.backupPanel.setBackground(new Color(0, 255, 0)); this.backupPanel.setBackground(new Color(0, 255, 0));
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleBackupPanel.text"), //$NON-NLS-1$ tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleBackupPanel.text"),
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.backupPanel, new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.backupPanel,
null); null);
this.checkPanel = new CheckPanel(); this.checkPanel = new CheckPanel();
this.checkPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.checkPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
this.checkPanel.setBackground(new Color(144, 238, 144)); this.checkPanel.setBackground(new Color(144, 238, 144));
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleCheckPanel.text"), //$NON-NLS-1$ tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleCheckPanel.text"),
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.checkPanel, new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.checkPanel,
null); null);
this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12)); this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
this.frmSimpleBackup.setForeground(new Color(0, 100, 0)); this.frmSimpleBackup.setForeground(new Color(0, 100, 0));
this.frmSimpleBackup.setBackground(new Color(102, 205, 170)); this.frmSimpleBackup.setBackground(new Color(102, 205, 170));
this.frmSimpleBackup.setTitle("Simple Backup"); this.frmSimpleBackup.setTitle("Simple Backup");
this.frmSimpleBackup.setBounds(100, 100, 450, 300); this.frmSimpleBackup.setBounds(100, 100, 450, 300);
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar(); JMenuBar menuBar = new JMenuBar();
menuBar.setBackground(Color.GREEN); menuBar.setBackground(Color.GREEN);
this.frmSimpleBackup.setJMenuBar(menuBar); this.frmSimpleBackup.setJMenuBar(menuBar);
JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text")); //$NON-NLS-1$ JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text"));
mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mnFile.setBackground(Color.GREEN); mnFile.setBackground(Color.GREEN);
mnFile.setMnemonic('F'); mnFile.setMnemonic('F');
mnFile.setForeground(Color.BLACK); mnFile.setForeground(Color.BLACK);
menuBar.add(mnFile); menuBar.add(mnFile);
JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text")); //$NON-NLS-1$ JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text"));
mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmBackup.setBackground(Color.GREEN); mntmBackup.setBackground(Color.GREEN);
mntmBackup.addActionListener(new ActionListener() mntmBackup.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
tabbedPane.setSelectedIndex(0); tabbedPane.setSelectedIndex(0);
File file = SourceDirectorySelector.showSelectorDialog(SibaGUI.this.backupPanel, null); File file = SourceDirectorySelector.showSelectorDialog(SibaGUI.this.backupPanel, null);
if (file != null) if (file != null)
{ {
SibaGUI.this.backupPanel.setSourceDirectory(file.getPath()); SibaGUI.this.backupPanel.setSourceDirectory(file.getPath());
} }
} }
}); });
mnFile.add(mntmBackup); mnFile.add(mntmBackup);
JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text")); //$NON-NLS-1$ JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text"));
mntmCheck.setBackground(Color.GREEN); mntmCheck.setBackground(Color.GREEN);
mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmCheck.addActionListener(new ActionListener() mntmCheck.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
tabbedPane.setSelectedIndex(1); tabbedPane.setSelectedIndex(1);
File choosenFile = CheckDirectorySelector.showSelectorDialog(SibaGUI.this.checkPanel, null); File choosenFile = CheckDirectorySelector.showSelectorDialog(SibaGUI.this.checkPanel, null);
if ((choosenFile != null) && choosenFile.exists()) if ((choosenFile != null) && choosenFile.exists())
{ {
SibaGUI.this.checkPanel.setFileToCheck(choosenFile.getAbsolutePath()); SibaGUI.this.checkPanel.setFileToCheck(choosenFile.getAbsolutePath());
} }
} }
}); });
mnFile.add(mntmCheck); mnFile.add(mntmCheck);
JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text")); //$NON-NLS-1$ JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text"));
mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmQuit.setBackground(Color.GREEN); mntmQuit.setBackground(Color.GREEN);
mntmQuit.setMnemonic(KeyEvent.VK_Q); mntmQuit.setMnemonic(KeyEvent.VK_Q);
mntmQuit.addActionListener(new ActionListener() mntmQuit.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent arg0) public void actionPerformed(final ActionEvent arg0)
{ {
SibaGUI.this.frmSimpleBackup.dispose(); SibaGUI.this.frmSimpleBackup.dispose();
} }
}); });
JSeparator separator = new JSeparator(); JSeparator separator = new JSeparator();
mnFile.add(separator); mnFile.add(separator);
mnFile.add(mntmQuit); mnFile.add(mntmQuit);
JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$ JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text"));
mnNewMenu.setMnemonic('H'); mnNewMenu.setMnemonic('H');
mnNewMenu.setLocation(new Point(500, 0)); mnNewMenu.setLocation(new Point(500, 0));
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT); mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT); mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mnNewMenu.setForeground(new Color(0, 0, 0)); mnNewMenu.setForeground(new Color(0, 0, 0));
mnNewMenu.setBackground(Color.GREEN); mnNewMenu.setBackground(Color.GREEN);
mnNewMenu.setOpaque(true); mnNewMenu.setOpaque(true);
menuBar.add(mnNewMenu); menuBar.add(mnNewMenu);
JMenuItem mntmMenuItemAbout = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$ JMenuItem mntmMenuItemAbout = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
mntmMenuItemAbout.setBackground(Color.GREEN); mntmMenuItemAbout.setBackground(Color.GREEN);
mntmMenuItemAbout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmMenuItemAbout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mntmMenuItemAbout.addActionListener(new ActionListener() mntmMenuItemAbout.addActionListener(new ActionListener()
{ {
@Override @Override
public void actionPerformed(final ActionEvent e) public void actionPerformed(final ActionEvent e)
{ {
AboutDialog dialog; AboutDialog dialog;
try try
{ {
dialog = new AboutDialog(); dialog = new AboutDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true); dialog.setVisible(true);
} }
catch (IOException exception) catch (IOException exception)
{ {
logger.error("Exception ", exception); logger.error("Exception ", exception);
} }
} }
}); });
mnNewMenu.add(mntmMenuItemAbout); mnNewMenu.add(mntmMenuItemAbout);
} }
/** /**
* This method launch the GUI. * This method launch the GUI.
*/ */
public static void run() public static void run()
{ {
EventQueue.invokeLater(new Runnable() EventQueue.invokeLater(new Runnable()
{ {
@Override @Override
public void run() public void run()
{ {
try try
{ {
SibaGUI window = new SibaGUI(); SibaGUI window = new SibaGUI();
window.frmSimpleBackup.setVisible(true); window.frmSimpleBackup.setVisible(true);
} }
catch (SibaException exception) catch (SibaException exception)
{ {
logger.error("SibaException ", exception); logger.error("SibaException ", exception);
String dataMissing = exception.getMessage(); String dataMissing = exception.getMessage();
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text"); String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
} }
catch (Exception exception) catch (Exception exception)
{ {
logger.error("Exception ", exception); logger.error("Exception ", exception);
} }
} }
}); });
} }
/** /**
* This method set the local language. * This method set the local language.
* *
* @param source * @param source
* locale * locale
*/ */
public static void updateLanguage(final Locale source) public static void updateLanguage(final Locale source)
{ {
// Change JVM default locale. // Change JVM default locale.
java.util.Locale.setDefault(source); java.util.Locale.setDefault(source);
// Change LookAndFeel default locale. // Change LookAndFeel default locale.
javax.swing.UIManager.getDefaults().setDefaultLocale(source); javax.swing.UIManager.getDefaults().setDefaultLocale(source);
// Change new component default locale. // Change new component default locale.
javax.swing.JComponent.setDefaultLocale(source); javax.swing.JComponent.setDefaultLocale(source);
// //
ResourceBundle.clearCache(); ResourceBundle.clearCache();
} }
} }

View File

@ -17,102 +17,102 @@ import org.slf4j.LoggerFactory;
*/ */
public class SourceDirectorySelector extends JFileChooser public class SourceDirectorySelector extends JFileChooser
{ {
private static final long serialVersionUID = 3782597353602048214L; private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static Logger logger = LoggerFactory.getLogger(SourceDirectorySelector.class); public static Logger logger = LoggerFactory.getLogger(SourceDirectorySelector.class);
/** /**
* *
* @param targetFile * @param targetFile
* target file * target file
*/ */
public SourceDirectorySelector(final File targetFile) public SourceDirectorySelector(final File targetFile)
{ {
super(); super();
setBackground(new Color(152, 251, 152)); setBackground(new Color(152, 251, 152));
// //
File file; File file;
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath()))) if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{ {
file = null; file = null;
} }
else if (targetFile.isFile()) else if (targetFile.isFile())
{ {
file = targetFile.getParentFile(); file = targetFile.getParentFile();
} }
else else
{ {
file = targetFile; file = targetFile;
} }
// //
setSelectedFile(file); setSelectedFile(file);
setDialogTitle(BUNDLE.getString("SourceDirectorySelector.this.dialogTitle")); //$NON-NLS-1$ setDialogTitle(BUNDLE.getString("SourceDirectorySelector.this.dialogTitle"));
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
setAcceptAllFileFilterUsed(false); setAcceptAllFileFilterUsed(false);
setApproveButtonText(BUNDLE.getString("BackupPanel.sourceFileChooserButton.text")); setApproveButtonText(BUNDLE.getString("BackupPanel.sourceFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG); setDialogType(CUSTOM_DIALOG);
} }
/** /**
* *
*/ */
@Override @Override
public final void setSelectedFile(final File file) public final void setSelectedFile(final File file)
{ {
// //
super.setSelectedFile(file); super.setSelectedFile(file);
logger.debug("==== SET SELECTED FILE================="); logger.debug("==== SET SELECTED FILE=================");
logger.debug("SELECED FILE {} ", file); logger.debug("SELECED FILE {} ", file);
} }
/** /**
* *
*/ */
@Override @Override
public void setVisible(final boolean visible) public void setVisible(final boolean visible)
{ {
// //
super.setVisible(visible); super.setVisible(visible);
if (!visible) if (!visible)
{ {
// //
resetChoosableFileFilters(); resetChoosableFileFilters();
} }
} }
/** /**
* This method is the main one of the selector. * This method is the main one of the selector.
* *
* @param parent * @param parent
* the parent's component * the parent's component
* @param targetFile * @param targetFile
* target file * target file
* @return the selected file * @return the selected file
*/ */
public static File showSelectorDialog(final Component parent, final File targetFile) public static File showSelectorDialog(final Component parent, final File targetFile)
{ {
File result; File result;
// //
SourceDirectorySelector selector = new SourceDirectorySelector(targetFile); SourceDirectorySelector selector = new SourceDirectorySelector(targetFile);
// //
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION) if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{ {
// //
result = selector.getSelectedFile(); result = selector.getSelectedFile();
} }
else else
{ {
// //
result = null; result = null;
} }
// //
return result; return result;
} }
} }

View File

@ -17,104 +17,104 @@ import org.slf4j.LoggerFactory;
*/ */
public class TargetDirectorySelector extends JFileChooser public class TargetDirectorySelector extends JFileChooser
{ {
private static final long serialVersionUID = 3782597353602048214L; private static final long serialVersionUID = 3782597353602048214L;
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static Logger logger = LoggerFactory.getLogger(TargetDirectorySelector.class); public static Logger logger = LoggerFactory.getLogger(TargetDirectorySelector.class);
/** /**
* *
* @param targetFile * @param targetFile
* target file * target file
*/ */
public TargetDirectorySelector(final File targetFile) public TargetDirectorySelector(final File targetFile)
{ {
super(); super();
setBackground(new Color(152, 251, 152)); setBackground(new Color(152, 251, 152));
// //
File file; File file;
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath()))) if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{ {
file = null; file = null;
} }
else if (targetFile.isFile()) else if (targetFile.isFile())
{ {
file = targetFile.getParentFile(); file = targetFile.getParentFile();
} }
else else
{ {
file = targetFile; file = targetFile;
} }
// //
setSelectedFile(file); setSelectedFile(file);
setDialogTitle(BUNDLE.getString("TargetDirectorySelector.this.dialogTitle")); //$NON-NLS-1$ setDialogTitle(BUNDLE.getString("TargetDirectorySelector.this.dialogTitle"));
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
setAcceptAllFileFilterUsed(false); setAcceptAllFileFilterUsed(false);
setApproveButtonText(BUNDLE.getString("BackupPanel.targetFileChooserButton.text")); setApproveButtonText(BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
setDialogType(CUSTOM_DIALOG); setDialogType(CUSTOM_DIALOG);
} }
/** /**
* *
*/ */
@Override @Override
public final void setSelectedFile(final File file) public final void setSelectedFile(final File file)
{ {
// //
super.setSelectedFile(file); super.setSelectedFile(file);
logger.debug("==== SET SELECTED FILE================="); logger.debug("==== SET SELECTED FILE=================");
logger.debug("SELECED FILE {} ", file); logger.debug("SELECED FILE {} ", file);
} }
/** /**
* *
*/ */
@Override @Override
public void setVisible(final boolean visible) public void setVisible(final boolean visible)
{ {
// //
super.setVisible(visible); super.setVisible(visible);
if (!visible) if (!visible)
{ {
// //
resetChoosableFileFilters(); resetChoosableFileFilters();
} }
} }
/** /**
* This method is the main one of the selector. * This method is the main one of the selector.
* *
* @param parent * @param parent
* the parent's component * the parent's component
* @param targetFile * @param targetFile
* target file * target file
* @return the selected file * @return the selected file
*/ */
public static File showSelectorDialog(final Component parent, final File targetFile) public static File showSelectorDialog(final Component parent, final File targetFile)
{ {
File result; File result;
// //
TargetDirectorySelector selector = new TargetDirectorySelector(targetFile); TargetDirectorySelector selector = new TargetDirectorySelector(targetFile);
// //
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION) if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{ {
// //
result = selector.getSelectedFile(); result = selector.getSelectedFile();
} }
else else
{ {
// //
result = null; result = null;
} }
// //
return result; return result;
} }
} }

View File

@ -32,27 +32,27 @@ import javax.swing.UIManager;
*/ */
public final class GUIToolBox public final class GUIToolBox
{ {
private GUIToolBox() private GUIToolBox()
{ {
} }
public static List<String> availableLookAndFeels() public static List<String> availableLookAndFeels()
{ {
List<String> result; List<String> result;
// //
result = new ArrayList<String>(); result = new ArrayList<String>();
// //
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{ {
// //
result.add(info.getName()); result.add(info.getName());
} }
// //
return result; return result;
} }
} }

View File

@ -42,132 +42,132 @@ import org.dclermonte.siba.SibaException;
*/ */
public final class SibaManager public final class SibaManager
{ {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.model.messages"); //$NON-NLS-1$ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.model.messages"); //$NON-NLS-1$
private SibaManager() private SibaManager()
{ {
} }
/** /**
* This method perform the backup. * This method perform the backup.
* *
* @param fileToSave * @param fileToSave
* name of the directory to save * name of the directory to save
* @return the archive of the file * @return the archive of the file
* @throws SibaException * @throws SibaException
* specific exception for Siba * specific exception for Siba
*/ */
public static File backup(final File fileToSave) throws SibaException public static File backup(final File fileToSave) throws SibaException
{ {
File result; File result;
File target = new File(System.getProperty("user.dir")); File target = new File(System.getProperty("user.dir"));
result = backup(fileToSave, target); result = backup(fileToSave, target);
// //
return result; return result;
} }
/** /**
* This method perform the backup. * This method performs the backup.
* *
* @param fileToSave * @param fileToSave
* name of the directory to save * name of the directory to save
* @param target * @param target
* directory for the file * directory for the file
* @return the archive of the file * @return the archive of the file
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public static File backup(final File fileToSave, final File target) throws SibaException public static File backup(final File fileToSave, final File target) throws SibaException
{ {
File result; File result;
TarArchiveOutputStream out = null; TarArchiveOutputStream out = null;
try try
{ {
if ((fileToSave == null) || !fileToSave.exists()) if ((fileToSave == null) || !fileToSave.exists())
{ {
throw new SibaException(BUNDLE.getString("sourceNotExist.text")); throw new SibaException(BUNDLE.getString("sourceNotExist.text"));
} }
else if (!fileToSave.isDirectory()) else if (!fileToSave.isDirectory())
{ {
throw new SibaException(BUNDLE.getString("NotDirectorySource.text")); throw new SibaException(BUNDLE.getString("NotDirectorySource.text"));
} }
else if (!target.isDirectory()) else if (!target.isDirectory())
{ {
throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text")); throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text"));
} }
else else
{ {
LocalDateTime date = LocalDateTime.now(); LocalDateTime date = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH'h'mm'mn'ss's'"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH'h'mm'mn'ss's'");
String textDate = date.format(formatter); String textDate = date.format(formatter);
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate; String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz"); result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
OutputStream gzipOutputStream = new GzipCompressorOutputStream( OutputStream gzipOutputStream = new GzipCompressorOutputStream(
new BufferedOutputStream(new FileOutputStream(result))); new BufferedOutputStream(new FileOutputStream(result)));
out = new TarArchiveOutputStream(gzipOutputStream); out = new TarArchiveOutputStream(gzipOutputStream);
SibaUtils.tarDirectoryTree(fileToSave, out); SibaUtils.tarDirectoryTree(fileToSave, out);
out.close(); out.close();
SibaUtils.createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5"); SibaUtils.createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
} }
} }
catch (IOException exception) catch (IOException exception)
{ {
throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), exception); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), exception); //$NON-NLS-1$
} }
catch (NoSuchAlgorithmException exception) catch (NoSuchAlgorithmException exception)
{ {
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$
} }
finally finally
{ {
IOUtils.closeQuietly(out); IOUtils.closeQuietly(out);
} }
// //
return result; return result;
} }
/** /**
* This method is used to check the file. * This method is used to check the file.
* *
* @param choosenFile * @param choosenFile
* the file to check * the file to check
* @return the result of check * @return the result of check
* @throws SibaException * @throws SibaException
* specific exception * specific exception
*/ */
public static boolean check(final File choosenFile) throws SibaException public static boolean check(final File choosenFile) throws SibaException
{ {
boolean result; boolean result;
try try
{ {
String md5String = SibaUtils.loadMD5Sum(choosenFile); String md5String = SibaUtils.loadMD5Sum(choosenFile);
File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile); File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile);
if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1))) if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1)))
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
} }
catch (IOException exception) catch (IOException exception)
{ {
throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), exception); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), exception);
} }
catch (NoSuchAlgorithmException exception) catch (NoSuchAlgorithmException exception)
{ {
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$ throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception);
} }
// //
return result; return result;
} }
} }

View File

@ -40,288 +40,290 @@ import org.apache.commons.io.IOUtils;
*/ */
public final class SibaUtils public final class SibaUtils
{ {
static final String DEFAULT_CHARSET = "UTF-8"; static final String DEFAULT_CHARSET = "UTF-8";
private SibaUtils() private SibaUtils()
{ {
} }
/** /**
* *
* This method Generate the file with MD5. * This method Generate the file with MD5.
* *
* @param inputFile * @param inputFile
* the file on which the md5 is calculate * the file on which the md5 is calculate
* @param target * @param target
* the MD5 file * the MD5 file
* @return the MD5 file * @return the MD5 file
* @throws IOException * @throws IOException
* IOException * IOException
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
* NoSuchAlgorithmException * NoSuchAlgorithmException
*/ */
public static File createMD5File(final File inputFile, final String target) public static File createMD5File(final File inputFile, final String target)
throws IOException, NoSuchAlgorithmException throws IOException, NoSuchAlgorithmException
{ {
File result; File result;
String md5 = SibaUtils.md5(inputFile); String md5 = SibaUtils.md5(inputFile);
String fileName = inputFile.getName(); String fileName = inputFile.getName();
result = createMD5File(md5, fileName, target); result = createMD5File(md5, fileName, target);
// //
return result; return result;
} }
/** /**
* *
* @param md5 * @param md5
* Hash MD5 * Hash MD5
* @param fileName * @param fileName
* The name of the file * The name of the file
* @param target * @param target
* directory to put the file * directory to put the file
* @return The MD5 file * @return The MD5 file
* @throws IOException * @throws IOException
* IOexception * IOexception
*/ */
public static File createMD5File(final String md5, final String fileName, final String target) throws IOException public static File createMD5File(final String md5, final String fileName, final String target) throws IOException
{ {
File result; File result;
FileWriter out = null; FileWriter out = null;
try try
{ {
result = new File(target); result = new File(target);
out = new FileWriter(result); out = new FileWriter(result);
out.write(md5); out.write(md5);
String newLine = System.getProperty("line.separator"); String newLine = System.getProperty("line.separator");
out.append(" "); out.append(" ");
out.append(fileName); out.append(fileName);
out.append(newLine); out.append(newLine);
out.close(); out.close();
} }
finally finally
{ {
IOUtils.closeQuietly(out); IOUtils.closeQuietly(out);
} }
// //
return result; return result;
} }
/** /**
* *
* @param choosenFile * @param choosenFile
* the file to check * the file to check
* @return The MD5sum * @return The MD5sum
* @throws IOException * @throws IOException
* IOException * IOException
*/ */
public static String loadMD5Sum(final File choosenFile) throws IOException public static String loadMD5Sum(final File choosenFile) throws IOException
{ {
String result; String result;
FileReader in = null; FileReader in = null;
try try
{ {
if (choosenFile.exists() && (choosenFile.length() > 32)) if (choosenFile.exists() && (choosenFile.length() > 32))
{ {
in = new FileReader(choosenFile); in = new FileReader(choosenFile);
BufferedReader bufferedReader = new BufferedReader(in); BufferedReader bufferedReader = new BufferedReader(in);
String line = bufferedReader.readLine(); String line = bufferedReader.readLine();
result = line.substring(0, 32); result = line.substring(0, 32);
in.close(); in.close();
} }
else else
{ {
result = ""; result = "";
} }
} }
finally finally
{ {
IOUtils.closeQuietly(in); IOUtils.closeQuietly(in);
} }
// //
return result; return result;
} }
/** /**
* This method calculate the MD5 itself. * This method calculate the MD5 itself.
* *
* @param input * @param input
* The name of the file for witch the MD5 sum is to calculate * The name of the file for witch the MD5 sum is to calculate
* @return The MD5Sum * @return The MD5Sum
* @throws IOException * @throws IOException
* IOException * IOException
* @throws NoSuchAlgorithmException * @throws NoSuchAlgorithmException
* NoSuchAlgorithmException * NoSuchAlgorithmException
*/ */
public static String md5(final File input) throws IOException, NoSuchAlgorithmException public static String md5(final File input) throws IOException, NoSuchAlgorithmException
{ {
String result; String result;
StringBuilder hashString = new StringBuilder(); StringBuilder hashString = new StringBuilder();
FileInputStream fileInputStream = null; FileInputStream fileInputStream = null;
try try
{ {
byte[] byteInput = new byte[(int) input.length()]; byte[] byteInput = new byte[(int) input.length()];
fileInputStream = new FileInputStream(input); fileInputStream = new FileInputStream(input);
for (int index1 = 0; index1 < input.length(); index1++) for (int index1 = 0; index1 < input.length(); index1++)
{ {
byteInput[index1] = (byte) fileInputStream.read(); byteInput[index1] = (byte) fileInputStream.read();
} }
byte[] hash = null; byte[] hash = null;
MessageDigest messageDigest = MessageDigest.getInstance("MD5"); MessageDigest messageDigest = MessageDigest.getInstance("MD5");
hash = messageDigest.digest(byteInput); hash = messageDigest.digest(byteInput);
for (int index = 0; index < hash.length; index++) for (int index = 0; index < hash.length; index++)
{ {
String hex = Integer.toHexString(hash[index]); String hex = Integer.toHexString(hash[index]);
if (hex.length() == 1) if (hex.length() == 1)
{ {
hashString.append('0'); hashString.append('0');
hashString.append(hex.charAt(hex.length() - 1)); hashString.append(hex.charAt(hex.length() - 1));
} }
else else
{ {
hashString.append(hex.substring(hex.length() - 2)); hashString.append(hex.substring(hex.length() - 2));
} }
} }
fileInputStream.close(); fileInputStream.close();
result = hashString.toString(); result = hashString.toString();
} }
finally finally
{ {
IOUtils.closeQuietly(fileInputStream); IOUtils.closeQuietly(fileInputStream);
} }
// //
return result; return result;
} }
/** /**
* *
* @param choosenFile * @param choosenFile
* The MD5file * The MD5file
* @return the file to check * @return the file to check
* @throws IOException * @throws IOException
* IOException * IOException
*/ */
public static File readFileNameToCheck(final File choosenFile) throws IOException public static File readFileNameToCheck(final File choosenFile) throws IOException
{ {
File result; File result;
FileReader in = null;
try
{
if (choosenFile.exists() && (choosenFile.length() > 32))
{
in = new FileReader(choosenFile);
BufferedReader bufferedReader = new BufferedReader(in);
String line = bufferedReader.readLine();
String fileNameToString;
fileNameToString = line.substring(33);
in.close();
if (choosenFile.isAbsolute())
{
result = new File(choosenFile.getParent() + "/" + fileNameToString);
}
else
{
String path = System.getProperty("user.dir");
result = new File(path + "/" + fileNameToString);
}
}
else
{
result = null;
}
}
finally
{
IOUtils.closeQuietly(in);
}
//
return result;
}
/** FileReader in = null;
* try
* @param resource {
* the resource to read if (choosenFile.exists() && (choosenFile.length() > 32))
* @return the string of the resource {
* @throws IOException in = new FileReader(choosenFile);
* IOException BufferedReader bufferedReader = new BufferedReader(in);
*/ String line = bufferedReader.readLine();
public static String readResource(final String resource) throws IOException String fileNameToString;
{ fileNameToString = line.substring(33);
String result; in.close();
if (choosenFile.isAbsolute())
{
result = new File(choosenFile.getParent() + "/" + fileNameToString);
}
else
{
String path = System.getProperty("user.dir");
result = new File(path + "/" + fileNameToString);
}
}
else
{
result = null;
}
}
finally
{
IOUtils.closeQuietly(in);
}
URL url = SibaUtils.class.getResource(resource); //
result = IOUtils.toString(url, DEFAULT_CHARSET); return result;
}
return result; /**
} *
* @param resource
* the resource to read
* @return the string of the resource
* @throws IOException
* IOException
*/
public static String readResource(final String resource) throws IOException
{
String result;
/** URL url = SibaUtils.class.getResource(resource);
* result = IOUtils.toString(url, DEFAULT_CHARSET);
* @param fileToSave
* The directory to backup
* @param outputStream
* local Stream
* @throws IOException
* IOException
*/
public static void tarDirectoryTree(final File fileToSave, final TarArchiveOutputStream outputStream)
throws IOException
{
int pathLength = fileToSave.getParentFile().getAbsolutePath().length();
tarDirectoryTree(fileToSave, outputStream, pathLength);
}
/** return result;
* }
* This method generates ArchiveEntry.
*
* @param directory
* The actual directory being archived
* @param outputStream
* local stream
* @param pathLength
* used to select the starting directory
* @throws IOException
* IOException
*/
public static void tarDirectoryTree(final File directory, final TarArchiveOutputStream outputStream,
final int pathLength) throws IOException
{
for (File file : directory.listFiles())
{
if (file.isDirectory())
{
if (file.listFiles().length == 0)
{
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength);
tarArchiveEntry.setName(pathPartiel);
outputStream.putArchiveEntry(tarArchiveEntry);
outputStream.closeArchiveEntry();
}
else
{
tarDirectoryTree(file, outputStream, pathLength);
}
}
else
{
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength);
tarArchiveEntry.setName(pathPartiel);
outputStream.putArchiveEntry(tarArchiveEntry);
IOUtils.copy(new FileInputStream(file), outputStream);
outputStream.closeArchiveEntry();
} /**
} *
} * @param fileToSave
* The directory to backup
* @param outputStream
* local Stream
* @throws IOException
* IOException
*/
public static void tarDirectoryTree(final File fileToSave, final TarArchiveOutputStream outputStream)
throws IOException
{
int pathLength = fileToSave.getParentFile().getAbsolutePath().length();
tarDirectoryTree(fileToSave, outputStream, pathLength);
}
/**
*
* This method generates ArchiveEntry.
*
* @param directory
* The actual directory being archived
* @param outputStream
* local stream
* @param pathLength
* used to select the starting directory
* @throws IOException
* IOException
*/
public static void tarDirectoryTree(final File directory, final TarArchiveOutputStream outputStream,
final int pathLength) throws IOException
{
for (File file : directory.listFiles())
{
if (file.isDirectory())
{
if (file.listFiles().length == 0)
{
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength);
tarArchiveEntry.setName(pathPartiel);
outputStream.putArchiveEntry(tarArchiveEntry);
outputStream.closeArchiveEntry();
}
else
{
tarDirectoryTree(file, outputStream, pathLength);
}
}
else
{
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength);
tarArchiveEntry.setName(pathPartiel);
outputStream.putArchiveEntry(tarArchiveEntry);
IOUtils.copy(new FileInputStream(file), outputStream);
outputStream.closeArchiveEntry();
}
}
}
} }