Commit 1bd5eb87 authored by Christian MOMON's avatar Christian MOMON
Browse files

Made a code review.

parent efe6ae08
#Build Number for ANT. Do not edit!
#Sun Oct 04 21:02:08 CEST 2015
build.number=6
#Sat Jul 23 02:18:05 CEST 2016
build.number=7
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -43,13 +43,10 @@ public class GUIToolBox
{
List<String> result;
//
result = new ArrayList<String>();
//
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
//
result.add(info.getName());
}
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......
......@@ -94,8 +94,8 @@ public class FlatDB4GeoNamesWindow extends JFrame
}
});
JMenuItem mntmDownloadGeonamesFiles_1 = new JMenuItem("Download GeoNames files…");
mntmDownloadGeonamesFiles_1.addActionListener(new ActionListener()
JMenuItem mntmDownloadGeonamesFiles = new JMenuItem("Download GeoNames files…");
mntmDownloadGeonamesFiles.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent event)
......@@ -104,11 +104,11 @@ public class FlatDB4GeoNamesWindow extends JFrame
DownloadGeoNamesFilesDialog.showDialog(null);
}
});
mnFile.add(mntmDownloadGeonamesFiles_1);
mnFile.add(mntmDownloadGeonamesFiles);
mnFile.add(mntmBuildIndex);
JSeparator separator_3 = new JSeparator();
mnFile.add(separator_3);
JSeparator separator3 = new JSeparator();
mnFile.add(separator3);
JMenuItem mntmDownloadIndexes = new JMenuItem("Download full database…");
mntmDownloadIndexes.addActionListener(new ActionListener()
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -130,7 +130,7 @@ public class BuildIndexesDialog extends JDialog
this.btnSelector.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Select target directory button.
File target = BuildIndexesSourceSelector.showSelectorDialog(null, null);
......@@ -212,7 +212,7 @@ public class BuildIndexesDialog extends JDialog
this.btnCancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Cancel button.
......@@ -251,154 +251,142 @@ public class BuildIndexesDialog extends JDialog
this.btnBuild.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Build button.
try
{
BuildIndexesDialog.this.btnBuild.setEnabled(false);
BuildIndexesDialog.this.btnSelector.setEnabled(false);
final String targetDirectory = BuildIndexesDialog.this.txtfldSourceDirectory.getText();
BuildIndexesDialog.this.btnBuild.setEnabled(false);
BuildIndexesDialog.this.btnSelector.setEnabled(false);
final String targetDirectory = BuildIndexesDialog.this.txtfldSourceDirectory.getText();
BuildIndexesDialog.this.chrono = new Chronometer();
BuildIndexesDialog.this.chrono = new Chronometer();
//
BuildIndexesDialog.this.buildWorker = new SwingWorker<Boolean, Integer>()
//
BuildIndexesDialog.this.buildWorker = new SwingWorker<Boolean, Integer>()
{
@Override
protected Boolean doInBackground() throws Exception
{
@Override
protected Boolean doInBackground() throws Exception
Boolean result;
try
{
Boolean result;
clearTarget(targetDirectory);
try
{
clearTarget(targetDirectory);
FlatDB4GeoNamesFactory.buildIndex(new File(targetDirectory));
FlatDB4GeoNamesFactory.buildIndex(new File(targetDirectory));
result = true;
}
catch (FileNotFoundException exception)
{
exception.printStackTrace();
result = true;
}
catch (FileNotFoundException exception)
{
exception.printStackTrace();
String title = "Error";
String message = "File not found: " + exception.getMessage();
String title = "Error";
String message = "File not found: " + exception.getMessage();
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
result = false;
}
catch (Exception exception)
{
exception.printStackTrace();
result = false;
}
catch (Exception exception)
{
exception.printStackTrace();
String title = "Error";
String message = "Download error: " + exception.getMessage();
String title = "Error";
String message = "Download error: " + exception.getMessage();
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
result = false;
}
result = false;
}
//
return result;
}
//
return result;
}
// Can safely update the GUI from this
// method.
@Override
protected void done()
{
// Retrieve the return value of
// doInBackground.
logger.debug("download progress done");
BuildIndexesDialog.this.btnCancel.setEnabled(false);
BuildIndexesDialog.this.btnBuild.setEnabled(false);
BuildIndexesDialog.this.btnDone.setEnabled(true);
BuildIndexesDialog.this.progressWorker.cancel(true);
BuildIndexesDialog.this.progressBarGlobal.setValue(100);
BuildIndexesDialog.this.progressBarIdSeekIndex.setValue(100);
BuildIndexesDialog.this.progressBarSeeksIndex.setValue(100);
BuildIndexesDialog.this.progressBarWordSeekIndex.setValue(100);
}
};
BuildIndexesDialog.this.buildWorker.execute();
// Can safely update the GUI from this
// method.
@Override
protected void done()
//
BuildIndexesDialog.this.progressWorker = new SwingWorker<Boolean, Integer>()
{
@Override
protected Boolean doInBackground() throws Exception
{
boolean ended = false;
while (!ended)
{
// Retrieve the return value of
// doInBackground.
logger.debug("download progress done");
BuildIndexesDialog.this.btnCancel.setEnabled(false);
BuildIndexesDialog.this.btnBuild.setEnabled(false);
BuildIndexesDialog.this.btnDone.setEnabled(true);
BuildIndexesDialog.this.progressWorker.cancel(true);
BuildIndexesDialog.this.progressBarGlobal.setValue(100);
BuildIndexesDialog.this.progressBarIdSeekIndex.setValue(100);
BuildIndexesDialog.this.progressBarSeeksIndex.setValue(100);
BuildIndexesDialog.this.progressBarWordSeekIndex.setValue(100);
Thread.sleep(1000);
publish();
}
};
BuildIndexesDialog.this.buildWorker.execute();
//
BuildIndexesDialog.this.progressWorker = new SwingWorker<Boolean, Integer>()
return true;
}
// Can safely update the GUI from this
// method.
@Override
protected void done()
{
@Override
protected Boolean doInBackground() throws Exception
logger.debug("progressworker done");
}
@Override
// Can safely update the GUI from this
// method.
protected void process(final List<Integer> chunks)
{
// logger.debug("progress worker process");
//
updateFreeDiskSpace();
//
if (new File(targetDirectory + File.separator + "id_seek.index").exists())
{
boolean ended = false;
while (!ended)
{
Thread.sleep(1000);
publish();
}
return true;
BuildIndexesDialog.this.progressBarIdSeekIndex.setValue(100);
}
// Can safely update the GUI from this
// method.
@Override
protected void done()
//
if (new File(targetDirectory + File.separator + "seeks.index").exists())
{
logger.debug("progressworker done");
BuildIndexesDialog.this.progressBarSeeksIndex.setValue(100);
}
@Override
// Can safely update the GUI from this
// method.
protected void process(final List<Integer> chunks)
//
if (new File(targetDirectory + File.separator + "word_seek.index").exists())
{
// logger.debug("progress worker process");
//
updateFreeDiskSpace();
//
if (new File(targetDirectory + File.separator + "id_seek.index").exists())
{
BuildIndexesDialog.this.progressBarIdSeekIndex.setValue(100);
}
//
if (new File(targetDirectory + File.separator + "seeks.index").exists())
{
BuildIndexesDialog.this.progressBarSeeksIndex.setValue(100);
}
//
if (new File(targetDirectory + File.separator + "word_seek.index").exists())
{
BuildIndexesDialog.this.progressBarWordSeekIndex.setValue(100);
}
//
long duration = BuildIndexesDialog.this.chrono.stop().interval();
BuildIndexesDialog.this.progressBarGlobal.setValue((int) (duration * 100 / (25 * 60 * 1000)));
//
String timerValue = Chronometer.toTimer(duration);
BuildIndexesDialog.this.lblTimer.setText(timerValue);
BuildIndexesDialog.this.progressBarWordSeekIndex.setValue(100);
}
};
BuildIndexesDialog.this.progressWorker.execute();
}
catch (final Exception exception)
{
//
String title = "Error computerum est";
String message = "Error occured during working: " + exception.getMessage();
//
long duration = BuildIndexesDialog.this.chrono.stop().interval();
BuildIndexesDialog.this.progressBarGlobal.setValue((int) (duration * 100 / (25 * 60 * 1000)));
//
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
}
//
String timerValue = Chronometer.toTimer(duration);
BuildIndexesDialog.this.lblTimer.setText(timerValue);
}
};
BuildIndexesDialog.this.progressWorker.execute();
}
});
this.btnBuild.setActionCommand("OK");
......@@ -435,11 +423,11 @@ public class BuildIndexesDialog extends JDialog
{
if (StringUtils.isNotBlank(path))
{
new File(path + File.separator + "id_seek.index").delete();
new File(path + File.separator + "seeks.index").delete();
new File(path + File.separator + "word_seek.index").delete();
new File(path + File.separator + "word_seeks.index").delete();
new File(path + File.separator + "word_seeks.index.rejection").delete();
new File(path, "id_seek.index").delete();
new File(path, "seeks.index").delete();
new File(path, "word_seek.index").delete();
new File(path, "word_seeks.index").delete();
new File(path, "word_seeks.index.rejection").delete();
}
}
......@@ -528,11 +516,19 @@ public class BuildIndexesDialog extends JDialog
* Launch the application.
*/
public static void showDialog()
{
showDialog(null);
}
/**
* Launch the application.
*/
public static void showDialog(final Component parent)
{
//
BuildIndexesDialog dialog = new BuildIndexesDialog();
dialog.setLocationRelativeTo(null);
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
}
}
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -49,7 +49,6 @@ public class BuildIndexesSourceSelector extends JFileChooser
if ((targetFile == null) || (StringUtils.isBlank(targetFile.getAbsolutePath())))
{
file = null;
}
else if (targetFile.isFile())
{
......@@ -104,8 +103,8 @@ public class BuildIndexesSourceSelector extends JFileChooser
//
super.setSelectedFile(file);
System.out.println("==== SET SELECTED FILE=================");
System.out.println("SELECED FILE " + file);
logger.debug("==== SET SELECTED FILE=================");
logger.debug("SELECED FILE {}", file);
}
/**
......@@ -119,7 +118,6 @@ public class BuildIndexesSourceSelector extends JFileChooser
if (!visible)
{
//
resetChoosableFileFilters();
}
}
......@@ -140,7 +138,6 @@ public class BuildIndexesSourceSelector extends JFileChooser
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
logger.debug("getCurrentDirectory(): {}", selector.getCurrentDirectory());
logger.debug("getSelectedFile() : {}", selector.getSelectedFile());
result = selector.getSelectedFile();
......@@ -148,7 +145,6 @@ public class BuildIndexesSourceSelector extends JFileChooser
}
else
{
//
result = null;
}
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -77,6 +77,7 @@ public class DownloadingGeoNamesFilesDialog extends JDialog
*/
public DownloadingGeoNamesFilesDialog(final DownloadGeoNamesFilesCriteria criteria)
{
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setModal(true);
setTitle("Downloading GeoNames dump files");
setBounds(100, 100, 780, 350);
......@@ -420,8 +421,8 @@ public class DownloadingGeoNamesFilesDialog extends JDialog
{
//
DownloadingGeoNamesFilesDialog dialog = new DownloadingGeoNamesFilesDialog(criteria);
dialog.setLocationRelativeTo(null);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
}
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -25,6 +25,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.List;
......@@ -148,7 +149,7 @@ public class DownloadGeoNamesFilesDialog extends JDialog
this.btnSelector.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Select target directory button.
File target = DownloadTargetSelector.showSelectorDialog(null, null);
......@@ -236,7 +237,7 @@ public class DownloadGeoNamesFilesDialog extends JDialog
this.btnCancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Cancel button.
......@@ -273,7 +274,7 @@ public class DownloadGeoNamesFilesDialog extends JDialog
this.btnDownload.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Download button.
final DownloadGeoNamesFilesCriteria criteria = getCriteria();
......@@ -447,7 +448,7 @@ public class DownloadGeoNamesFilesDialog extends JDialog
DownloadGeoNamesFilesDialog.this.progressWorker.execute();
}
catch (final Exception exception)
catch (final IOException exception)
{
//
String title = "Error computerum est";
......@@ -470,7 +471,7 @@ public class DownloadGeoNamesFilesDialog extends JDialog
this.btnDone.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
public void actionPerformed(final ActionEvent event)
{
// Button done.
dispose();
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......@@ -138,7 +138,6 @@ public class DownloadTargetSelector extends JFileChooser
//
if (selector.showDialog(parent, null) == JFileChooser.APPROVE_OPTION)
{
//
logger.debug("getCurrentDirectory(): {}", selector.getCurrentDirectory());
logger.debug("getSelectedFile() : {}", selector.getSelectedFile());
result = selector.getSelectedFile();
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......
/*
* Copyright (C) 2015 Christian Pierre MOMON <christian.momon@devinsy.fr>
* Copyright (C) 2016 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of FlatDB4GeoNames.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment