mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 15:58:41 -04:00
improved svg import handling
This commit is contained in:
parent
4aef42cc3d
commit
022ce57a21
@ -9,6 +9,7 @@ import de.neemann.digital.core.ObservableValues;
|
|||||||
import de.neemann.digital.core.element.Keys;
|
import de.neemann.digital.core.element.Keys;
|
||||||
import de.neemann.digital.core.element.PinDescription;
|
import de.neemann.digital.core.element.PinDescription;
|
||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
|
import de.neemann.digital.draw.graphics.Style;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -61,7 +62,7 @@ public class SvgTemplate implements Closeable {
|
|||||||
+ " xmlns=\"http://www.w3.org/2000/svg\"\n"
|
+ " xmlns=\"http://www.w3.org/2000/svg\"\n"
|
||||||
+ " xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n"
|
+ " xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n"
|
||||||
+ " xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n"
|
+ " xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n"
|
||||||
+ " viewBox=\"-" + border + " -" + border + " " + (width + border * 2) + " " + (height + border * 2) + "\"\n"
|
+ " viewBox=\"-" + border + " -" + border + " " + (width + border * 2) + " " + (height - SIZE + border * 2) + "\"\n"
|
||||||
+ " version=\"1.1\">\n"
|
+ " version=\"1.1\">\n"
|
||||||
+ " <sodipodi:namedview showgrid=\"true\">\n"
|
+ " <sodipodi:namedview showgrid=\"true\">\n"
|
||||||
+ " <inkscape:grid\n"
|
+ " <inkscape:grid\n"
|
||||||
@ -82,16 +83,20 @@ public class SvgTemplate implements Closeable {
|
|||||||
|
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (PinDescription i : inputs) {
|
for (PinDescription i : inputs) {
|
||||||
w.write(" <circle fill=\"blue\" id=\"pin+:" + i.getName() + "\" cx=\"0\" cy=\"" + y + "\" r=\"3\"/>\n");
|
w.write(" <circle fill=\"" + getColor(Style.WIRE) + "\" id=\"pin+:" + i.getName() + "\" cx=\"0\" cy=\"" + y + "\" r=\"3\"/>\n");
|
||||||
y += 20;
|
y += 20;
|
||||||
}
|
}
|
||||||
y = 0;
|
y = 0;
|
||||||
for (PinDescription o : outputs) {
|
for (PinDescription o : outputs) {
|
||||||
w.write(" <circle fill=\"red\" id=\"pin+:" + o.getName() + "\" cx=\"" + width + "\" cy=\"" + y + "\" r=\"3\"/>\n");
|
w.write(" <circle fill=\"" + getColor(Style.WIRE_OUT) + "\" id=\"pin+:" + o.getName() + "\" cx=\"" + width + "\" cy=\"" + y + "\" r=\"3\"/>\n");
|
||||||
y += 20;
|
y += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getColor(Style style) {
|
||||||
|
return "#" + Integer.toHexString(style.getColor().getRGB()).substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
w.write("</svg>\n");
|
w.write("</svg>\n");
|
||||||
|
@ -97,7 +97,7 @@ public final class SaveAsHelper {
|
|||||||
* @return the file name with the given suffix
|
* @return the file name with the given suffix
|
||||||
*/
|
*/
|
||||||
public static File checkSuffix(File filename, String suffix) {
|
public static File checkSuffix(File filename, String suffix) {
|
||||||
if (suffix == null)
|
if (suffix == null || filename == null)
|
||||||
return filename;
|
return filename;
|
||||||
|
|
||||||
String name = filename.getName();
|
String name = filename.getName();
|
||||||
|
@ -58,12 +58,7 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
|||||||
load = new ToolTipAction(Lang.get("btn_loadSvg")) {
|
load = new ToolTipAction(Lang.get("btn_loadSvg")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File path = null;
|
JFileChooser fc = getjFileChooser();
|
||||||
if (lastSVGFile != null)
|
|
||||||
path = lastSVGFile.getParentFile();
|
|
||||||
JFileChooser fc = new MyFileChooser(path);
|
|
||||||
if (lastSVGFile != null)
|
|
||||||
fc.setSelectedFile(lastSVGFile);
|
|
||||||
if (fc.showOpenDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
if (fc.showOpenDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
||||||
lastSVGFile = fc.getSelectedFile();
|
lastSVGFile = fc.getSelectedFile();
|
||||||
try {
|
try {
|
||||||
@ -78,11 +73,7 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
|||||||
template = new ToolTipAction(Lang.get("btn_saveTemplate")) {
|
template = new ToolTipAction(Lang.get("btn_saveTemplate")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File path = null;
|
JFileChooser fc = getjFileChooser();
|
||||||
if (lastSVGFile != null)
|
|
||||||
path = lastSVGFile.getParentFile();
|
|
||||||
JFileChooser fc = new MyFileChooser(path);
|
|
||||||
|
|
||||||
if (fc.showSaveDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
if (fc.showSaveDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
||||||
try {
|
try {
|
||||||
final Main main = getAttributeDialog().getMain();
|
final Main main = getAttributeDialog().getMain();
|
||||||
@ -103,6 +94,19 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JFileChooser getjFileChooser() {
|
||||||
|
File path = null;
|
||||||
|
if (lastSVGFile == null)
|
||||||
|
lastSVGFile = SaveAsHelper.checkSuffix(getAttributeDialog().getMain().getBaseFileName(), "svg");
|
||||||
|
if (lastSVGFile != null)
|
||||||
|
path = lastSVGFile.getParentFile();
|
||||||
|
|
||||||
|
JFileChooser fc = new MyFileChooser(path);
|
||||||
|
if (lastSVGFile != null)
|
||||||
|
fc.setSelectedFile(lastSVGFile);
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user