Commit f67c675c authored by JxDannyxJ's avatar JxDannyxJ

The Preferences.userNodeForPackage map returned the path specified with a dot...

The Preferences.userNodeForPackage map returned the path specified with a dot at the end of the path.
Which resulted in a malformed path string without any critical effect.

To boost the usability of the Image and Video export a filechooser has been included, where the default name of the exported data fits the previously optionless default name
parent 86ddc46c
VadereGui/resources/icons/stop_record.png

5.84 KB | W: | H:

VadereGui/resources/icons/stop_record.png

884 Bytes | W: | H:

VadereGui/resources/icons/stop_record.png
VadereGui/resources/icons/stop_record.png
VadereGui/resources/icons/stop_record.png
VadereGui/resources/icons/stop_record.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -11,8 +11,6 @@ import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.ImageGenerator;
import org.vadere.gui.postvisualization.view.ImageSizeDialog;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -21,6 +19,9 @@ 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 = LogManager.getLogger(ActionGeneratePNG.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -40,21 +41,32 @@ public class ActionGeneratePNG extends AbstractAction implements IRendererChange
ImageSizeDialog imageSizeDialog = new ImageSizeDialog(model);
if (imageSizeDialog.getState() == ImageSizeDialog.State.Ok) {
BufferedImage bi = generator.generateImage(imageSizeDialog.getImageBound());
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", "."));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("View.dataFormat"));
String formattedDate = formatter.format(todaysDate);
File outputfile = new File(
Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", ".")
+ System.getProperty("file.separator") + "pv_snapshot_" + formattedDate + ".png");
try {
ImageIO.write(bi, "png", outputfile);
logger.info("generate new png: " + outputfile.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
File outputFile = new File("pv_snapshot_" + formattedDate + ".png");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".png") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".png");
BufferedImage bi = generator.generateImage(imageSizeDialog.getImageBound());
try {
ImageIO.write(bi, "png", outputFile);
logger.info("generate new png: " + outputFile.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
}
}
}
}
......
......@@ -8,17 +8,16 @@ 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.utils.SVGGenerator;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
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 = LogManager.getLogger(ActionGenerateSVG.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -37,10 +36,21 @@ public class ActionGenerateSVG extends AbstractAction implements IRendererChange
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("View.dataFormat"));
String formattedDate = formatter.format(todaysDate);
File outputfile = new File(
Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", ".")
+ System.getProperty("file.separator") + "pv_snapshot_" + formattedDate + ".svg");
svgGenerator.generateSVG(outputfile);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", "."));
File outputFile = new File("pv_snapshot_" + formattedDate + ".svg");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".svg") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".svg");
svgGenerator.generateSVG(outputFile);
}
}
@Override
......
package org.vadere.gui.postvisualization.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.ImageGenerator;
import org.vadere.gui.postvisualization.view.ImageSizeDialog;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -11,14 +19,6 @@ import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.*;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.ImageGenerator;
import org.vadere.gui.postvisualization.view.ImageSizeDialog;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
public class ActionGeneratePNG extends ActionVisualization {
private static Logger logger = LogManager.getLogger(ActionGeneratePNG.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -35,21 +35,32 @@ public class ActionGeneratePNG extends ActionVisualization {
ImageSizeDialog imageSizeDialog = new ImageSizeDialog(model);
if (imageSizeDialog.getState() == ImageSizeDialog.State.Ok) {
BufferedImage bi = generator.generateImage(imageSizeDialog.getImageBound());
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", "."));
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("View.dataFormat"));
String formattedDate = formatter.format(todaysDate);
File outputfile = new File(
Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", ".")
+ System.getProperty("file.separator") + "pv_snapshot_" + formattedDate + ".png");
try {
ImageIO.write(bi, "png", outputfile);
logger.info("generate new png: " + outputfile.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
File outputFile = new File("pv_snapshot_" + formattedDate + ".png");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".png") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".png");
BufferedImage bi = generator.generateImage(imageSizeDialog.getImageBound());
try {
ImageIO.write(bi, "png", outputFile);
logger.info("generate new png: " + outputFile.getAbsolutePath());
} catch (IOException e1) {
logger.error(e1.getMessage());
e1.printStackTrace();
}
}
}
}
......
package org.vadere.gui.postvisualization.control;
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.Icon;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Resources;
......@@ -15,6 +7,14 @@ import org.vadere.gui.postvisualization.PostVisualisation;
import org.vadere.gui.postvisualization.utils.SVGGenerator;
import org.vadere.gui.postvisualization.view.PostvisualizationRenderer;
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 ActionVisualization {
private static Logger logger = LogManager.getLogger(ActionGenerateSVG.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -30,9 +30,19 @@ public class ActionGenerateSVG extends ActionVisualization {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("View.dataFormat"));
String formattedDate = formatter.format(todaysDate);
File outputfile = new File(
Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", ".")
+ System.getProperty("file.separator") + "pv_snapshot_" + formattedDate + ".svg");
svgGenerator.generateSVG(outputfile);
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", "."));
File outputFile = new File("pv_snapshot_" + formattedDate + ".svg");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".svg") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".svg");
svgGenerator.generateSVG(outputFile);
}
}
}
......@@ -2,6 +2,8 @@ package org.vadere.gui.postvisualization.utils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.lf5.LogLevel;
import org.jcodec.api.awt.SequenceEncoder;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.postvisualization.PostVisualisation;
......@@ -17,6 +19,8 @@ import java.util.Date;
import java.util.Observable;
import java.util.prefs.Preferences;
import javax.swing.*;
public class MovRecorder implements IRecorder {
private static Logger logger = LogManager.getLogger(MovRecorder.class);
private static Resources resources = Resources.getInstance("postvisualization");
......@@ -61,7 +65,11 @@ public class MovRecorder implements IRecorder {
@Override
public synchronized void stopRecording() throws IOException {
enc.finish();
try {
enc.finish();
} catch (IndexOutOfBoundsException error) {
logger.log(Priority.DEBUG, "Nothing recorded! " + error.getMessage());
}
logger.info(this + " stop recording");
}
......@@ -77,15 +85,25 @@ public class MovRecorder implements IRecorder {
Date todaysDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat(resources.getProperty("View.dataFormat"));
String formattedDate = formatter.format(todaysDate);
try {
this.enc = new SequenceEncoder(new File(
Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", ".")
+ System.getProperty("file.separator") + "pv_snapshot_" + formattedDate + ".mov"));
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
JFileChooser fileChooser = new JFileChooser(Preferences.userNodeForPackage(PostVisualisation.class).get("PostVis.snapshotDirectory.path", "."));
File outputFile = new File("pv_snapshot_" + formattedDate + ".mov");
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
if (returnVal == JFileChooser.APPROVE_OPTION) {
outputFile = fileChooser.getSelectedFile().toString().endsWith(".mov") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".mov");
try {
this.enc = new SequenceEncoder(outputFile);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
logger.info(this + " start recording");
}
logger.info(this + " start recording");
}
@Override
......
Markdown is supported
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