mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-29 07:50:29 -04:00
added svg export to measurement graph
This commit is contained in:
parent
58039e0d26
commit
13c9c7e7d1
@ -216,9 +216,15 @@ public class ElementAttributes {
|
|||||||
* @param file the file
|
* @param file the file
|
||||||
*/
|
*/
|
||||||
public void setFile(String fileKey, File file) {
|
public void setFile(String fileKey, File file) {
|
||||||
if (attributes == null)
|
if (file == null) {
|
||||||
attributes = new HashMap<>();
|
if (attributes != null)
|
||||||
attributes.put(fileKey, file.getPath());
|
attributes.remove(fileKey);
|
||||||
|
} else if (!file.equals(getFile(fileKey))) {
|
||||||
|
if (attributes == null)
|
||||||
|
attributes = new HashMap<>();
|
||||||
|
attributes.put(fileKey, file.getPath());
|
||||||
|
fireValueChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,8 +76,6 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
private static final String KEY_START_STOP_ACTION = "startStop";
|
private static final String KEY_START_STOP_ACTION = "startStop";
|
||||||
private static boolean experimental;
|
private static boolean experimental;
|
||||||
|
|
||||||
private static File lastExportDirectory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if experimental features are enabled
|
* @return true if experimental features are enabled
|
||||||
*/
|
*/
|
||||||
@ -1205,13 +1203,15 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
if (filename != null)
|
if (filename != null)
|
||||||
fc.setSelectedFile(SaveAsHelper.checkSuffix(filename, suffix));
|
fc.setSelectedFile(SaveAsHelper.checkSuffix(filename, suffix));
|
||||||
|
|
||||||
if (lastExportDirectory != null)
|
ElementAttributes settings = Settings.getInstance().getAttributes();
|
||||||
fc.setCurrentDirectory(lastExportDirectory);
|
File exportDir = settings.getFile("exportDirectory");
|
||||||
|
if (exportDir != null)
|
||||||
|
fc.setCurrentDirectory(exportDir);
|
||||||
|
|
||||||
fc.addChoosableFileFilter(new FileNameExtensionFilter(name, suffix));
|
fc.addChoosableFileFilter(new FileNameExtensionFilter(name, suffix));
|
||||||
new SaveAsHelper(Main.this, fc, suffix).checkOverwrite(
|
new SaveAsHelper(Main.this, fc, suffix).checkOverwrite(
|
||||||
file -> {
|
file -> {
|
||||||
lastExportDirectory = file.getParentFile();
|
settings.setFile("exportDirectory", file.getParentFile());
|
||||||
try (OutputStream out = new FileOutputStream(file)) {
|
try (OutputStream out = new FileOutputStream(file)) {
|
||||||
new Export(circuitComponent.getCircuit(), exportFactory).export(out);
|
new Export(circuitComponent.getCircuit(), exportFactory).export(out);
|
||||||
}
|
}
|
||||||
@ -1234,13 +1234,15 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
if (filename != null)
|
if (filename != null)
|
||||||
fc.setSelectedFile(SaveAsHelper.checkSuffix(filename, "gif"));
|
fc.setSelectedFile(SaveAsHelper.checkSuffix(filename, "gif"));
|
||||||
|
|
||||||
if (lastExportDirectory != null)
|
ElementAttributes settings = Settings.getInstance().getAttributes();
|
||||||
fc.setCurrentDirectory(lastExportDirectory);
|
File exportDir = settings.getFile("exportDirectory");
|
||||||
|
if (exportDir != null)
|
||||||
|
fc.setCurrentDirectory(exportDir);
|
||||||
|
|
||||||
fc.addChoosableFileFilter(new FileNameExtensionFilter(name, "gif"));
|
fc.addChoosableFileFilter(new FileNameExtensionFilter(name, "gif"));
|
||||||
new SaveAsHelper(Main.this, fc, "gif").checkOverwrite(
|
new SaveAsHelper(Main.this, fc, "gif").checkOverwrite(
|
||||||
file -> {
|
file -> {
|
||||||
lastExportDirectory = file.getParentFile();
|
settings.setFile("exportDirectory", file.getParentFile());
|
||||||
GifExporter gifExporter = new GifExporter(Main.this, circuitComponent.getCircuit(), 500, file);
|
GifExporter gifExporter = new GifExporter(Main.this, circuitComponent.getCircuit(), 500, file);
|
||||||
setDebug(false);
|
setDebug(false);
|
||||||
windowPosManager.closeAll();
|
windowPosManager.closeAll();
|
||||||
|
@ -87,4 +87,11 @@ public class GraphComponent extends JComponent {
|
|||||||
public void setScrollPane(JScrollPane scrollPane) {
|
public void setScrollPane(JScrollPane scrollPane) {
|
||||||
this.scrollPane = scrollPane;
|
this.scrollPane = scrollPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the data plotter
|
||||||
|
*/
|
||||||
|
public DataPlotter getPlotter() {
|
||||||
|
return plotter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package de.neemann.digital.gui.components.data;
|
package de.neemann.digital.gui.components.data;
|
||||||
|
|
||||||
import de.neemann.digital.core.*;
|
import de.neemann.digital.core.*;
|
||||||
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
import de.neemann.digital.data.ValueTable;
|
import de.neemann.digital.data.ValueTable;
|
||||||
|
import de.neemann.digital.draw.graphics.*;
|
||||||
import de.neemann.digital.gui.SaveAsHelper;
|
import de.neemann.digital.gui.SaveAsHelper;
|
||||||
|
import de.neemann.digital.gui.Settings;
|
||||||
import de.neemann.digital.gui.components.OrderMerger;
|
import de.neemann.digital.gui.components.OrderMerger;
|
||||||
import de.neemann.digital.gui.components.testing.ValueTableDialog;
|
import de.neemann.digital.gui.components.testing.ValueTableDialog;
|
||||||
import de.neemann.digital.gui.sync.NoSync;
|
import de.neemann.digital.gui.sync.NoSync;
|
||||||
@ -18,6 +21,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -163,6 +167,8 @@ public class GraphDialog extends JDialog implements Observer {
|
|||||||
.checkOverwrite(logData::saveCSV);
|
.checkOverwrite(logData::saveCSV);
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_saveData_tt")).createJMenuItem());
|
}.setToolTip(Lang.get("menu_saveData_tt")).createJMenuItem());
|
||||||
|
file.add(new ExportAction(Lang.get("menu_exportSVG"), GraphicSVGIndex::new).createJMenuItem());
|
||||||
|
file.add(new ExportAction(Lang.get("menu_exportSVGLaTex"), GraphicSVGLaTeX::new).createJMenuItem());
|
||||||
|
|
||||||
JMenu view = new JMenu(Lang.get("menu_view"));
|
JMenu view = new JMenu(Lang.get("menu_view"));
|
||||||
bar.add(view);
|
bar.add(view);
|
||||||
@ -198,4 +204,41 @@ public class GraphDialog extends JDialog implements Observer {
|
|||||||
showTable.setActive(false);
|
showTable.setActive(false);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class ExportAction extends ToolTipAction {
|
||||||
|
private final ExportFactory factory;
|
||||||
|
|
||||||
|
private ExportAction(String title, ExportFactory factory) {
|
||||||
|
super(title);
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
JFileChooser fileChooser = new MyFileChooser();
|
||||||
|
|
||||||
|
ElementAttributes settings = Settings.getInstance().getAttributes();
|
||||||
|
File exportDir = settings.getFile("exportDirectory");
|
||||||
|
if (exportDir != null)
|
||||||
|
fileChooser.setCurrentDirectory(exportDir);
|
||||||
|
|
||||||
|
|
||||||
|
fileChooser.setFileFilter(new FileNameExtensionFilter("SVG", "svg"));
|
||||||
|
new SaveAsHelper(GraphDialog.this, fileChooser, "svg")
|
||||||
|
.checkOverwrite(file -> {
|
||||||
|
settings.setFile("exportDirectory", file.getParentFile());
|
||||||
|
Graphic gr = factory.create(new FileOutputStream(file));
|
||||||
|
try {
|
||||||
|
GraphicMinMax minMax = new GraphicMinMax();
|
||||||
|
dsc.getPlotter().drawTo(minMax, null);
|
||||||
|
gr.setBoundingBox(minMax.getMin(), minMax.getMax());
|
||||||
|
dsc.getPlotter().drawTo(gr, null);
|
||||||
|
} finally {
|
||||||
|
if (gr instanceof Closeable)
|
||||||
|
((Closeable) gr).close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user