mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -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.PinDescription;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.graphics.Style;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -61,7 +62,7 @@ public class SvgTemplate implements Closeable {
|
||||
+ " xmlns=\"http://www.w3.org/2000/svg\"\n"
|
||||
+ " xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\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"
|
||||
+ " <sodipodi:namedview showgrid=\"true\">\n"
|
||||
+ " <inkscape:grid\n"
|
||||
@ -82,16 +83,20 @@ public class SvgTemplate implements Closeable {
|
||||
|
||||
int y = 0;
|
||||
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 = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private String getColor(Style style) {
|
||||
return "#" + Integer.toHexString(style.getColor().getRGB()).substring(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
w.write("</svg>\n");
|
||||
|
@ -97,7 +97,7 @@ public final class SaveAsHelper {
|
||||
* @return the file name with the given suffix
|
||||
*/
|
||||
public static File checkSuffix(File filename, String suffix) {
|
||||
if (suffix == null)
|
||||
if (suffix == null || filename == null)
|
||||
return filename;
|
||||
|
||||
String name = filename.getName();
|
||||
|
@ -58,12 +58,7 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
||||
load = new ToolTipAction(Lang.get("btn_loadSvg")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File path = null;
|
||||
if (lastSVGFile != null)
|
||||
path = lastSVGFile.getParentFile();
|
||||
JFileChooser fc = new MyFileChooser(path);
|
||||
if (lastSVGFile != null)
|
||||
fc.setSelectedFile(lastSVGFile);
|
||||
JFileChooser fc = getjFileChooser();
|
||||
if (fc.showOpenDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
||||
lastSVGFile = fc.getSelectedFile();
|
||||
try {
|
||||
@ -78,11 +73,7 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
||||
template = new ToolTipAction(Lang.get("btn_saveTemplate")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File path = null;
|
||||
if (lastSVGFile != null)
|
||||
path = lastSVGFile.getParentFile();
|
||||
JFileChooser fc = new MyFileChooser(path);
|
||||
|
||||
JFileChooser fc = getjFileChooser();
|
||||
if (fc.showSaveDialog(getAttributeDialog()) == JFileChooser.APPROVE_OPTION) {
|
||||
try {
|
||||
final Main main = getAttributeDialog().getMain();
|
||||
@ -103,6 +94,19 @@ public class CustomShapeEditor extends EditorFactory.LabelEditor<CustomShapeDesc
|
||||
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
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
|
Loading…
x
Reference in New Issue
Block a user