04.07., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 6689dc51 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Refactored code, deleted unnecessary code and renamed config file "vadere.conf" to ".vadere.conf".

parent 9a3db0ba
Pipeline #121955 passed with stages
in 115 minutes and 8 seconds
[Global]
# Default Simulation Config
Density.measurementScale=10.0
Density.measurementRadius=15
Density.standardDeviation=0.5
Pedestrian.radius=0.195
Toolbar.size=40
Logo.show=false
SettingsDialog.maxNumberOfTargets=10
SettingsDialog.dataFormat=yyyy_MM_dd_HH_mm_ss
SettingsDialog.outputDirectory.path=.
SettingsDialog.snapshotDirectory.path=.
# GUI
Toolbar.size=40
ProjectView.icon.height.value=35
ProjectView.icon.width.value=35
ProjectView.cellWidth=1.0
ProjectView.minCellWidth=0.01
ProjectView.maxCellWidth=10.0
[TopographyCreator]
TopographyCreator.dotRadius=0.5
SettingsDialog.maxNumberOfTargets=10
SettingsDialog.dataFormat=yyyy_MM_dd_HH_mm_ss
SettingsDialog.outputDirectory.path=.
SettingsDialog.snapshotDirectory.path=.
SettingsDialog.showLogo=false
[PostVis]
PostVis.SVGWidth=1024
PostVis.SVGHeight=768
PostVis.maxNumberOfSaveDirectories=5
......@@ -31,3 +27,5 @@ PostVis.cellWidth=1.0
PostVis.minCellWidth=0.01
PostVis.maxCellWidth=10.0
PostVis.enableJsonInformationPanel=true
TopographyCreator.dotRadius=0.5
package org.vadere.gui.components.control.simulation;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.ImageGenerator;
import org.vadere.gui.postvisualization.view.ImageSizeDialog;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -20,12 +22,11 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ActionGeneratePNG extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGeneratePNG.class);
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private ImageGenerator generator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -45,7 +46,7 @@ public class ActionGeneratePNG extends AbstractAction implements IRendererChange
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.get("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
......
package org.vadere.gui.components.control.simulation;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.SVGGenerator;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.prefs.Preferences;
import javax.swing.*;
public class ActionGenerateSVG extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGenerateSVG.class);
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final SVGGenerator svgGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -36,7 +36,7 @@ public class ActionGenerateSVG extends AbstractAction implements IRendererChange
@Override
public void actionPerformed(ActionEvent e) {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.get("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
......
package org.vadere.gui.components.control.simulation;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.TikzGenerator;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.prefs.Preferences;
import javax.swing.*;
public class ActionGenerateTikz extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGenerateTikz.class);
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final TikzGenerator tikzGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -36,7 +37,7 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
@Override
public void actionPerformed(ActionEvent e) {
Date todaysDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.get("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
......
package org.vadere.gui.components.control.simulation;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.prefs.Preferences;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.util.config.VadereConfig;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.prefs.Preferences;
public class ActionSetSnapshotDirectory extends ActionVisualization {
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final JTextField textField;
......@@ -26,14 +24,17 @@ public class ActionSetSnapshotDirectory extends ActionVisualization {
@Override
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser(CONFIG.get("SettingsDialog.snapshotDirectory.path"));
final JFileChooser fc = new JFileChooser(CONFIG.getString("SettingsDialog.snapshotDirectory.path"));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
CONFIG.set("SettingsDialog.snapshotDirectory.path", file.getAbsolutePath());
CONFIG.setProperty("SettingsDialog.snapshotDirectory.path", file.getAbsolutePath());
Preferences.userNodeForPackage(PostVisualisation.class).put("SettingsDialog.snapshotDirectory.path",
file.getAbsolutePath());
textField.setText(file.getAbsolutePath());
}
}
......
......@@ -6,14 +6,15 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.vadere.util.config.IConfigSection;
import org.apache.commons.configuration2.Configuration;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.visualization.ColorHelper;
public class DefaultSimulationConfig extends DefaultConfig {
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private boolean showLogo = CONFIG.getBoolean("Logo.show");
private static final Configuration CONFIG = VadereConfig.getConfig();
private boolean showLogo = CONFIG.getBoolean("SettingsDialog.showLogo");
private double densityScale = CONFIG.getDouble("Density.measurementScale");
private double densityMeasurementRadius = CONFIG.getDouble("Density.measurementRadius");
private double densityStandardDerivation = CONFIG.getDouble("Density.standardDeviation");
......
package org.vadere.gui.components.utils;
import org.apache.commons.configuration2.Configuration;
import org.jcodec.api.awt.SequenceEncoder;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.IRecorder;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -18,17 +19,17 @@ import java.util.Date;
import java.util.Observable;
import java.util.prefs.Preferences;
import javax.swing.*;
public class Recorder implements IRecorder {
private static Logger logger = Logger.getLogger(Recorder.class);
private static final Configuration CONFIG = VadereConfig.getConfig();
private SequenceEncoder enc;
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
@Override
public void startRecording() {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.get("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
File outputFile = new File("VADERE_sim_" + formattedDate + ".mov");
......
......@@ -2,17 +2,18 @@ package org.vadere.gui.components.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.control.simulation.*;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.*;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.SwingUtils;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.control.ActionCloseSettingDialog;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
......@@ -20,14 +21,12 @@ import java.util.List;
import java.util.Optional;
import java.util.prefs.Preferences;
import javax.swing.*;
/**
* @author Benedikt Zoennchen
*/
public class SettingsDialog extends JDialog {
private static Logger logger = Logger.getLogger(SettingsDialog.class);
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private DefaultSimulationConfig config;
private List<JButton> targetColorButtons;
......@@ -93,7 +92,7 @@ public class SettingsDialog extends JDialog {
colorLayeredPane.setLayout(colorLayout);
additionalLayeredPane.setLayout(additionalLayout);
Integer[] colorIds = new Integer[Integer.parseInt(CONFIG.get("SettingsDialog.maxNumberOfTargets"))];
Integer[] colorIds = new Integer[CONFIG.getInt("SettingsDialog.maxNumberOfTargets")];
for (int index = 1; index <= colorIds.length; index++) {
colorIds[index - 1] = index;
}
......
......@@ -2,42 +2,38 @@ package org.vadere.gui.onlinevisualization.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
import org.vadere.gui.components.control.ViewportChangeListener;
import org.vadere.gui.components.utils.*;
import org.vadere.gui.components.control.simulation.*;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.utils.SwingUtils;
import org.vadere.gui.components.view.DialogFactory;
import org.vadere.gui.components.view.ScenarioElementView;
import org.vadere.gui.components.view.ScenarioScrollPane;
import org.vadere.gui.components.view.SimulationInfoPanel;
import org.vadere.gui.components.control.simulation.ActionGeneratePNG;
import org.vadere.gui.components.control.simulation.ActionGenerateSVG;
import org.vadere.gui.components.control.simulation.ActionGenerateTikz;
import org.vadere.gui.onlinevisualization.control.ActionOnlineVisMenu;
import org.vadere.gui.onlinevisualization.control.ActionShowMesh;
import org.vadere.gui.onlinevisualization.control.ActionShowPotentialField;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import org.vadere.gui.components.control.simulation.ActionSwapSelectionMode;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.view.DialogFactory;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;
public class OnlineVisualisationWindow extends JPanel implements Observer {
private static final long serialVersionUID = 3522170593760789565L;
private static final Resources resources = Resources.getInstance("global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private ScenarioElementView jsonPanel;
private static final Configuration CONFIG = VadereConfig.getConfig(); private ScenarioElementView jsonPanel;
private JToolBar toolbar;
private SimulationInfoPanel infoPanel;
......
package org.vadere.gui.postvisualization.control;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.DialogFactory;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.io.IOUtils;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
......@@ -20,11 +21,10 @@ import java.util.Optional;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javax.swing.*;
public class ActionOpenFile extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionOpenFile.class);
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final PostvisualizationModel model;
private String path = null;
......@@ -63,8 +63,9 @@ public class ActionOpenFile extends ActionVisualization {
final File threadFile = file;
if (file != null) {
CONFIG.set("SettingsDialog.outputDirectory.path", file.getParent());
CONFIG.setProperty("SettingsDialog.outputDirectory.path", file.getParent());
Preferences.userNodeForPackage(PostVisualisation.class).put("SettingsDialog.outputDirectory.path", file.getParent());
try {
IOUtils.saveUserPreferences(PostVisualisation.preferencesFilename,
Preferences.userNodeForPackage(PostVisualisation.class));
......@@ -122,7 +123,7 @@ public class ActionOpenFile extends ActionVisualization {
}
String[] dirs =
Preferences.userNodeForPackage(PostVisualisation.class).get("recentlyOpenedFiles", "").split(",");
int maxSavedDirs = Integer.valueOf(CONFIG.get("PostVis.maxNumberOfSaveDirectories"));
int maxSavedDirs = CONFIG.getInt("PostVis.maxNumberOfSaveDirectories");
if (dirs != null) {
int i = 0;
......
package org.vadere.gui.postvisualization.control;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.utils.Resources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.gui.postvisualization.utils.IRecorder;
import org.vadere.gui.postvisualization.utils.MovRecorder;
import org.vadere.gui.postvisualization.view.ImageSizeDialog;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import javax.swing.*;
public class ActionRecording extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionRecording.class);
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private static Resources resources = Resources.getInstance("postvisualization");
private final PostvisualizationModel model;
......
package org.vadere.gui.postvisualization.control;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.DialogFactory;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.gui.postvisualization.utils.PotentialFieldContainer;
import org.vadere.state.scenario.Topography;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.*;
public class ActionShowPotentialField extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionShowPotentialField.class);
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private final PostvisualizationModel model;
private static final Configuration CONFIG = VadereConfig.getConfig(); private final PostvisualizationModel model;
public ActionShowPotentialField(final String name, final Icon icon, final PostvisualizationModel model) {
super(name, icon, model);
......@@ -36,7 +35,7 @@ public class ActionShowPotentialField extends ActionVisualization {
if (returnVal == JFileChooser.APPROVE_OPTION) {
final File file = fc.getSelectedFile();
CONFIG.set("SettingsDialog.outputDirectory.path", file.getParent());
CONFIG.setProperty("SettingsDialog.outputDirectory.path", file.getParent());
final JFrame dialog = DialogFactory.createLoadingDialog();
dialog.setVisible(true);
......@@ -52,14 +51,14 @@ public class ActionShowPotentialField extends ActionVisualization {
model.config.setShowTargetPotentialField(true);
model.notifyObservers();
// logger.info("read: \n" + data);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex.getMessage());
JOptionPane.showMessageDialog(
null,
CONFIG.get("InformationDialogFileError") + " - "
+ e.getMessage(),
CONFIG.get("InformationDialogError.title"),
ex.getMessage(),
Messages.getString("InformationDialogError.title"),
JOptionPane.ERROR_MESSAGE);
}
......
package org.vadere.gui.postvisualization.model;
import java.util.*;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import java.util.Observable;
public class PostvisualizationConfig extends DefaultSimulationConfig {
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private static final Configuration CONFIG = VadereConfig.getConfig();
private boolean recording = false;
private boolean showAllTrajectories = true;
......
package org.vadere.util.config;
import javax.swing.*;
import java.awt.image.BufferedImage;
/**
* A {@link VadereConfig} is divided into config sections (denoted by square brackets "[SectionName]").
* This class represents such a section with key-value pairs.
*/
public interface IConfigSection {
default String decorate(final String key) {
return key.replace(".", "..");
}
default String get(final String key) {
return getString(key);
}
boolean getBoolean(final String key);
String getString(final String key);
double getDouble(final String key);
int getInt(final String key);
void set(final String key, Object value);
}
package org.vadere.util.config;
import org.apache.commons.configuration2.SubnodeConfiguration;
import org.vadere.util.logging.Logger;
public class IniConfigSection implements IConfigSection {
// Variables
private final SubnodeConfiguration configuration;
// Constructors
public IniConfigSection(SubnodeConfiguration section) {
this.configuration = section;
}
// Methods
@Override
public boolean getBoolean(String key) {
return configuration.getBoolean(decorate(key));
}
@Override
public String getString(String key) {
return configuration.getString(decorate(key));
}
@Override
public double getDouble(String key) {
return configuration.getDouble(decorate(key));
}
@Override
public int getInt(String key) {
return configuration.getInt(decorate(key));
}
@Override
public void set(String key, Object value) {
configuration.setProperty(decorate(key), value);
}
}
package org.vadere.util.config;
import org.apache.commons.configuration2.INIConfiguration;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.FileBasedConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.vadere.util.logging.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
/**
* A Vadere config reads its values from an INI-based text file which is divided into sections.
* A {@link VadereConfig} reads its options from a text file in "properties" style. I.e., simple key-value pairs
* where keys can contain dots but no section dividers are allowed (for more details see
* https://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Properties_files).
* {@link VadereConfig} uses the Apache Commons Configuration library to read such property files.
*
* An input looks like this:
* A Vadere config file looks like this:
*
* <pre>
* [PostVis]
* # PostVis
* PostVis.SVGWidth=1024
* PostVis.SVGHeight=768
* </pre>
*
* This config object is used like this:
*
* <pre>int svgWidth = VadereConfig.getInstance().getSection("PostVis").getInt("PostVis.SVGWidth");</pre>
* <pre>int svgWidth = VadereConfig.getConfig().getInt("PostVis.SVGWidth");</pre>
*/
public class VadereConfig {
// Static Variables
private static final Logger logger = Logger.getLogger(VadereConfig.class);
// TODO: Provide following functionality:
// - Use OS-specific location to store config file (home directory preferred).
// - Write default config file if no config file exists or errors occur while reading existing config file.
// - Add flag --config-file <path/to/file> to all(!) Vadere applications (i.e., GUI, Console, PostVis, ...).
private static final String PATH_TO_CONFIG = "./vadere.conf";
private static final VadereConfig SINGLETON_INSTANCE = new VadereConfig(PATH_TO_CONFIG);
private static final Logger LOGGER = Logger.getLogger(VadereConfig.class);
private static final VadereConfig SINGLETON_INSTANCE = new VadereConfig();
private static final String CONFIG_FILENAME = ".vadere.conf";
// Variables
// TODO: Use "PropertiesConfiguration" and "dot" notation in "vadere.conf" and avoid "decorate()" method.
// See https://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_properties.html#Properties_files)
private final INIConfiguration configuration;
private final HashMap<String, IConfigSection> configSections;
Configuration vadereConfig;
// Constructors
public VadereConfig(String path) {
configuration = new INIConfiguration();
configSections = new HashMap<>();
public VadereConfig() {
// TODO: Set additional parameters like search location etc and ensure set keys are sorted alphabetically.
PropertiesBuilderParameters propertiesParams = new Parameters().properties()
.setFileName(CONFIG_FILENAME)
.setBasePath("./");
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(propertiesParams);