Replace tab by space and remove trailing comment
This commit is contained in:
parent
8bc116734c
commit
ee8abfbca8
@ -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.enabling_tag=@formatter\:on
|
||||
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_enum_constant_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_empty_lines_to_preserve=1
|
||||
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.use_on_off_tags=false
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
|
||||
|
@ -35,43 +35,43 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
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
|
||||
* arguments
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
// Configure log.
|
||||
File loggerConfig = new File("log4j.properties");
|
||||
if (loggerConfig.exists())
|
||||
{
|
||||
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
|
||||
logger.info("Dedicated log configuration done.");
|
||||
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
BasicConfigurator.configure();
|
||||
logger.info("Basic log configuration done.");
|
||||
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
* arguments
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
// Configure log.
|
||||
File loggerConfig = new File("log4j.properties");
|
||||
if (loggerConfig.exists())
|
||||
{
|
||||
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
|
||||
logger.info("Dedicated log configuration done.");
|
||||
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
BasicConfigurator.configure();
|
||||
logger.info("Basic log configuration done.");
|
||||
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
|
||||
}
|
||||
|
||||
// Run.
|
||||
if (args.length == 0)
|
||||
{
|
||||
SibaGUI.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
SibaCLI.run(args);
|
||||
}
|
||||
}
|
||||
// Run.
|
||||
if (args.length == 0)
|
||||
{
|
||||
SibaGUI.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
SibaCLI.run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,45 +27,45 @@ package org.dclermonte.siba;
|
||||
*/
|
||||
public class SibaException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 2909630770291570845L;
|
||||
private static final long serialVersionUID = 2909630770291570845L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SibaException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public SibaException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* error message
|
||||
*/
|
||||
public SibaException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* error message
|
||||
*/
|
||||
public SibaException(final String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* text
|
||||
* @param cause
|
||||
* caused by…
|
||||
*/
|
||||
public SibaException(final String message, final Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* text
|
||||
* @param cause
|
||||
* caused by…
|
||||
*/
|
||||
public SibaException(final String message, final Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cause
|
||||
* caused by …
|
||||
*/
|
||||
public SibaException(final Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param cause
|
||||
* caused by …
|
||||
*/
|
||||
public SibaException(final Throwable cause)
|
||||
{
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -37,191 +37,191 @@ import fr.devinsy.util.strings.StringList;
|
||||
*/
|
||||
public final class SibaCLI
|
||||
{
|
||||
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 Logger logger = LoggerFactory.getLogger(SibaCLI.class);
|
||||
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
|
||||
{
|
||||
File result;
|
||||
result = SibaManager.backup(directoryToSave);
|
||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
||||
}
|
||||
public static void backup(final File directoryToSave) throws SibaException
|
||||
{
|
||||
File result;
|
||||
result = SibaManager.backup(directoryToSave);
|
||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is called for Backup from CLI.
|
||||
*
|
||||
* @param directoryToSave
|
||||
* The directory to save
|
||||
* @param targetDirectory
|
||||
* where to put the generated file
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static void backup(final File directoryToSave, final File targetDirectory) throws SibaException
|
||||
{
|
||||
File result;
|
||||
result = SibaManager.backup(directoryToSave, targetDirectory);
|
||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method is called for Backup from CLI.
|
||||
*
|
||||
* @param directoryToSave
|
||||
* The directory to save
|
||||
* @param targetDirectory
|
||||
* where to put the generated file
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static void backup(final File directoryToSave, final File targetDirectory) throws SibaException
|
||||
{
|
||||
File result;
|
||||
result = SibaManager.backup(directoryToSave, targetDirectory);
|
||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is called for Check from CLI. anObject
|
||||
*
|
||||
* @param fileToCheck
|
||||
* The file to be check
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static void check(final File fileToCheck) throws SibaException
|
||||
{
|
||||
boolean result;
|
||||
result = SibaManager.check(fileToCheck);
|
||||
if (result)
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("confirmDialogGood.text"), fileToCheck.getName());
|
||||
System.out.println(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("confirmDialogBad.text"), fileToCheck.getName());
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method is called for Check from CLI. anObject
|
||||
*
|
||||
* @param fileToCheck
|
||||
* The file to be check
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static void check(final File fileToCheck) throws SibaException
|
||||
{
|
||||
boolean result;
|
||||
result = SibaManager.check(fileToCheck);
|
||||
if (result)
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("confirmDialogGood.text"), fileToCheck.getName());
|
||||
System.out.println(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("confirmDialogBad.text"), fileToCheck.getName());
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method send help response.
|
||||
*
|
||||
*/
|
||||
public static void help()
|
||||
{
|
||||
StringList message = new StringList();
|
||||
/**
|
||||
* This method send help response.
|
||||
*
|
||||
*/
|
||||
public static void help()
|
||||
{
|
||||
StringList message = new StringList();
|
||||
|
||||
message.appendln("Usage:");
|
||||
message.appendln(" siba [ -h | -help | --help ]");
|
||||
message.appendln(" siba backup directoryToSave [ target ]");
|
||||
message.appendln(" siba check [ filename | filename.tgz | filename.tgz.md5 ]");
|
||||
message.appendln("Usage:");
|
||||
message.appendln(" siba [ -h | -help | --help ]");
|
||||
message.appendln(" siba backup directoryToSave [ target ]");
|
||||
message.appendln(" siba check [ filename | filename.tgz | filename.tgz.md5 ]");
|
||||
|
||||
System.out.println(message.toString());
|
||||
}
|
||||
System.out.println(message.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void manageSibaCLIException()
|
||||
{
|
||||
// Set default CLI catch.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||
{
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable exception)
|
||||
{
|
||||
String message;
|
||||
if (exception instanceof OutOfMemoryError)
|
||||
{
|
||||
message = "Java ran out of memory!\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void manageSibaCLIException()
|
||||
{
|
||||
// Set default CLI catch.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||
{
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable exception)
|
||||
{
|
||||
String message;
|
||||
if (exception instanceof OutOfMemoryError)
|
||||
{
|
||||
message = "Java ran out of memory!\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
|
||||
}
|
||||
|
||||
logger.error("uncaughtException ", exception);
|
||||
logger.error(message);
|
||||
logger.info(BUNDLE.getString("UnexpectedError.text"));
|
||||
}
|
||||
});
|
||||
}
|
||||
logger.error("uncaughtException ", exception);
|
||||
logger.error(message);
|
||||
logger.info(BUNDLE.getString("UnexpectedError.text"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method launch CLI.
|
||||
*
|
||||
* @param args
|
||||
* necessary arguments
|
||||
*/
|
||||
public static void run(final String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
manageSibaCLIException();
|
||||
// This part implements an automate.
|
||||
int parameterCount = args.length;
|
||||
if (parameterCount == 0)
|
||||
{
|
||||
help();
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "-h") || StringUtils.equals(args[0], "-help")
|
||||
|| StringUtils.equals(args[0], "--help"))
|
||||
{
|
||||
help();
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "backup"))
|
||||
{
|
||||
if (parameterCount == 1)
|
||||
{
|
||||
backup(null, null);
|
||||
}
|
||||
else if (parameterCount == 2)
|
||||
{
|
||||
backup(new File(args[1]));
|
||||
}
|
||||
else if (parameterCount == 3)
|
||||
{
|
||||
backup(new File(args[1]), new File(args[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "check"))
|
||||
{
|
||||
if (parameterCount == 1)
|
||||
{
|
||||
check(null);
|
||||
}
|
||||
else if (parameterCount == 2)
|
||||
{
|
||||
String fileToCheckName;
|
||||
if (!args[1].endsWith("tgz") && !args[1].endsWith("md5"))
|
||||
{
|
||||
fileToCheckName = args[1].concat(".tgz.md5");
|
||||
}
|
||||
else if (args[1].endsWith("tgz"))
|
||||
{
|
||||
fileToCheckName = args[1].concat(".md5");
|
||||
}
|
||||
else
|
||||
{
|
||||
fileToCheckName = args[1];
|
||||
}
|
||||
File fileToCheck = new File(fileToCheckName);
|
||||
check(fileToCheck);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(BUNDLE.getString("badUsage.text"));
|
||||
help();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* This method launch CLI.
|
||||
*
|
||||
* @param args
|
||||
* necessary arguments
|
||||
*/
|
||||
public static void run(final String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
manageSibaCLIException();
|
||||
// This part implements an automate.
|
||||
int parameterCount = args.length;
|
||||
if (parameterCount == 0)
|
||||
{
|
||||
help();
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "-h") || StringUtils.equals(args[0], "-help")
|
||||
|| StringUtils.equals(args[0], "--help"))
|
||||
{
|
||||
help();
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "backup"))
|
||||
{
|
||||
if (parameterCount == 1)
|
||||
{
|
||||
backup(null, null);
|
||||
}
|
||||
else if (parameterCount == 2)
|
||||
{
|
||||
backup(new File(args[1]));
|
||||
}
|
||||
else if (parameterCount == 3)
|
||||
{
|
||||
backup(new File(args[1]), new File(args[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ToManyParameter.text"));
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equals(args[0], "check"))
|
||||
{
|
||||
if (parameterCount == 1)
|
||||
{
|
||||
check(null);
|
||||
}
|
||||
else if (parameterCount == 2)
|
||||
{
|
||||
String fileToCheckName;
|
||||
if (!args[1].endsWith("tgz") && !args[1].endsWith("md5"))
|
||||
{
|
||||
fileToCheckName = args[1].concat(".tgz.md5");
|
||||
}
|
||||
else if (args[1].endsWith("tgz"))
|
||||
{
|
||||
fileToCheckName = args[1].concat(".md5");
|
||||
}
|
||||
else
|
||||
{
|
||||
fileToCheckName = args[1];
|
||||
}
|
||||
File fileToCheck = new File(fileToCheckName);
|
||||
check(fileToCheck);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ToManyParameter.text"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(BUNDLE.getString("badUsage.text"));
|
||||
help();
|
||||
}
|
||||
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
System.err.println("SibaException = " + exception.getMessage());
|
||||
logger.error(exception.getMessage(), exception);
|
||||
help();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
System.err.println("SibaException = " + exception.getMessage());
|
||||
logger.error(exception.getMessage(), exception);
|
||||
help();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,86 +49,86 @@ import org.dclermonte.siba.model.SibaUtils;
|
||||
*/
|
||||
public class AboutDialog extends JDialog
|
||||
{
|
||||
private static final long serialVersionUID = 8868109575782482455L;
|
||||
private static final long serialVersionUID = 8868109575782482455L;
|
||||
|
||||
/**
|
||||
* This is the constructor for the dialog.
|
||||
*
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public AboutDialog() throws IOException
|
||||
{
|
||||
/**
|
||||
* This is the constructor for the dialog.
|
||||
*
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public AboutDialog() throws IOException
|
||||
{
|
||||
|
||||
setMinimumSize(new Dimension(600, 350));
|
||||
setMaximumSize(new Dimension(600, 500));
|
||||
setIconImage(Toolkit.getDefaultToolkit()
|
||||
.getImage(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
|
||||
setBackground(Color.GREEN);
|
||||
getContentPane().setBackground(Color.GREEN);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setBackground(Color.GREEN);
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.setFocusTraversalKeysEnabled(false);
|
||||
okButton.setFocusPainted(false);
|
||||
okButton.setBackground(new Color(0, 128, 0));
|
||||
okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
okButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonPane.add(horizontalGlue);
|
||||
}
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonPane.add(horizontalGlue);
|
||||
}
|
||||
}
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(Color.GREEN);
|
||||
getContentPane().add(panel, BorderLayout.CENTER);
|
||||
panel.setLayout(new BorderLayout(0, 0));
|
||||
setMinimumSize(new Dimension(600, 350));
|
||||
setMaximumSize(new Dimension(600, 500));
|
||||
setIconImage(Toolkit.getDefaultToolkit()
|
||||
.getImage(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
|
||||
setBackground(Color.GREEN);
|
||||
getContentPane().setBackground(Color.GREEN);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setBackground(Color.GREEN);
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.setFocusTraversalKeysEnabled(false);
|
||||
okButton.setFocusPainted(false);
|
||||
okButton.setBackground(new Color(0, 128, 0));
|
||||
okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
okButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonPane.add(horizontalGlue);
|
||||
}
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonPane.add(horizontalGlue);
|
||||
}
|
||||
}
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(Color.GREEN);
|
||||
getContentPane().add(panel, BorderLayout.CENTER);
|
||||
panel.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JTextPane txtpnSimpleBackupDveloppeur = new JTextPane();
|
||||
txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN);
|
||||
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
|
||||
txtpnSimpleBackupDveloppeur.setContentType("text/html");
|
||||
String resource;
|
||||
String locale = Locale.getDefault().toString();
|
||||
if (locale.equals("fr_FR"))
|
||||
{
|
||||
resource = "/org/dclermonte/siba/gui/about_fr.html";
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = "/org/dclermonte/siba/gui/about_en.html";
|
||||
}
|
||||
txtpnSimpleBackupDveloppeur.setText(SibaUtils.readResource(resource));
|
||||
panel.add(txtpnSimpleBackupDveloppeur);
|
||||
{
|
||||
JLabel lblNewLabel = new JLabel("");
|
||||
lblNewLabel
|
||||
.setIcon(new ImageIcon(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo_256.png")));
|
||||
panel.add(lblNewLabel, BorderLayout.WEST);
|
||||
}
|
||||
JTextPane txtpnSimpleBackupDveloppeur = new JTextPane();
|
||||
txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN);
|
||||
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
|
||||
txtpnSimpleBackupDveloppeur.setContentType("text/html");
|
||||
String resource;
|
||||
String locale = Locale.getDefault().toString();
|
||||
if (locale.equals("fr_FR"))
|
||||
{
|
||||
resource = "/org/dclermonte/siba/gui/about_fr.html";
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = "/org/dclermonte/siba/gui/about_en.html";
|
||||
}
|
||||
txtpnSimpleBackupDveloppeur.setText(SibaUtils.readResource(resource));
|
||||
panel.add(txtpnSimpleBackupDveloppeur);
|
||||
{
|
||||
JLabel lblNewLabel = new JLabel("");
|
||||
lblNewLabel
|
||||
.setIcon(new ImageIcon(AboutDialog.class.getResource("/org/dclermonte/siba/gui/SibaLogo_256.png")));
|
||||
panel.add(lblNewLabel, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,167 +53,167 @@ import com.jgoodies.forms.layout.RowSpec;
|
||||
*/
|
||||
public class BackupPanel extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = 4714383090458639282L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
private JTextField sourceDirectoryField;
|
||||
private JTextField targetDirectoryField;
|
||||
private static final long serialVersionUID = 4714383090458639282L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
private JTextField sourceDirectoryField;
|
||||
private JTextField targetDirectoryField;
|
||||
|
||||
/**
|
||||
* This is the constructor for this panel.
|
||||
*
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public BackupPanel() throws SibaException
|
||||
{
|
||||
/**
|
||||
* This is the constructor for this panel.
|
||||
*
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public BackupPanel() throws SibaException
|
||||
{
|
||||
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel helpPanel = new JPanel();
|
||||
add(helpPanel, BorderLayout.NORTH);
|
||||
JPanel helpPanel = new JPanel();
|
||||
add(helpPanel, BorderLayout.NORTH);
|
||||
|
||||
JLabel lblHelp = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text")); //$NON-NLS-1$
|
||||
helpPanel.add(lblHelp);
|
||||
JLabel lblHelp = new JLabel(BUNDLE.getString("BackupPanel.lblNewLabel_2.text"));
|
||||
helpPanel.add(lblHelp);
|
||||
|
||||
JPanel choosePanel = new JPanel();
|
||||
add(choosePanel);
|
||||
choosePanel.setLayout(new FormLayout(
|
||||
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
|
||||
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
|
||||
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
|
||||
new RowSpec[] { FormSpecs.RELATED_GAP_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, }));
|
||||
JPanel choosePanel = new JPanel();
|
||||
add(choosePanel);
|
||||
choosePanel.setLayout(new FormLayout(
|
||||
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
|
||||
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
|
||||
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
|
||||
new RowSpec[] { FormSpecs.RELATED_GAP_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$
|
||||
choosePanel.add(lblSourceDirectory, "2, 2");
|
||||
lblSourceDirectory.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblSourceDirectory.setVerticalAlignment(SwingConstants.TOP);
|
||||
JLabel lblSourceDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblSourceDirectory.text"));
|
||||
choosePanel.add(lblSourceDirectory, "2, 2");
|
||||
lblSourceDirectory.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
lblSourceDirectory.setVerticalAlignment(SwingConstants.TOP);
|
||||
|
||||
this.sourceDirectoryField = new JTextField();
|
||||
choosePanel.add(this.sourceDirectoryField, "4, 2");
|
||||
this.sourceDirectoryField.setColumns(10);
|
||||
this.sourceDirectoryField = new JTextField();
|
||||
choosePanel.add(this.sourceDirectoryField, "4, 2");
|
||||
this.sourceDirectoryField.setColumns(10);
|
||||
|
||||
JButton btnSourceDirectory = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text")); //$NON-NLS-1$
|
||||
btnSourceDirectory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
btnSourceDirectory.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
File file = SourceDirectorySelector.showSelectorDialog(BackupPanel.this, null);
|
||||
if (file != null)
|
||||
{
|
||||
BackupPanel.this.sourceDirectoryField.setText(file.getPath());
|
||||
}
|
||||
JButton btnSourceDirectory = new JButton(BUNDLE.getString("BackupPanel.btnNewButton.text"));
|
||||
btnSourceDirectory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
btnSourceDirectory.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
File file = SourceDirectorySelector.showSelectorDialog(BackupPanel.this, null);
|
||||
if (file != null)
|
||||
{
|
||||
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$
|
||||
choosePanel.add(lblTargetDirectory, "2, 4");
|
||||
lblTargetDirectory.setVerticalAlignment(SwingConstants.TOP);
|
||||
lblTargetDirectory.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
JLabel lblTargetDirectory = new JLabel(BUNDLE.getString("BackupPanel.lblTargetDirectory.text"));
|
||||
choosePanel.add(lblTargetDirectory, "2, 4");
|
||||
lblTargetDirectory.setVerticalAlignment(SwingConstants.TOP);
|
||||
lblTargetDirectory.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
|
||||
this.targetDirectoryField = new JTextField();
|
||||
choosePanel.add(this.targetDirectoryField, "4, 4");
|
||||
this.targetDirectoryField.setColumns(10);
|
||||
this.targetDirectoryField = new JTextField();
|
||||
choosePanel.add(this.targetDirectoryField, "4, 4");
|
||||
this.targetDirectoryField.setColumns(10);
|
||||
|
||||
JButton btnTarget = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text")); //$NON-NLS-1$
|
||||
btnTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
btnTarget.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
JButton btnTarget = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_1.text"));
|
||||
btnTarget.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
btnTarget.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
|
||||
File file = TargetDirectorySelector.showSelectorDialog(BackupPanel.this, null);
|
||||
if (file != null)
|
||||
{
|
||||
BackupPanel.this.targetDirectoryField.setText(file.getPath());
|
||||
}
|
||||
File file = TargetDirectorySelector.showSelectorDialog(BackupPanel.this, null);
|
||||
if (file != null)
|
||||
{
|
||||
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);
|
||||
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
|
||||
add(actionPanel, BorderLayout.SOUTH);
|
||||
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
Component verticalStrut1 = Box.createVerticalStrut(5);
|
||||
actionPanel.add(verticalStrut1);
|
||||
Component verticalStrut1 = Box.createVerticalStrut(5);
|
||||
actionPanel.add(verticalStrut1);
|
||||
|
||||
JPanel buttonActionPanel = new JPanel();
|
||||
actionPanel.add(buttonActionPanel);
|
||||
buttonActionPanel.setLayout(new BoxLayout(buttonActionPanel, BoxLayout.X_AXIS));
|
||||
JPanel buttonActionPanel = new JPanel();
|
||||
actionPanel.add(buttonActionPanel);
|
||||
buttonActionPanel.setLayout(new BoxLayout(buttonActionPanel, BoxLayout.X_AXIS));
|
||||
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonActionPanel.add(horizontalGlue);
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
buttonActionPanel.add(horizontalGlue);
|
||||
|
||||
JButton btnBackup = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text")); //$NON-NLS-1$
|
||||
btnBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
buttonActionPanel.add(btnBackup);
|
||||
JButton btnBackup = new JButton(BUNDLE.getString("BackupPanel.btnNewButton_2.text"));
|
||||
btnBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
buttonActionPanel.add(btnBackup);
|
||||
|
||||
Component horizontalGlue1 = Box.createHorizontalGlue();
|
||||
buttonActionPanel.add(horizontalGlue1);
|
||||
Component horizontalGlue1 = Box.createHorizontalGlue();
|
||||
buttonActionPanel.add(horizontalGlue1);
|
||||
|
||||
Component verticalStrut = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut);
|
||||
btnBackup.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
File directoryToSave1 = new File(BackupPanel.this.sourceDirectoryField.getText());
|
||||
File targetDirectory = new File(BackupPanel.this.targetDirectoryField.getText());
|
||||
if (directoryToSave1.exists() && targetDirectory.exists())
|
||||
{
|
||||
File output1 = SibaManager.backup(directoryToSave1, targetDirectory);
|
||||
Component verticalStrut = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut);
|
||||
btnBackup.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
File directoryToSave1 = new File(BackupPanel.this.sourceDirectoryField.getText());
|
||||
File targetDirectory = new File(BackupPanel.this.targetDirectoryField.getText());
|
||||
if (directoryToSave1.exists() && targetDirectory.exists())
|
||||
{
|
||||
File output1 = SibaManager.backup(directoryToSave1, targetDirectory);
|
||||
|
||||
String message = BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + output1.getName();
|
||||
String titre = BUNDLE.getString("BackupPanel.confirmDialogTitle.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
String message = BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + output1.getName();
|
||||
String titre = BUNDLE.getString("BackupPanel.confirmDialogTitle.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
}
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
String dataMissing = exception.getMessage();
|
||||
}
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
String dataMissing = exception.getMessage();
|
||||
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(BackupPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sourceDirectory
|
||||
* the source Directory
|
||||
*/
|
||||
public void setSourceDirectory(final String sourceDirectory)
|
||||
{
|
||||
this.sourceDirectoryField.setText(sourceDirectory);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param sourceDirectory
|
||||
* the source Directory
|
||||
*/
|
||||
public void setSourceDirectory(final String sourceDirectory)
|
||||
{
|
||||
this.sourceDirectoryField.setText(sourceDirectory);
|
||||
}
|
||||
}
|
||||
|
@ -19,103 +19,103 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class CheckDirectorySelector extends JFileChooser
|
||||
{
|
||||
private static final long serialVersionUID = 3782597353602048214L;
|
||||
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 final long serialVersionUID = 3782597353602048214L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
private static Logger logger = LoggerFactory.getLogger(CheckDirectorySelector.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public CheckDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public CheckDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
|
||||
setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5");
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
addChoosableFileFilter(filter);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.checkFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("CheckDirectorySelector.this.dialogTitle"));
|
||||
setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fichiers md5", "md5");
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
addChoosableFileFilter(filter);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.checkFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {}", file);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {}", file);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* The parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* The parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
|
||||
//
|
||||
CheckDirectorySelector selector = new CheckDirectorySelector(targetFile);
|
||||
//
|
||||
CheckDirectorySelector selector = new CheckDirectorySelector(targetFile);
|
||||
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
@ -55,125 +55,125 @@ import com.jgoodies.forms.layout.RowSpec;
|
||||
|
||||
public class CheckPanel extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = 4495957907349664847L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(CheckPanel.class);
|
||||
private JTextField fileToCheckField;
|
||||
private static final long serialVersionUID = 4495957907349664847L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(CheckPanel.class);
|
||||
private JTextField fileToCheckField;
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public CheckPanel() throws SibaException
|
||||
{
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
/**
|
||||
*
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public CheckPanel() throws SibaException
|
||||
{
|
||||
setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel choosePanel = new JPanel();
|
||||
add(choosePanel, BorderLayout.CENTER);
|
||||
choosePanel.setLayout(new FormLayout(
|
||||
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
|
||||
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
|
||||
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
|
||||
new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
|
||||
JPanel choosePanel = new JPanel();
|
||||
add(choosePanel, BorderLayout.CENTER);
|
||||
choosePanel.setLayout(new FormLayout(
|
||||
new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
|
||||
FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
|
||||
FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
|
||||
new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
|
||||
|
||||
JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text")); //$NON-NLS-1$
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
choosePanel.add(lblNewLabel, "2, 2, left, center");
|
||||
JLabel lblNewLabel = new JLabel(BUNDLE.getString("CheckPanel.lblNewLabel.text"));
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
choosePanel.add(lblNewLabel, "2, 2, left, center");
|
||||
|
||||
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text")); //$NON-NLS-1$
|
||||
btnNewButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null);
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
CheckPanel.this.fileToCheckField.setText(choosenFile.getAbsolutePath());
|
||||
CheckPanel.this.fileToCheckField
|
||||
.setCaretPosition(CheckPanel.this.fileToCheckField.getText().length());
|
||||
}
|
||||
}
|
||||
});
|
||||
JButton btnNewButton = new JButton(BUNDLE.getString("CheckPanel.btnNewButton.text"));
|
||||
btnNewButton.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
File choosenFile = CheckDirectorySelector.showSelectorDialog(CheckPanel.this, null);
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
CheckPanel.this.fileToCheckField.setText(choosenFile.getAbsolutePath());
|
||||
CheckPanel.this.fileToCheckField
|
||||
.setCaretPosition(CheckPanel.this.fileToCheckField.getText().length());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.fileToCheckField = new JTextField();
|
||||
choosePanel.add(this.fileToCheckField, "4, 2, fill, default");
|
||||
this.fileToCheckField.setColumns(10);
|
||||
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
choosePanel.add(btnNewButton, "6, 2, left, top");
|
||||
this.fileToCheckField = new JTextField();
|
||||
choosePanel.add(this.fileToCheckField, "4, 2, fill, default");
|
||||
this.fileToCheckField.setColumns(10);
|
||||
btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
choosePanel.add(btnNewButton, "6, 2, left, top");
|
||||
|
||||
JPanel actionPanel = new JPanel();
|
||||
add(actionPanel, BorderLayout.SOUTH);
|
||||
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
|
||||
JPanel actionPanel = new JPanel();
|
||||
add(actionPanel, BorderLayout.SOUTH);
|
||||
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
Component verticalStrut = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut);
|
||||
Component verticalStrut = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
actionPanel.add(panel);
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
JPanel panel = new JPanel();
|
||||
actionPanel.add(panel);
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
panel.add(horizontalGlue);
|
||||
JButton btnCheck = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text")); //$NON-NLS-1$
|
||||
panel.add(btnCheck);
|
||||
btnCheck.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
File choosenFile = new File(CheckPanel.this.fileToCheckField.getText());
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
boolean check = SibaManager.check(choosenFile);
|
||||
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
|
||||
if (check)
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"),
|
||||
choosenFile.getName());
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"),
|
||||
choosenFile.getName());
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
logger.error("SibaException ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
Component horizontalGlue = Box.createHorizontalGlue();
|
||||
panel.add(horizontalGlue);
|
||||
JButton btnCheck = new JButton(BUNDLE.getString("CheckPanel.btnNewButton_1.text"));
|
||||
panel.add(btnCheck);
|
||||
btnCheck.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
try
|
||||
{
|
||||
File choosenFile = new File(CheckPanel.this.fileToCheckField.getText());
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
boolean check = SibaManager.check(choosenFile);
|
||||
String titre = BUNDLE.getString("CheckPanel.confirmDialogTitle.text");
|
||||
if (check)
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogGood.text"),
|
||||
choosenFile.getName());
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = String.format(BUNDLE.getString("CheckPanel.confirmDialogBad.text"),
|
||||
choosenFile.getName());
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, message, titre,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(CheckPanel.this, dataMissing, titleWarning,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
logger.error("SibaException ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
|
||||
Component horizontalGlue1 = Box.createHorizontalGlue();
|
||||
panel.add(horizontalGlue1);
|
||||
Component verticalStrut1 = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut1);
|
||||
}
|
||||
Component horizontalGlue1 = Box.createHorizontalGlue();
|
||||
panel.add(horizontalGlue1);
|
||||
Component verticalStrut1 = Box.createVerticalStrut(20);
|
||||
actionPanel.add(verticalStrut1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sourceDirectory
|
||||
* the source directory
|
||||
*/
|
||||
public void setFileToCheck(final String sourceDirectory)
|
||||
{
|
||||
this.fileToCheckField.setText(sourceDirectory);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param sourceDirectory
|
||||
* the source directory
|
||||
*/
|
||||
public void setFileToCheck(final String sourceDirectory)
|
||||
{
|
||||
this.fileToCheckField.setText(sourceDirectory);
|
||||
}
|
||||
}
|
||||
|
@ -63,279 +63,279 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public final class SibaGUI
|
||||
{
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(SibaGUI.class);
|
||||
private JFrame frmSimpleBackup;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(SibaGUI.class);
|
||||
private JFrame frmSimpleBackup;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
|
||||
private BackupPanel backupPanel;
|
||||
private CheckPanel checkPanel;
|
||||
private BackupPanel backupPanel;
|
||||
private CheckPanel checkPanel;
|
||||
|
||||
/**
|
||||
* This is the constructor of this application.
|
||||
*
|
||||
* @throws UnsupportedLookAndFeelException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private SibaGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
UnsupportedLookAndFeelException, SibaException
|
||||
{
|
||||
final Locale locale;
|
||||
// Set default GUI catch.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||
{
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable exception)
|
||||
{
|
||||
String message;
|
||||
if (exception instanceof OutOfMemoryError)
|
||||
{
|
||||
message = "Java ran out of memory!\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
|
||||
}
|
||||
/**
|
||||
* This is the constructor of this application.
|
||||
*
|
||||
* @throws UnsupportedLookAndFeelException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
private SibaGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
|
||||
UnsupportedLookAndFeelException, SibaException
|
||||
{
|
||||
final Locale locale;
|
||||
// Set default GUI catch.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||
{
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable exception)
|
||||
{
|
||||
String message;
|
||||
if (exception instanceof OutOfMemoryError)
|
||||
{
|
||||
message = "Java ran out of memory!\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "An error occured: " + exception.getClass() + "(" + exception.getMessage() + ")";
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(SibaGUI.this.frmSimpleBackup, message, "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
logger.error("uncaughtException ", exception);
|
||||
}
|
||||
});
|
||||
JOptionPane.showMessageDialog(SibaGUI.this.frmSimpleBackup, message, "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
logger.error("uncaughtException ", exception);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove BOLD on default font.
|
||||
UIManager.put("swing.boldMetal", Boolean.FALSE);
|
||||
// Remove BOLD on default font.
|
||||
UIManager.put("swing.boldMetal", Boolean.FALSE);
|
||||
|
||||
// Set LookAndFeel.
|
||||
logger.debug("System lookAndFeel property: {}", System.getProperty("swing.defaultlaf"));
|
||||
logger.debug("Available lookAndFeel: {} ", GUIToolBox.availableLookAndFeels().toString());
|
||||
logger.debug("System lookAndFeel: {} ", UIManager.getSystemLookAndFeelClassName());
|
||||
logger.debug("Current lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
|
||||
// Set LookAndFeel.
|
||||
logger.debug("System lookAndFeel property: {}", System.getProperty("swing.defaultlaf"));
|
||||
logger.debug("Available lookAndFeel: {} ", GUIToolBox.availableLookAndFeels().toString());
|
||||
logger.debug("System lookAndFeel: {} ", UIManager.getSystemLookAndFeelClassName());
|
||||
logger.debug("Current lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
|
||||
|
||||
if (!StringUtils.equals(UIManager.getSystemLookAndFeelClassName(), "javax.swing.plaf.metal.MetalLookAndFeel"))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.debug("Metal LAF setted and system LAF detected, try to set system LAF.");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.debug("Failed to set the system LookAndFeel.");
|
||||
}
|
||||
}
|
||||
else if (GUIToolBox.availableLookAndFeels().toString().contains("GTK+"))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.debug("Metal LAF setted and GTK+ LAF detected, try to set GTK+ LAF.");
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.debug("Failed to set the system LookAndFeel.");
|
||||
}
|
||||
}
|
||||
logger.debug("Activated lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
|
||||
if (!StringUtils.equals(UIManager.getSystemLookAndFeelClassName(), "javax.swing.plaf.metal.MetalLookAndFeel"))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.debug("Metal LAF setted and system LAF detected, try to set system LAF.");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.debug("Failed to set the system LookAndFeel.");
|
||||
}
|
||||
}
|
||||
else if (GUIToolBox.availableLookAndFeels().toString().contains("GTK+"))
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.debug("Metal LAF setted and GTK+ LAF detected, try to set GTK+ LAF.");
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.debug("Failed to set the system LookAndFeel.");
|
||||
}
|
||||
}
|
||||
logger.debug("Activated lookAndFeel: {} ", UIManager.getLookAndFeel().getName());
|
||||
|
||||
// Set default locale.
|
||||
locale = Locale.getDefault();
|
||||
updateLanguage(locale);
|
||||
logger.debug(locale.getDisplayLanguage());
|
||||
initialize();
|
||||
// Set default locale.
|
||||
locale = Locale.getDefault();
|
||||
updateLanguage(locale);
|
||||
logger.debug(locale.getDisplayLanguage());
|
||||
initialize();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*
|
||||
* @throws SibaException
|
||||
*/
|
||||
private void initialize() throws SibaException
|
||||
{
|
||||
this.frmSimpleBackup = new JFrame();
|
||||
this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit()
|
||||
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
|
||||
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
|
||||
this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN);
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*
|
||||
* @throws SibaException
|
||||
*/
|
||||
private void initialize() throws SibaException
|
||||
{
|
||||
this.frmSimpleBackup = new JFrame();
|
||||
this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit()
|
||||
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")));
|
||||
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
|
||||
this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
tabbedPane.setBackground(Color.GREEN);
|
||||
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
tabbedPane.setBackground(Color.GREEN);
|
||||
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
this.backupPanel = new BackupPanel();
|
||||
this.backupPanel.setBackground(new Color(0, 255, 0));
|
||||
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleBackupPanel.text"), //$NON-NLS-1$
|
||||
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.backupPanel,
|
||||
null);
|
||||
this.checkPanel = new CheckPanel();
|
||||
this.checkPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
this.checkPanel.setBackground(new Color(144, 238, 144));
|
||||
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleCheckPanel.text"), //$NON-NLS-1$
|
||||
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.checkPanel,
|
||||
null);
|
||||
this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
|
||||
this.frmSimpleBackup.setForeground(new Color(0, 100, 0));
|
||||
this.frmSimpleBackup.setBackground(new Color(102, 205, 170));
|
||||
this.frmSimpleBackup.setTitle("Simple Backup");
|
||||
this.frmSimpleBackup.setBounds(100, 100, 450, 300);
|
||||
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.backupPanel = new BackupPanel();
|
||||
this.backupPanel.setBackground(new Color(0, 255, 0));
|
||||
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleBackupPanel.text"),
|
||||
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.backupPanel,
|
||||
null);
|
||||
this.checkPanel = new CheckPanel();
|
||||
this.checkPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
this.checkPanel.setBackground(new Color(144, 238, 144));
|
||||
tabbedPane.addTab(BUNDLE.getString("BackupPanel.TitleCheckPanel.text"),
|
||||
new ImageIcon(SibaGUI.class.getResource("/org/dclermonte/siba/gui/SibaLogo.png")), this.checkPanel,
|
||||
null);
|
||||
this.frmSimpleBackup.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
|
||||
this.frmSimpleBackup.setForeground(new Color(0, 100, 0));
|
||||
this.frmSimpleBackup.setBackground(new Color(102, 205, 170));
|
||||
this.frmSimpleBackup.setTitle("Simple Backup");
|
||||
this.frmSimpleBackup.setBounds(100, 100, 450, 300);
|
||||
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBackground(Color.GREEN);
|
||||
this.frmSimpleBackup.setJMenuBar(menuBar);
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBackground(Color.GREEN);
|
||||
this.frmSimpleBackup.setJMenuBar(menuBar);
|
||||
|
||||
JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text")); //$NON-NLS-1$
|
||||
mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mnFile.setBackground(Color.GREEN);
|
||||
mnFile.setMnemonic('F');
|
||||
mnFile.setForeground(Color.BLACK);
|
||||
menuBar.add(mnFile);
|
||||
JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text"));
|
||||
mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mnFile.setBackground(Color.GREEN);
|
||||
mnFile.setMnemonic('F');
|
||||
mnFile.setForeground(Color.BLACK);
|
||||
menuBar.add(mnFile);
|
||||
|
||||
JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text")); //$NON-NLS-1$
|
||||
mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmBackup.setBackground(Color.GREEN);
|
||||
mntmBackup.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
tabbedPane.setSelectedIndex(0);
|
||||
File file = SourceDirectorySelector.showSelectorDialog(SibaGUI.this.backupPanel, null);
|
||||
if (file != null)
|
||||
{
|
||||
SibaGUI.this.backupPanel.setSourceDirectory(file.getPath());
|
||||
}
|
||||
}
|
||||
});
|
||||
mnFile.add(mntmBackup);
|
||||
JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text"));
|
||||
mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmBackup.setBackground(Color.GREEN);
|
||||
mntmBackup.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
tabbedPane.setSelectedIndex(0);
|
||||
File file = SourceDirectorySelector.showSelectorDialog(SibaGUI.this.backupPanel, null);
|
||||
if (file != null)
|
||||
{
|
||||
SibaGUI.this.backupPanel.setSourceDirectory(file.getPath());
|
||||
}
|
||||
}
|
||||
});
|
||||
mnFile.add(mntmBackup);
|
||||
|
||||
JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text")); //$NON-NLS-1$
|
||||
mntmCheck.setBackground(Color.GREEN);
|
||||
mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmCheck.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
File choosenFile = CheckDirectorySelector.showSelectorDialog(SibaGUI.this.checkPanel, null);
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
SibaGUI.this.checkPanel.setFileToCheck(choosenFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
});
|
||||
mnFile.add(mntmCheck);
|
||||
JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text"));
|
||||
mntmCheck.setBackground(Color.GREEN);
|
||||
mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmCheck.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
File choosenFile = CheckDirectorySelector.showSelectorDialog(SibaGUI.this.checkPanel, null);
|
||||
if ((choosenFile != null) && choosenFile.exists())
|
||||
{
|
||||
SibaGUI.this.checkPanel.setFileToCheck(choosenFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
});
|
||||
mnFile.add(mntmCheck);
|
||||
|
||||
JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text")); //$NON-NLS-1$
|
||||
mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmQuit.setBackground(Color.GREEN);
|
||||
mntmQuit.setMnemonic(KeyEvent.VK_Q);
|
||||
mntmQuit.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent arg0)
|
||||
{
|
||||
SibaGUI.this.frmSimpleBackup.dispose();
|
||||
}
|
||||
});
|
||||
JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text"));
|
||||
mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmQuit.setBackground(Color.GREEN);
|
||||
mntmQuit.setMnemonic(KeyEvent.VK_Q);
|
||||
mntmQuit.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent arg0)
|
||||
{
|
||||
SibaGUI.this.frmSimpleBackup.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
JSeparator separator = new JSeparator();
|
||||
mnFile.add(separator);
|
||||
mnFile.add(mntmQuit);
|
||||
JSeparator separator = new JSeparator();
|
||||
mnFile.add(separator);
|
||||
mnFile.add(mntmQuit);
|
||||
|
||||
JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$
|
||||
mnNewMenu.setMnemonic('H');
|
||||
mnNewMenu.setLocation(new Point(500, 0));
|
||||
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
|
||||
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mnNewMenu.setForeground(new Color(0, 0, 0));
|
||||
mnNewMenu.setBackground(Color.GREEN);
|
||||
mnNewMenu.setOpaque(true);
|
||||
menuBar.add(mnNewMenu);
|
||||
JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text"));
|
||||
mnNewMenu.setMnemonic('H');
|
||||
mnNewMenu.setLocation(new Point(500, 0));
|
||||
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
|
||||
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mnNewMenu.setForeground(new Color(0, 0, 0));
|
||||
mnNewMenu.setBackground(Color.GREEN);
|
||||
mnNewMenu.setOpaque(true);
|
||||
menuBar.add(mnNewMenu);
|
||||
|
||||
JMenuItem mntmMenuItemAbout = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
|
||||
mntmMenuItemAbout.setBackground(Color.GREEN);
|
||||
mntmMenuItemAbout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmMenuItemAbout.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
AboutDialog dialog;
|
||||
try
|
||||
{
|
||||
dialog = new AboutDialog();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
logger.error("Exception ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
mnNewMenu.add(mntmMenuItemAbout);
|
||||
}
|
||||
JMenuItem mntmMenuItemAbout = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
|
||||
mntmMenuItemAbout.setBackground(Color.GREEN);
|
||||
mntmMenuItemAbout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
mntmMenuItemAbout.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e)
|
||||
{
|
||||
AboutDialog dialog;
|
||||
try
|
||||
{
|
||||
dialog = new AboutDialog();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
logger.error("Exception ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
mnNewMenu.add(mntmMenuItemAbout);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method launch the GUI.
|
||||
*/
|
||||
public static void run()
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
SibaGUI window = new SibaGUI();
|
||||
window.frmSimpleBackup.setVisible(true);
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
logger.error("SibaException ", exception);
|
||||
String dataMissing = exception.getMessage();
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.error("Exception ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This method launch the GUI.
|
||||
*/
|
||||
public static void run()
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
SibaGUI window = new SibaGUI();
|
||||
window.frmSimpleBackup.setVisible(true);
|
||||
}
|
||||
catch (SibaException exception)
|
||||
{
|
||||
logger.error("SibaException ", exception);
|
||||
String dataMissing = exception.getMessage();
|
||||
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
|
||||
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.error("Exception ", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This method set the local language.
|
||||
*
|
||||
* @param source
|
||||
* locale
|
||||
*/
|
||||
public static void updateLanguage(final Locale source)
|
||||
{
|
||||
// Change JVM default locale.
|
||||
java.util.Locale.setDefault(source);
|
||||
/**
|
||||
* This method set the local language.
|
||||
*
|
||||
* @param source
|
||||
* locale
|
||||
*/
|
||||
public static void updateLanguage(final Locale source)
|
||||
{
|
||||
// Change JVM default locale.
|
||||
java.util.Locale.setDefault(source);
|
||||
|
||||
// Change LookAndFeel default locale.
|
||||
javax.swing.UIManager.getDefaults().setDefaultLocale(source);
|
||||
// Change LookAndFeel default locale.
|
||||
javax.swing.UIManager.getDefaults().setDefaultLocale(source);
|
||||
|
||||
// Change new component default locale.
|
||||
javax.swing.JComponent.setDefaultLocale(source);
|
||||
// Change new component default locale.
|
||||
javax.swing.JComponent.setDefaultLocale(source);
|
||||
|
||||
//
|
||||
ResourceBundle.clearCache();
|
||||
}
|
||||
//
|
||||
ResourceBundle.clearCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,102 +17,102 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class SourceDirectorySelector extends JFileChooser
|
||||
{
|
||||
private static final long serialVersionUID = 3782597353602048214L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(SourceDirectorySelector.class);
|
||||
private static final long serialVersionUID = 3782597353602048214L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(SourceDirectorySelector.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public SourceDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public SourceDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("SourceDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
|
||||
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.sourceFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("SourceDirectorySelector.this.dialogTitle"));
|
||||
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.sourceFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {} ", file);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {} ", file);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* the parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* the parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
|
||||
//
|
||||
SourceDirectorySelector selector = new SourceDirectorySelector(targetFile);
|
||||
//
|
||||
SourceDirectorySelector selector = new SourceDirectorySelector(targetFile);
|
||||
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
@ -17,104 +17,104 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class TargetDirectorySelector extends JFileChooser
|
||||
{
|
||||
private static final long serialVersionUID = 3782597353602048214L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(TargetDirectorySelector.class);
|
||||
private static final long serialVersionUID = 3782597353602048214L;
|
||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||
public static Logger logger = LoggerFactory.getLogger(TargetDirectorySelector.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public TargetDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
/**
|
||||
*
|
||||
* @param targetFile
|
||||
* target file
|
||||
*/
|
||||
public TargetDirectorySelector(final File targetFile)
|
||||
{
|
||||
super();
|
||||
setBackground(new Color(152, 251, 152));
|
||||
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
//
|
||||
File file;
|
||||
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
|
||||
{
|
||||
file = null;
|
||||
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
}
|
||||
else if (targetFile.isFile())
|
||||
{
|
||||
file = targetFile.getParentFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = targetFile;
|
||||
}
|
||||
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("TargetDirectorySelector.this.dialogTitle")); //$NON-NLS-1$
|
||||
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
//
|
||||
setSelectedFile(file);
|
||||
setDialogTitle(BUNDLE.getString("TargetDirectorySelector.this.dialogTitle"));
|
||||
setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
setApproveButtonText(BUNDLE.getString("BackupPanel.targetFileChooserButton.text"));
|
||||
setDialogType(CUSTOM_DIALOG);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public final void setSelectedFile(final File file)
|
||||
{
|
||||
//
|
||||
super.setSelectedFile(file);
|
||||
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {} ", file);
|
||||
}
|
||||
logger.debug("==== SET SELECTED FILE=================");
|
||||
logger.debug("SELECED FILE {} ", file);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void setVisible(final boolean visible)
|
||||
{
|
||||
//
|
||||
super.setVisible(visible);
|
||||
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
if (!visible)
|
||||
{
|
||||
//
|
||||
resetChoosableFileFilters();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* the parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
* This method is the main one of the selector.
|
||||
*
|
||||
* @param parent
|
||||
* the parent's component
|
||||
* @param targetFile
|
||||
* target file
|
||||
* @return the selected file
|
||||
*/
|
||||
public static File showSelectorDialog(final Component parent, final File targetFile)
|
||||
{
|
||||
File result;
|
||||
|
||||
//
|
||||
TargetDirectorySelector selector = new TargetDirectorySelector(targetFile);
|
||||
//
|
||||
TargetDirectorySelector selector = new TargetDirectorySelector(targetFile);
|
||||
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
//
|
||||
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
//
|
||||
result = selector.getSelectedFile();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
@ -32,27 +32,27 @@ import javax.swing.UIManager;
|
||||
*/
|
||||
public final class GUIToolBox
|
||||
{
|
||||
private GUIToolBox()
|
||||
{
|
||||
private GUIToolBox()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> availableLookAndFeels()
|
||||
{
|
||||
List<String> result;
|
||||
public static List<String> availableLookAndFeels()
|
||||
{
|
||||
List<String> result;
|
||||
|
||||
//
|
||||
result = new ArrayList<String>();
|
||||
//
|
||||
result = new ArrayList<String>();
|
||||
|
||||
//
|
||||
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
|
||||
{
|
||||
//
|
||||
result.add(info.getName());
|
||||
}
|
||||
//
|
||||
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
|
||||
{
|
||||
//
|
||||
result.add(info.getName());
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -42,132 +42,132 @@ import org.dclermonte.siba.SibaException;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param fileToSave
|
||||
* name of the directory to save
|
||||
* @return the archive of the file
|
||||
* @throws SibaException
|
||||
* specific exception for Siba
|
||||
*/
|
||||
public static File backup(final File fileToSave) throws SibaException
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
* This method perform the backup.
|
||||
*
|
||||
* @param fileToSave
|
||||
* name of the directory to save
|
||||
* @return the archive of the file
|
||||
* @throws SibaException
|
||||
* specific exception for Siba
|
||||
*/
|
||||
public static File backup(final File fileToSave) throws SibaException
|
||||
{
|
||||
File result;
|
||||
|
||||
File target = new File(System.getProperty("user.dir"));
|
||||
result = backup(fileToSave, target);
|
||||
File target = new File(System.getProperty("user.dir"));
|
||||
result = backup(fileToSave, target);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method perform the backup.
|
||||
*
|
||||
* @param fileToSave
|
||||
* name of the directory to save
|
||||
* @param target
|
||||
* directory for the file
|
||||
* @return the archive of the file
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static File backup(final File fileToSave, final File target) throws SibaException
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
* This method performs the backup.
|
||||
*
|
||||
* @param fileToSave
|
||||
* name of the directory to save
|
||||
* @param target
|
||||
* directory for the file
|
||||
* @return the archive of the file
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static File backup(final File fileToSave, final File target) throws SibaException
|
||||
{
|
||||
File result;
|
||||
|
||||
TarArchiveOutputStream out = null;
|
||||
try
|
||||
{
|
||||
if ((fileToSave == null) || !fileToSave.exists())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("sourceNotExist.text"));
|
||||
}
|
||||
else if (!fileToSave.isDirectory())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("NotDirectorySource.text"));
|
||||
}
|
||||
else if (!target.isDirectory())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH'h'mm'mn'ss's'");
|
||||
String textDate = date.format(formatter);
|
||||
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
|
||||
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
|
||||
OutputStream gzipOutputStream = new GzipCompressorOutputStream(
|
||||
new BufferedOutputStream(new FileOutputStream(result)));
|
||||
out = new TarArchiveOutputStream(gzipOutputStream);
|
||||
SibaUtils.tarDirectoryTree(fileToSave, out);
|
||||
out.close();
|
||||
SibaUtils.createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
catch (NoSuchAlgorithmException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
TarArchiveOutputStream out = null;
|
||||
try
|
||||
{
|
||||
if ((fileToSave == null) || !fileToSave.exists())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("sourceNotExist.text"));
|
||||
}
|
||||
else if (!fileToSave.isDirectory())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("NotDirectorySource.text"));
|
||||
}
|
||||
else if (!target.isDirectory())
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalDateTime date = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH'h'mm'mn'ss's'");
|
||||
String textDate = date.format(formatter);
|
||||
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
|
||||
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
|
||||
OutputStream gzipOutputStream = new GzipCompressorOutputStream(
|
||||
new BufferedOutputStream(new FileOutputStream(result)));
|
||||
out = new TarArchiveOutputStream(gzipOutputStream);
|
||||
SibaUtils.tarDirectoryTree(fileToSave, out);
|
||||
out.close();
|
||||
SibaUtils.createMD5File(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
catch (NoSuchAlgorithmException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to check the file.
|
||||
*
|
||||
* @param choosenFile
|
||||
* the file to check
|
||||
* @return the result of check
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static boolean check(final File choosenFile) throws SibaException
|
||||
{
|
||||
boolean result;
|
||||
/**
|
||||
* This method is used to check the file.
|
||||
*
|
||||
* @param choosenFile
|
||||
* the file to check
|
||||
* @return the result of check
|
||||
* @throws SibaException
|
||||
* specific exception
|
||||
*/
|
||||
public static boolean check(final File choosenFile) throws SibaException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
try
|
||||
{
|
||||
String md5String = SibaUtils.loadMD5Sum(choosenFile);
|
||||
File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile);
|
||||
if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
catch (NoSuchAlgorithmException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception); //$NON-NLS-1$
|
||||
}
|
||||
try
|
||||
{
|
||||
String md5String = SibaUtils.loadMD5Sum(choosenFile);
|
||||
File fileToCheck1 = SibaUtils.readFileNameToCheck(choosenFile);
|
||||
if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), exception);
|
||||
}
|
||||
catch (NoSuchAlgorithmException exception)
|
||||
{
|
||||
throw new SibaException(BUNDLE.getString("noSuchAlgorithm.text"), exception);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,288 +40,290 @@ import org.apache.commons.io.IOUtils;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param inputFile
|
||||
* the file on which the md5 is calculate
|
||||
* @param target
|
||||
* the MD5 file
|
||||
* @return the MD5 file
|
||||
* @throws IOException
|
||||
* IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
* NoSuchAlgorithmException
|
||||
*/
|
||||
public static File createMD5File(final File inputFile, final String target)
|
||||
throws IOException, NoSuchAlgorithmException
|
||||
{
|
||||
File result;
|
||||
/**
|
||||
*
|
||||
* This method Generate the file with MD5.
|
||||
*
|
||||
* @param inputFile
|
||||
* the file on which the md5 is calculate
|
||||
* @param target
|
||||
* the MD5 file
|
||||
* @return the MD5 file
|
||||
* @throws IOException
|
||||
* IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
* NoSuchAlgorithmException
|
||||
*/
|
||||
public static File createMD5File(final File inputFile, final String target)
|
||||
throws IOException, NoSuchAlgorithmException
|
||||
{
|
||||
File result;
|
||||
|
||||
String md5 = SibaUtils.md5(inputFile);
|
||||
String fileName = inputFile.getName();
|
||||
result = createMD5File(md5, fileName, target);
|
||||
String md5 = SibaUtils.md5(inputFile);
|
||||
String fileName = inputFile.getName();
|
||||
result = createMD5File(md5, fileName, target);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param md5
|
||||
* Hash MD5
|
||||
* @param fileName
|
||||
* The name of the file
|
||||
* @param target
|
||||
* directory to put the file
|
||||
* @return The MD5 file
|
||||
* @throws IOException
|
||||
* IOexception
|
||||
*/
|
||||
public static File createMD5File(final String md5, final String fileName, final String target) throws IOException
|
||||
{
|
||||
File result;
|
||||
FileWriter out = null;
|
||||
try
|
||||
{
|
||||
result = new File(target);
|
||||
out = new FileWriter(result);
|
||||
out.write(md5);
|
||||
String newLine = System.getProperty("line.separator");
|
||||
out.append(" ");
|
||||
out.append(fileName);
|
||||
out.append(newLine);
|
||||
out.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param md5
|
||||
* Hash MD5
|
||||
* @param fileName
|
||||
* The name of the file
|
||||
* @param target
|
||||
* directory to put the file
|
||||
* @return The MD5 file
|
||||
* @throws IOException
|
||||
* IOexception
|
||||
*/
|
||||
public static File createMD5File(final String md5, final String fileName, final String target) throws IOException
|
||||
{
|
||||
File result;
|
||||
FileWriter out = null;
|
||||
try
|
||||
{
|
||||
result = new File(target);
|
||||
out = new FileWriter(result);
|
||||
out.write(md5);
|
||||
String newLine = System.getProperty("line.separator");
|
||||
out.append(" ");
|
||||
out.append(fileName);
|
||||
out.append(newLine);
|
||||
out.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param choosenFile
|
||||
* the file to check
|
||||
* @return The MD5sum
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public static String loadMD5Sum(final File choosenFile) throws IOException
|
||||
{
|
||||
String result;
|
||||
FileReader in = null;
|
||||
try
|
||||
{
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
{
|
||||
in = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(in);
|
||||
String line = bufferedReader.readLine();
|
||||
result = line.substring(0, 32);
|
||||
in.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param choosenFile
|
||||
* the file to check
|
||||
* @return The MD5sum
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public static String loadMD5Sum(final File choosenFile) throws IOException
|
||||
{
|
||||
String result;
|
||||
FileReader in = null;
|
||||
try
|
||||
{
|
||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||
{
|
||||
in = new FileReader(choosenFile);
|
||||
BufferedReader bufferedReader = new BufferedReader(in);
|
||||
String line = bufferedReader.readLine();
|
||||
result = line.substring(0, 32);
|
||||
in.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calculate the MD5 itself.
|
||||
*
|
||||
* @param input
|
||||
* The name of the file for witch the MD5 sum is to calculate
|
||||
* @return The MD5Sum
|
||||
* @throws IOException
|
||||
* IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
* NoSuchAlgorithmException
|
||||
*/
|
||||
public static String md5(final File input) throws IOException, NoSuchAlgorithmException
|
||||
{
|
||||
String result;
|
||||
/**
|
||||
* This method calculate the MD5 itself.
|
||||
*
|
||||
* @param input
|
||||
* The name of the file for witch the MD5 sum is to calculate
|
||||
* @return The MD5Sum
|
||||
* @throws IOException
|
||||
* IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
* NoSuchAlgorithmException
|
||||
*/
|
||||
public static String md5(final File input) throws IOException, NoSuchAlgorithmException
|
||||
{
|
||||
String result;
|
||||
|
||||
StringBuilder hashString = new StringBuilder();
|
||||
FileInputStream fileInputStream = null;
|
||||
try
|
||||
{
|
||||
byte[] byteInput = new byte[(int) input.length()];
|
||||
fileInputStream = new FileInputStream(input);
|
||||
for (int index1 = 0; index1 < input.length(); index1++)
|
||||
{
|
||||
byteInput[index1] = (byte) fileInputStream.read();
|
||||
}
|
||||
byte[] hash = null;
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
hash = messageDigest.digest(byteInput);
|
||||
StringBuilder hashString = new StringBuilder();
|
||||
FileInputStream fileInputStream = null;
|
||||
try
|
||||
{
|
||||
byte[] byteInput = new byte[(int) input.length()];
|
||||
fileInputStream = new FileInputStream(input);
|
||||
for (int index1 = 0; index1 < input.length(); index1++)
|
||||
{
|
||||
byteInput[index1] = (byte) fileInputStream.read();
|
||||
}
|
||||
byte[] hash = null;
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
hash = messageDigest.digest(byteInput);
|
||||
|
||||
for (int index = 0; index < hash.length; index++)
|
||||
{
|
||||
String hex = Integer.toHexString(hash[index]);
|
||||
if (hex.length() == 1)
|
||||
{
|
||||
hashString.append('0');
|
||||
hashString.append(hex.charAt(hex.length() - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
hashString.append(hex.substring(hex.length() - 2));
|
||||
}
|
||||
}
|
||||
fileInputStream.close();
|
||||
for (int index = 0; index < hash.length; index++)
|
||||
{
|
||||
String hex = Integer.toHexString(hash[index]);
|
||||
if (hex.length() == 1)
|
||||
{
|
||||
hashString.append('0');
|
||||
hashString.append(hex.charAt(hex.length() - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
hashString.append(hex.substring(hex.length() - 2));
|
||||
}
|
||||
}
|
||||
fileInputStream.close();
|
||||
|
||||
result = hashString.toString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
result = hashString.toString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param choosenFile
|
||||
* The MD5file
|
||||
* @return the file to check
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public static File readFileNameToCheck(final File choosenFile) throws IOException
|
||||
{
|
||||
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;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param choosenFile
|
||||
* The MD5file
|
||||
* @return the file to check
|
||||
* @throws IOException
|
||||
* IOException
|
||||
*/
|
||||
public static File readFileNameToCheck(final File choosenFile) throws IOException
|
||||
{
|
||||
File 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;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
URL url = SibaUtils.class.getResource(resource);
|
||||
result = IOUtils.toString(url, DEFAULT_CHARSET);
|
||||
|
||||
/**
|
||||
*
|
||||
* 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();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user