Commit b4a48638 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

Cleaned up branch "single_config" a bit and added TODOs.

- Moved all config classes to package "org.vadere.util.config".
- Renamed:
  * "ExperimentalResources" to "VadereConfig".
  * "ConfigurationSection" to "IConfigSection".
  * "INIConfigurationSection" to "IniConfigSection".
- Revised "config.ini" (renamed keys and deleted unnecessary keys).
parent 415d81b2
Obstacle.color=#000000
Target.color=#00FF00
Source.color=#00FFFF
Pedestrian.color=#0000FF
Density.measurementscale=10.0
Density.measurementradius=15
Density.standardderivation=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=.
ProjectView.icon.height.value=35
ProjectView.icon.width.value=35
ProjectView.cellWidth=1.0
ProjectView.minCellWidth=0.01
ProjectView.maxCellWidth=10.0
PostVis.SVGWidth=1024
PostVis.SVGHeight=768
PostVis.maxNumberOfSaveDirectories=5
PostVis.maxFramePerSecond=30
PostVis.framesPerSecond=5
PostVis.cellWidth=1.0
PostVis.minCellWidth=0.01
PostVis.maxCellWidth=10.0
PostVis.enableJsonInformationPanel=true
#generate_high_resolution_image = Generate High Resolution Image
ImageSizeDialog.title=Image size
ImageSizeDialog.lblWidth.text=Width
ImageSizeDialog.lblHeight.text=Height
\ No newline at end of file
TopographyCreator.dotRadius=0.5
\ No newline at end of file
......@@ -383,3 +383,7 @@ RunScenarioNotReadyToRun.text=One or more of the selected scenarios isn't ready
ActionEditScenarioDescription.menu.title=Edit description
Data.TrajectoryOrScenarioFile.NoData.text=No trajectory or scenario file found.
ImageSizeDialog.title=Image size
ImageSizeDialog.lblWidth.text=Width
ImageSizeDialog.lblHeight.text=Height
\ No newline at end of file
......@@ -376,4 +376,8 @@ RunScenarioNotReadyToRun.text=Eines oder mehrere der ausgew\u00e4hlten Szenario
ActionEditScenarioDescription.menu.title=Beschreibung bearbeiten
Data.TrajectoryOrScenarioFile.NoData.text=Keine Trajektorien- oder Szenario-Datei gefunden.
\ No newline at end of file
Data.TrajectoryOrScenarioFile.NoData.text=Keine Trajektorien- oder Szenario-Datei gefunden.
ImageSizeDialog.title=Bildgr\u00f6\u00dfe
ImageSizeDialog.lblWidth.text=Breite
ImageSizeDialog.lblHeight.text=H\u00f6he
\ No newline at end of file
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.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
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;
import java.io.IOException;
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 Resources resources = Resources.getInstance("global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private ImageGenerator generator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -41,10 +41,10 @@ public class ActionGeneratePNG extends AbstractAction implements IRendererChange
ImageSizeDialog imageSizeDialog = new ImageSizeDialog(model);
if (imageSizeDialog.getState() == ImageSizeDialog.State.Ok) {
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
JFileChooser fileChooser = new JFileChooser(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
......
......@@ -4,24 +4,21 @@ package 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.Messages;
import org.vadere.gui.components.utils.Resources;
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 Resources resources = Resources.getInstance("global");
private final SVGGenerator svgGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -35,10 +32,10 @@ public class ActionGenerateSVG extends AbstractAction implements IRendererChange
@Override
public void actionPerformed(ActionEvent e) {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("SettingsDialog.dataFormat"));
SimpleDateFormat formatter = new SimpleDateFormat(VadereConfig.getConfig().getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
JFileChooser fileChooser = new JFileChooser(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
File outputFile = new File(Messages.getString("FileDialog.filenamePrefix") + formattedDate + ".svg");
fileChooser.setSelectedFile(outputFile);
......
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.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
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 Resources resources = Resources.getInstance("global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final TikzGenerator tikzGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -35,10 +35,10 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
@Override
public void actionPerformed(ActionEvent e) {
Date todaysDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("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", "."));
JFileChooser fileChooser = new JFileChooser(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
File outputFile = new File(Messages.getString("FileDialog.filenamePrefix") + formattedDate + ".tex");
fileChooser.setSelectedFile(outputFile);
......
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.gui.components.utils.Resources;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.util.config.VadereConfig;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
public class ActionSetSnapshotDirectory extends ActionVisualization {
private static Resources resources = Resources.getInstance("postvisualization");
private static final Configuration CONFIG = VadereConfig.getConfig();
private final JTextField textField;
......@@ -25,14 +22,14 @@ public class ActionSetSnapshotDirectory extends ActionVisualization {
@Override
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser(resources.getProperty("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();
resources.setProperty("SettingsDialog.snapshotDirectory.path", file.getAbsolutePath());
Preferences.userNodeForPackage(PostVisualisation.class).put("SettingsDialog.snapshotDirectory.path",
file.getAbsolutePath());
CONFIG.setProperty("SettingsDialog.snapshotDirectory.path", file.getAbsolutePath());
textField.setText(file.getAbsolutePath());
}
}
......
......@@ -6,16 +6,19 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.vadere.gui.components.utils.Resources;
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 Resources resources = Resources.getInstance("global");
private boolean showLogo = Boolean.valueOf(resources.getProperty("Logo.show"));
private double densityScale = Double.valueOf(resources.getProperty("Density.measurementscale"));
private double densityMeasurementRadius = Double.valueOf(resources.getProperty("Density.measurementradius"));
private double densityStandardDerivation = Double.valueOf(resources.getProperty("Density.standardderivation"));
private double pedestrianTorso = Double.valueOf(resources.getProperty("Pedestrian.Radius")) * 2;
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");
private double pedestrianTorso = CONFIG.getDouble("Pedestrian.radius") * 2;
private boolean useRandomPedestrianColors = false;
private boolean showPedestrianIds = false;
......@@ -37,9 +40,9 @@ public class DefaultSimulationConfig extends DefaultConfig {
protected final Color pedestrianDefaultColor = Color.BLUE;
private Map<Integer, Color> pedestrianColors = new TreeMap<>();
private Map<Integer, Color> randomColors = new HashMap<>();
private double gridWidth = Double.valueOf(resources.getProperty("ProjectView.cellWidth"));
private final double MIN_CELL_WIDTH = Double.valueOf(resources.getProperty("ProjectView.minCellWidth"));
private final double MAX_CELL_WIDTH = Double.valueOf(resources.getProperty("ProjectView.maxCellWidth"));
private double gridWidth = CONFIG.getDouble("ProjectView.cellWidth");
private final double MIN_CELL_WIDTH = CONFIG.getDouble("ProjectView.minCellWidth");
private final double MAX_CELL_WIDTH = CONFIG.getDouble("ProjectView.maxCellWidth");
public DefaultSimulationConfig() {
super();
......
package org.vadere.gui.components.utils;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.lang.BundleManager;
import java.util.Locale;
import java.util.prefs.Preferences;
import javax.swing.*;
import java.util.Locale;
/**
* Messages class used in localization.
......@@ -34,7 +32,7 @@ public class Messages {
}
public static void changeLanguage(Locale lang) {
Preferences.userNodeForPackage(VadereApplication.class).put("language", lang.getLanguage());
VadereConfig.getConfig().setProperty("Messages.language", lang.getLanguage());
BundleManager.instance().setLanguage(lang);
JOptionPane.showMessageDialog(ProjectView.getMainWindow(), getString("Messages.changeLanguagePopup.text"),
getString("Messages.changeLanguagePopup.title"), JOptionPane.INFORMATION_MESSAGE);
......
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.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -14,21 +16,20 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
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 Resources resources = Resources.getInstance("global");
@Override
public void startRecording() {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("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", "."));
JFileChooser fileChooser = new JFileChooser(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
File outputFile = new File("VADERE_sim_" + formattedDate + ".mov");
fileChooser.setSelectedFile(outputFile);
......
......@@ -2,32 +2,29 @@ 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.Messages;
import org.vadere.gui.components.utils.Resources;
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.VadereConfig;
import org.vadere.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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 Resources resources = Resources.getInstance("global");
private static final Configuration CONFIG = VadereConfig.getConfig();
private DefaultSimulationConfig config;
private List<JButton> targetColorButtons;
......@@ -93,7 +90,8 @@ public class SettingsDialog extends JDialog {
colorLayeredPane.setLayout(colorLayout);
additionalLayeredPane.setLayout(additionalLayout);
Integer[] colorIds = new Integer[Integer.parseInt(resources.getProperty("SettingsDialog.maxNumberOfTargets"))];
// Integer[] colorIds = new Integer[CONFIG.("SettingsDialog.maxNumberOfTargets")];
Integer[] colorIds = (Integer[])CONFIG.getArray(Integer.class, "SettingsDialog.maxNumberOfTargets");
for (int index = 1; index <= colorIds.length; index++) {
colorIds[index - 1] = index;
}
......@@ -284,8 +282,9 @@ public class SettingsDialog extends JDialog {
additionalLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblSnapshotDir.text") + ":"),
cc.xy(2, 20));
JTextField tSnapshotDir = new JTextField(
Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));
/* JTextField tSnapshotDir = new JTextField(
Preferences.userNodeForPackage(PostVisualisation.class).get("SettingsDialog.snapshotDirectory.path", "."));*/
JTextField tSnapshotDir = new JTextField(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
tSnapshotDir.setEditable(false);
tSnapshotDir.setPreferredSize(new Dimension(130, 20));
additionalLayeredPane.add(tSnapshotDir, cc.xy(4, 20));
......
......@@ -3,7 +3,6 @@ package org.vadere.gui.components.view;
import org.jetbrains.annotations.NotNull;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.CLGaussianCalculator;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -22,7 +21,6 @@ import java.util.stream.Stream;
public abstract class SimulationRenderer extends DefaultRenderer {
private static Logger logger = Logger.getLogger(SimulationRenderer.class);
private static Resources resources = Resources.getInstance("postvisualization");
private static double MAX_POTENTIAL = 1000.0;
private static double CONTOUR_STEP = 2.0;
......
package org.vadere.gui.onlinevisualization.view;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.*;
import javax.swing.*;
import org.vadere.gui.components.control.DefaultModeAdapter;
import org.vadere.gui.components.control.IMode;
import org.vadere.gui.components.control.RectangleSelectionMode;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.gui.components.view.ScaleablePanel;
import org.vadere.gui.onlinevisualization.control.OnlineVisSelectionMode;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
......@@ -37,7 +31,6 @@ public class MainPanel extends ScaleablePanel implements Observer {
private final OnlineVisualizationModel model;
private List<IRendererChangeListener> rendererChangeListeners;
private static Resources resources = Resources.getInstance("global");
private IMode selectionMode = null;
/** Creates a new main panel. */
......@@ -118,7 +111,7 @@ public class MainPanel extends ScaleablePanel implements Observer {
public void preLoop() {
this.renderer = new OnlinevisualizationRenderer(model);
renderer.setLogo(resources.getImage("vadere.png"));
resources.getImage("vadere.png");
setRenderer(renderer);
rendererChangeListeners.stream().forEach(l -> l.update(renderer));
}
......
......@@ -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.control.simulation.ActionGeneratePoly;
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.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 ScenarioElementView jsonPanel;
private static final Configuration CONFIG = VadereConfig.getConfig(); private ScenarioElementView jsonPanel;
private JToolBar toolbar;
private SimulationInfoPanel infoPanel;
......@@ -70,7 +66,8 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
// toolbar.setBorderPainted(false);
toolbar.setAlignmentX(Component.LEFT_ALIGNMENT);
toolbar.setAlignmentY(Component.TOP_ALIGNMENT);
int toolbarSize = Integer.parseInt(resources.getProperty("Toolbar.size"));
// TODO: Should this be really configurable in a config file?
int toolbarSize = CONFIG.getInt("Gui.toolbar.size");
toolbar.setPreferredSize(new Dimension(toolbarSize, toolbarSize));
infoPanel = new SimulationInfoPanel(model);
......@@ -80,10 +77,9 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
setLayout(spiltLayout);
int iconHeight = Integer.valueOf(resources.getProperty("ProjectView.icon.height.value"));
int iconWidth = Integer.valueOf(resources.getProperty("ProjectView.icon.width.value"));
// TODO: Should this be really configurable in a config file?
int iconHeight = CONFIG.getInt("ProjectView.icon.height.value");
int iconWidth = CONFIG.getInt("ProjectView.icon.width.value");
AbstractAction openSettingsDialog = new ActionVisualization("settings", resources.getIcon("settings.png", iconWidth, iconHeight), model) {
@Override
......@@ -195,7 +191,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
ActionShowPotentialField showPotentialField = new ActionShowPotentialField(
"showPotentialField",
resources.getIcon("potentialField.png", iconWidth, iconHeight),
resources.getIcon("potentialField.png", iconWidth, iconHeight),
model);
mainPanel.addRendererChangeListener(generatePNG);
......
package org.vadere.gui.postvisualization;
import org.vadere.gui.postvisualization.view.PostvisualizationWindow;
import org.vadere.util.io.IOUtils;
import org.vadere.util.logging.Logger;
import org.vadere.util.logging.StdOutErrLog;
import java.io.IOException;
import java.util.prefs.BackingStoreException;
import java.util.prefs.InvalidPreferencesFormatException;
import java.util.prefs.Preferences;
public class PostVisualisation {
public static final String preferencesFilename = "PostVisualisation.preferences.xml";
// TODO: Move logic to read/write config file to "VadereConfig.java".
private static Logger logger = Logger.getLogger(PostVisualisation.class);
public static void main(String[] args) {
StdOutErrLog.addStdOutErrToLog();
logger.info("starting post visualization ...");
// load settings
loadPreferences();
logger.info("preferences started");
// start main gui
PostvisualizationWindow.start();
logger.info("post visualization started");
}
/**
* Load the preferences from file.
*/
private static void loadPreferences() {
Preferences prefs = null;
try {
IOUtils.loadUserPreferences(preferencesFilename, PostVisualisation.class);
} catch (IOException | InvalidPreferencesFormatException e) {
logger.error("preferences file not found or corrupted. creating a new file...");
prefs = Preferences.userNodeForPackage(PostVisualisation.class);
defaultPreferences(prefs);
try {
IOUtils.saveUserPreferences(preferencesFilename, prefs);
} catch (IOException | BackingStoreException e1) {
logger.error("preferences file could not be written.");
}
}
}
/**
* Set default preferences.
*
* @param prefs
*/
private static void defaultPreferences(final Preferences prefs) {
prefs.put("SettingsDialog.outputDirectory.path", ".");
prefs.put("SettingsDialog.snapshotDirectory.path", ".");
prefs.put("recentlyOpenedFiles", "");
}
}
package org.vadere.gui.postvisualization.control;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.util.io.IOUtils;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javax.swing.*;
import java.awt.event.ActionEvent;
public class ActionCloseSettingDialog extends AbstractAction {
private static Logger logger = Logger.getLogger(ActionCloseSettingDialog.class);
......@@ -22,14 +17,6 @@ public class ActionCloseSettingDialog extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
try {
IOUtils.saveUserPreferences(PostVisualisation.preferencesFilename,
Preferences.userNodeForPackage(PostVisualisation.class));
} catch (IOException | BackingStoreException e1) {
e1.printStackTrace();
}
dialog.setVisible(false);
}
......
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.Messages;
import org.vadere.gui.components.utils.Resources;
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;
import java.util.Optional;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;