Commit b6e97efa 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 fa56b36b
Pipeline #121385 passed with stages
in 118 minutes and 43 seconds
......@@ -3,10 +3,10 @@ Target.color=#00FF00
Source.color=#00FFFF
Pedestrian.color=#0000FF
Density.measurementscale=10.0
Density.measurementradius=15
Density.standardderivation=0.5
Pedestrian.Radius=0.195
Density.measurementScale=10.0
Density.measurementRadius=15
Density.standardDeviation=0.5
Pedestrian.radius=0.195
Toolbar.size=40
Logo.show=false
......
......@@ -376,3 +376,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
......@@ -370,4 +370,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
......@@ -2,10 +2,9 @@ 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.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
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;
......@@ -26,7 +25,7 @@ import javax.swing.*;
public class ActionGeneratePNG extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGeneratePNG.class);
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private ImageGenerator generator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......
......@@ -3,10 +3,9 @@ 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.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
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;
......@@ -23,7 +22,7 @@ import javax.swing.*;
public class ActionGenerateSVG extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGenerateSVG.class);
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private final SVGGenerator svgGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......
......@@ -3,10 +3,9 @@ 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.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
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;
......@@ -23,7 +22,7 @@ import javax.swing.*;
public class ActionGenerateTikz extends AbstractAction implements IRendererChangeListener {
private static Logger logger = Logger.getLogger(ActionGenerateTikz.class);
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private final TikzGenerator tikzGenerator;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......
......@@ -9,13 +9,12 @@ import javax.swing.JTextField;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.gui.components.utils.Resources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.postvisualization.PostVisualisation;
public class ActionSetSnapshotDirectory extends ActionVisualization {
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("PostVis");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private final JTextField textField;
......
......@@ -6,19 +6,18 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.gui.components.utils.Resources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.visualization.ColorHelper;
public class DefaultSimulationConfig extends DefaultConfig {
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private boolean showLogo = CONFIG.getBoolean("Logo.show");
private double densityScale = CONFIG.getDouble("Density.measurementscale");
private double densityMeasurementRadius = CONFIG.getDouble("Density.measurementradius");
private double densityStandardDerivation = CONFIG.getDouble("Density.standardderivation");
private double pedestrianTorso = CONFIG.getDouble("Pedestrian.Radius") * 2;
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;
......
......@@ -5,6 +5,8 @@ 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 java.awt.geom.Rectangle2D;
......@@ -21,7 +23,7 @@ import javax.swing.*;
public class Recorder implements IRecorder {
private static Logger logger = Logger.getLogger(Recorder.class);
private SequenceEncoder enc;
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
@Override
public void startRecording() {
......
......@@ -9,6 +9,8 @@ import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.*;
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 java.awt.*;
......@@ -25,7 +27,7 @@ import javax.swing.*;
*/
public class SettingsDialog extends JDialog {
private static Logger logger = Logger.getLogger(SettingsDialog.class);
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private DefaultSimulationConfig config;
private List<JButton> targetColorButtons;
......
......@@ -3,9 +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.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
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;
......
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.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
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;
......@@ -38,8 +30,7 @@ public class MainPanel extends ScaleablePanel implements Observer {
private OnlinevisualizationRenderer renderer;
private final OnlineVisualizationModel model;
private List<IRendererChangeListener> rendererChangeListeners;
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static Resources resources = Resources.getInstance("global");
private IMode selectionMode = null;
/** Creates a new main panel. */
......@@ -120,7 +111,7 @@ public class MainPanel extends ScaleablePanel implements Observer {
public void preLoop() {
this.renderer = new OnlinevisualizationRenderer(model);
renderer.setLogo(CONFIG.getImage("vadere.png"));
resources.getImage("vadere.png");
setRenderer(renderer);
rendererChangeListeners.stream().forEach(l -> l.update(renderer));
}
......
......@@ -21,6 +21,8 @@ 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 java.awt.*;
import java.awt.event.ActionEvent;
......@@ -33,7 +35,8 @@ import javax.swing.*;
public class OnlineVisualisationWindow extends JPanel implements Observer {
private static final long serialVersionUID = 3522170593760789565L;
private static final ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("Global");
private static final Resources resources = Resources.getInstance("global");
private static final IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private ScenarioElementView jsonPanel;
private JToolBar toolbar;
private SimulationInfoPanel infoPanel;
......@@ -67,6 +70,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
// toolbar.setBorderPainted(false);
toolbar.setAlignmentX(Component.LEFT_ALIGNMENT);
toolbar.setAlignmentY(Component.TOP_ALIGNMENT);
// TODO: Should this be really configurable in a config file?
int toolbarSize = CONFIG.getInt("Toolbar.size");
toolbar.setPreferredSize(new Dimension(toolbarSize, toolbarSize));
......@@ -77,12 +81,11 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
setLayout(spiltLayout);
// 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", CONFIG.getIcon("settings.png", iconWidth, iconHeight), model) {
AbstractAction openSettingsDialog = new ActionVisualization("settings", resources.getIcon("settings.png", iconWidth, iconHeight), model) {
@Override
public void actionPerformed(ActionEvent e) {
DialogFactory.createSettingsDialog(model).setVisible(true);
......@@ -91,7 +94,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
AbstractAction paintArrowAction = new AbstractAction("paintArrowAction",
CONFIG.getIcon("walking_direction.png", iconWidth, iconHeight)) {
resources.getIcon("walking_direction.png", iconWidth, iconHeight)) {
private static final long serialVersionUID = 14131313L;
......@@ -103,7 +106,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
AbstractAction paintPedestriansAction = new AbstractAction("paintPedestrianAction",
CONFIG.getIcon("pedestrian.png", iconWidth, iconHeight)) {
resources.getIcon("pedestrian.png", iconWidth, iconHeight)) {
private static final long serialVersionUID = 14131313L;
......@@ -115,7 +118,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
AbstractAction showGroupInformationAction = new AbstractAction("showGroupInformationAction",
CONFIG.getIcon("group.png", iconWidth, iconHeight)) {
resources.getIcon("group.png", iconWidth, iconHeight)) {
@Override
public void actionPerformed(ActionEvent e) {
model.config.setShowGroups(!model.config.isShowGroups());
......@@ -123,13 +126,13 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
}
};
AbstractAction drawVoronoiDiagram = new ActionSwapSelectionMode("draw_voronoi_diagram", CONFIG.getIcon("voronoi.png", iconWidth, iconHeight), model);
AbstractAction drawVoronoiDiagram = new ActionSwapSelectionMode("draw_voronoi_diagram", resources.getIcon("voronoi.png", iconWidth, iconHeight), model);
AbstractAction drawMesh = new ActionShowMesh("draw_mesh", CONFIG.getIcon("triangulation.png", iconWidth, iconHeight), model);
AbstractAction drawMesh = new ActionShowMesh("draw_mesh", resources.getIcon("triangulation.png", iconWidth, iconHeight), model);
AbstractAction paintGridAction = new AbstractAction("paintGridAction",
CONFIG.getIcon("grid.png", iconWidth, iconHeight)) {
resources.getIcon("grid.png", iconWidth, iconHeight)) {
private static final long serialVersionUID = 1123132132L;
......@@ -141,7 +144,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
AbstractAction paintTrajectories = new AbstractAction("paintTrajectoriesAction",
CONFIG.getIcon("trajectories.png", iconWidth, iconHeight)) {
resources.getIcon("trajectories.png", iconWidth, iconHeight)) {
private static final long serialVersionUID = 1123132132L;
......@@ -153,7 +156,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
AbstractAction paintDensity = new AbstractAction("paintDensityAction",
CONFIG.getIcon("density.png", iconWidth, iconHeight)) {
resources.getIcon("density.png", iconWidth, iconHeight)) {
private static final long serialVersionUID = 1123132132L;
......@@ -165,29 +168,29 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
};
OnlinevisualizationRenderer renderer = new OnlinevisualizationRenderer(model);
renderer.setLogo(CONFIG.getImage("vadere.png"));
renderer.setLogo(resources.getImage("vadere.png"));
ActionGeneratePNG generatePNG = new ActionGeneratePNG(
Messages.getString("ProjectView.btnPNGSnapshot.tooltip"),
CONFIG.getIcon("camera_png.png", iconWidth, iconHeight),
resources.getIcon("camera_png.png", iconWidth, iconHeight),
renderer,
model);
ActionGenerateSVG generateSVG = new ActionGenerateSVG(
Messages.getString("ProjectView.btnSVGSnapshot.tooltip"),
CONFIG.getIcon("camera_svg.png", iconWidth, iconHeight),
resources.getIcon("camera_svg.png", iconWidth, iconHeight),
renderer,
model);
ActionGenerateTikz generateTikz = new ActionGenerateTikz(
Messages.getString("ProjectView.btnTikZSnapshot.tooltip"),
CONFIG.getIcon("camera_tikz.png", iconWidth, iconHeight),
resources.getIcon("camera_tikz.png", iconWidth, iconHeight),
renderer,
model);
ActionShowPotentialField showPotentialField = new ActionShowPotentialField(
"showPotentialField",
CONFIG.getIcon("potentialField.png", iconWidth, iconHeight),
resources.getIcon("potentialField.png", iconWidth, iconHeight),
model);
mainPanel.addRendererChangeListener(generatePNG);
......@@ -223,7 +226,7 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
ActionOnlineVisMenu imgDialog = new ActionOnlineVisMenu(
"camera_menu",
CONFIG.getIcon("camera.png", iconWidth, iconHeight), imgOptions);
resources.getIcon("camera.png", iconWidth, iconHeight), imgOptions);
JButton imgMenuBtn =
SwingUtils.addActionToToolbar(toolbar, imgDialog, Messages.getString("ProjectView.btnSnapshot.tooltip"));
imgDialog.setParent(imgMenuBtn);
......
......@@ -2,10 +2,9 @@ package org.vadere.gui.postvisualization.control;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
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;
......@@ -25,7 +24,7 @@ import javax.swing.*;
public class ActionOpenFile extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionOpenFile.class);
private static ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("PostVis");
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private final PostvisualizationModel model;
private String path = null;
......
package org.vadere.gui.postvisualization.control;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
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;
......@@ -18,7 +18,9 @@ import javax.swing.*;
public class ActionRecording extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionRecording.class);
private static ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("PostVis");
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("Global");
private static Resources resources = Resources.getInstance("postvisualization");
private final PostvisualizationModel model;
private JButton button;
private final int iconWidth;
......@@ -45,7 +47,7 @@ public class ActionRecording extends ActionVisualization {
logger.warn("recording failed.");
}
finally {
button.setIcon(CONFIG.getIcon("record.png", iconWidth, iconHeight));
button.setIcon(resources.getIcon("record.png", iconWidth, iconHeight));
model.config.setRecording(!model.config.isRecording());
}
......@@ -59,7 +61,7 @@ public class ActionRecording extends ActionVisualization {
logger.warn("start recording failed.");
}
finally {
button.setIcon(CONFIG.getIcon("stop_record.png", iconWidth, iconHeight));
button.setIcon(resources.getIcon("stop_record.png", iconWidth, iconHeight));
model.config.setRecording(!model.config.isRecording());
}
}
......
......@@ -2,9 +2,8 @@ package org.vadere.gui.postvisualization.control;
import org.vadere.gui.components.control.simulation.ActionVisualization;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.gui.components.utils.Resources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
import org.vadere.gui.components.view.DialogFactory;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.gui.postvisualization.utils.PotentialFieldContainer;
......@@ -19,7 +18,7 @@ import javax.swing.*;
public class ActionShowPotentialField extends ActionVisualization {
private static Logger logger = Logger.getLogger(ActionShowPotentialField.class);
private static ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("PostVis");
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private final PostvisualizationModel model;
public ActionShowPotentialField(final String name, final Icon icon, final PostvisualizationModel model) {
......
......@@ -3,13 +3,12 @@ package org.vadere.gui.postvisualization.model;
import java.util.*;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.utils.ConfigurationSection;
import org.vadere.gui.components.utils.ExperimentalResources;
import org.vadere.gui.components.utils.Resources;
import org.vadere.util.config.IConfigSection;
import org.vadere.util.config.VadereConfig;
public class PostvisualizationConfig extends DefaultSimulationConfig {
private static ConfigurationSection CONFIG = ExperimentalResources.getInstance().getSection("PostVis");
private static IConfigSection CONFIG = VadereConfig.getInstance().getSection("PostVis");
private boolean recording = false;
private boolean showAllTrajectories = true;
......
......@@ -3,6 +3,7 @@ package org.vadere.gui.postvisualization.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import org.openide.NotifyDescriptor;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.Messages;
......@@ -36,7 +37,7 @@ public class ImageSizeDialog extends JDialog {
this.model = model;
this.imageSize = new Rectangle2D.Double(0, 0, ImageGenerator.calculateOptimalWidth(model),
ImageGenerator.calculateOptimalHeight(model));
this.setTitle(resources.getProperty("ImageSizeDialog.title"));
this.setTitle(Messages.getString("ImageSizeDialog.title"));
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.addWindowListener(
new WindowAdapter() {
......@@ -54,7 +55,7 @@ public class ImageSizeDialog extends JDialog {
getContentPane().setLayout(mainLayout);
JLabel lblWidth = new JLabel(resources.getProperty("ImageSizeDialog.lblWidth.text") + ":");
JLabel lblWidth = new JLabel(Messages.getString("ImageSizeDialog.lblWidth.text") + ":");
final JSpinner spinnerWidth = new JSpinner();
sModelImageWidth = new SpinnerNumberModel(ImageGenerator.calculateOptimalWidth(model), 1, 5000, 1);
spinnerWidth.setModel(sModelImageWidth);
......@@ -65,7 +66,7 @@ public class ImageSizeDialog extends JDialog {
getContentPane().add(new JLabel("px"), cc.xy(6, 2));
JLabel lblHeight = new JLabel(resources.getProperty("ImageSizeDialog.lblHeight.text") + ":");
JLabel lblHeight = new JLabel(Messages.getString("ImageSizeDialog.lblHeight.text") + ":");
final JSpinner spinnerHeight = new JSpinner();
sModelImageHeight = new SpinnerNumberModel(ImageGenerator.calculateOptimalHeight(model), 1, 5000, 1);
spinnerHeight.setModel(sModelImageHeight);
......
package org.vadere.gui.components.utils;
package org.vadere.util.config;
import javax.swing.*;
import java.awt.image.BufferedImage;
public interface ConfigurationSection {
/**
* 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);
BufferedImage getImage(final String name);
Icon getIcon(final String name, final int iconWidth, final int iconHeight);
}
package org.vadere.gui.components.utils;
package org.vadere.util.config;
import org.apache.commons.configuration2.SubnodeConfiguration;
import org.vadere.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class INIConfigurationSection implements ConfigurationSection {
private static final Logger logger = Logger.getLogger(INIConfigurationSection.class);
public class IniConfigSection implements IConfigSection {
// Variables
private final SubnodeConfiguration configuration;
public INIConfigurationSection(SubnodeConfiguration section) {
// Constructors
public IniConfigSection(SubnodeConfiguration section) {
this.configuration = section;
}
// Methods
@Override
public boolean getBoolean(String key) {
return configuration.getBoolean(decorate(key));
......@@ -42,23 +38,4 @@ public class INIConfigurationSection implements ConfigurationSection {
public void set(String key, Object value) {
configuration.setProperty(decorate(key), value);
}
@Override
public BufferedImage getImage(String name) {
try {
return ImageIO.read(Resources.class.getResource("/images/" + name));
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
return null;
}
@Override
public Icon getIcon(String name, int iconWidth, int iconHeight) {
ImageIcon icon = new ImageIcon(Resources.class.getResource("/icons/" + name));
Image img = icon.getImage().getScaledInstance(iconWidth, iconHeight, java.awt.Image.SCALE_AREA_AVERAGING);
return new ImageIcon(img);
}
}
package org.vadere.gui.components.utils;
package org.vadere.util.config;
import org.apache.commons.configuration2.INIConfiguration;
import org.apache.commons.configuration2.SubnodeConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.tools.ant.taskdefs.Manifest;
import org.vadere.util.logging.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.stream.Stream;
public class ExperimentalResources {
/**
* A Vadere config reads its values from an INI-based text file which is divided into sections.
*
* An input looks like this:
*
* <pre>
* [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>
*/
public class VadereConfig {
private static final Logger logger = Logger.getLogger(ExperimentalResources.class);
private static final String RESOURCE_PATH = "VadereGui/target/config.ini";
private static final ExperimentalResources INSTANCE = new ExperimentalResources(RESOURCE_PATH);
public static ExperimentalResources getInstance() {
return INSTANCE;
}
// Static Variables
private static final Logger logger = Logger.getLogger(VadereConfig.class);
// TODO: Define concept to read and write config file, i.e.:
// - Where is config file stored? "%AppData%" in Windows? "~/.config/" in GNU/Linux?
// - Write default config file if no config file exists.
// - Add flag "--config-file <path/to/file> to all(!) Vadere applications?
private static final String PATH_TO_CONFIG = "./config.ini";
private static final VadereConfig SINGLETON_INSTANCE = new VadereConfig(PATH_TO_CONFIG);
// Variables
private final INIConfiguration configuration;
private final HashMap<String, IConfigSection> configSections;
private final HashMap<String, ConfigurationSection> map;
public ExperimentalResources(String path) {
// Constructors
public VadereConfig(String path) {
configuration = new INIConfiguration();
map = new HashMap<>();
configSections = new HashMap<>();
try {
configuration.read(Files.newBufferedReader(Paths.get(path)));
} catch (ConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
// TODO: Use default config if exception occurs.
} catch (ConfigurationException ex) {
logger.error("Error in config file \"%s\": ", PATH_TO_CONFIG, ex.getMessage());
logger.info("Create and use default config");
} catch (IOException ex) {
logger.error(String.format("Error while reading config file \"%s\": %s", PATH_TO_CONFIG, ex.getMessage()));
logger.info("Create and use default config");
}