diff --git a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java index 84276d74d..b74fa95e8 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -1046,7 +1046,11 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib @Override public void actionPerformed(ActionEvent actionEvent) { try { - new ElementHelpDialog(attributeDialog, elementType, element.getElementAttributes()).setVisible(true); + new ElementHelpDialog( + attributeDialog, + elementType, + element.getElementAttributes(), + getCircuit().getAttributes().get(Keys.IS_GENERIC)).setVisible(true); } catch (PinException | NodeException e1) { new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this); } diff --git a/src/main/java/de/neemann/digital/gui/components/ElementHelpDialog.java b/src/main/java/de/neemann/digital/gui/components/ElementHelpDialog.java index 657275389..32f3bb2bb 100644 --- a/src/main/java/de/neemann/digital/gui/components/ElementHelpDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/ElementHelpDialog.java @@ -24,6 +24,7 @@ import java.awt.event.ActionEvent; import java.awt.image.BufferedImage; import java.io.*; import java.net.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; @@ -37,6 +38,7 @@ public class ElementHelpDialog extends JDialog { private static final int MAX_WIDTH = 600; private static final int MAX_HEIGHT = 800; + private final boolean showKeys; private JPanel buttons; @@ -50,7 +52,22 @@ public class ElementHelpDialog extends JDialog { * @throws NodeException NodeException */ public ElementHelpDialog(Window parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) throws NodeException, PinException { + this(parent, elementType, elementAttributes, false); + } + + /** + * Creates a new instance + * + * @param parent the parents frame + * @param elementType the type of the element + * @param elementAttributes the attributes of this element + * @param showKeys shows the key strings + * @throws PinException PinException + * @throws NodeException NodeException + */ + public ElementHelpDialog(Window parent, ElementTypeDescription elementType, ElementAttributes elementAttributes, boolean showKeys) throws NodeException, PinException { super(parent, Lang.get("attr_help"), ModalityType.APPLICATION_MODAL); + this.showKeys = showKeys; setDefaultCloseOperation(DISPOSE_ON_CLOSE); StringWriter w = new StringWriter(); try { @@ -72,6 +89,7 @@ public class ElementHelpDialog extends JDialog { */ public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) throws NodeException, PinException { super(parent, Lang.get("attr_help"), true); + showKeys = false; setDefaultCloseOperation(DISPOSE_ON_CLOSE); MyURLStreamHandlerFactory.setShapeFactory(shapeFactory); StringWriter w = new StringWriter(); @@ -143,7 +161,7 @@ public class ElementHelpDialog extends JDialog { * @throws PinException PinException * @throws NodeException NodeException */ - private static void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException { + private void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException { ArrayList chapter = new ArrayList<>(); String actPath = null; @@ -187,7 +205,7 @@ public class ElementHelpDialog extends JDialog { * @param et the element to describe * @param elementAttributes the actual attributes of the element to describe */ - private static void writeDetailedDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { + private void writeDetailedDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { w.write(""); writeHTMLDescription(w, et, elementAttributes); w.write(""); @@ -203,7 +221,7 @@ public class ElementHelpDialog extends JDialog { * @throws PinException PinException * @throws NodeException NodeException */ - private static void writeHTMLDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { + private void writeHTMLDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException { String translatedName = et.getTranslatedName(); if (translatedName.endsWith(".dig")) translatedName = new File(translatedName).getName(); @@ -242,18 +260,22 @@ public class ElementHelpDialog extends JDialog { } } - private static void writeEntry(Writer w, String name, String description) throws IOException { + private void writeEntry(Writer w, String name, String description) throws IOException { w.append("
").append(escapeHTML(name)).append("
\n"); if (description != null && description.length() > 0 && !name.equals(description)) w.append("
").append(escapeHTML(description)).append("
\n"); } - private static void writeEntry(Writer w, Key key) throws IOException { + private void writeEntry(Writer w, Key key) throws IOException { final String name = key.getName(); final String description = key.getDescription(); w.append("
").append(escapeHTML(name)).append("
\n"); - if (description != null && description.length() > 0 && !name.equals(description)) - w.append("
").append(escapeHTML(description)).append(" (").append(key.getKey()).append(")
\n"); + if (description != null && description.length() > 0 && !name.equals(description)) { + w.append("
").append(escapeHTML(description)); + if (showKeys) + w.append(" (").append(key.getKey()).append(')'); + w.append("
\n"); + } } /** @@ -279,7 +301,7 @@ public class ElementHelpDialog extends JDialog { if (protocol.equals("image")) return new URLStreamHandler() { @Override - protected URLConnection openConnection(URL u) throws IOException { + protected URLConnection openConnection(URL u) { return new ImageConnection(u); } }; @@ -307,7 +329,7 @@ public class ElementHelpDialog extends JDialog { } @Override - public void connect() throws IOException { + public void connect() { } @Override @@ -335,7 +357,7 @@ public class ElementHelpDialog extends JDialog { * @throws PinException PinException * @throws NodeException NodeException */ - private static void exportHTMLDocumentation(File targetPath, ElementLibrary library) throws IOException, NodeException, PinException { + private void exportHTMLDocumentation(File targetPath, ElementLibrary library) throws IOException, NodeException, PinException { File images = new File(targetPath, "img"); if (!images.mkdir()) throw new IOException("could not create image folder " + images); @@ -343,7 +365,7 @@ public class ElementHelpDialog extends JDialog { new BufferedWriter( new OutputStreamWriter( new FileOutputStream( - new File(targetPath, "index.html")), "UTF-8"))) { + new File(targetPath, "index.html")), StandardCharsets.UTF_8))) { w.write("\n" + "\n" + "\n" diff --git a/src/test/java/de/neemann/digital/integration/TestExamples.java b/src/test/java/de/neemann/digital/integration/TestExamples.java index 3f3f92583..dbf65cc09 100644 --- a/src/test/java/de/neemann/digital/integration/TestExamples.java +++ b/src/test/java/de/neemann/digital/integration/TestExamples.java @@ -43,8 +43,8 @@ public class TestExamples extends TestCase { */ public void testTestExamples() throws Exception { File examples = new File(Resources.getRoot(), "/dig/test"); - assertEquals(164, new FileScanner(this::check).scan(examples)); - assertEquals(161, testCasesInFiles); + assertEquals(166, new FileScanner(this::check).scan(examples)); + assertEquals(162, testCasesInFiles); } /** diff --git a/src/test/resources/dig/test/generics/countSplitter.dig b/src/test/resources/dig/test/generics/countSplitter.dig new file mode 100644 index 000000000..26a09cf0a --- /dev/null +++ b/src/test/resources/dig/test/generics/countSplitter.dig @@ -0,0 +1,216 @@ + + + 1 + + + isGeneric + true + + + + + Counter + + + Bits + 2 + + + generic + this.Bits=int(args.bits); + + + + + + Counter + + + Bits + 2 + + + generic + this.Bits=int(args.bits); + + + + + + Ground + + + + + Ground + + + + + In + + + Label + en + + + + + + Splitter + + + Input Splitting + 2,2 + + + Output Splitting + 4 + + + generic + this.'Output Splitting'=""+(args.bits*2); +this.'Input Splitting'=args.bits+","+args.bits; + + + + + + Out + + + Label + d + + + Bits + 4 + + + generic + this.Bits=int(args.bits); + + + + + + Out + + + Label + ov + + + + + + Clock + + + runRealTime + true + + + Label + C + + + Frequency + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/dig/test/generics/mainSplitter.dig b/src/test/resources/dig/test/generics/mainSplitter.dig new file mode 100644 index 000000000..06f184708 --- /dev/null +++ b/src/test/resources/dig/test/generics/mainSplitter.dig @@ -0,0 +1,164 @@ + + + 1 + + + + Clock + + + runRealTime + true + + + Label + C + + + Frequency + 5 + + + + + + VDD + + + + + Splitter + + + Input Splitting + 4,6 + + + Output Splitting + 10 + + + + + + Out + + + Label + O + + + Bits + 10 + + + intFormat + hex + + + + + + Testcase + + + Testdata + + C O +loop(n,1024) +C (n+1) +end loop + + + + + + + countSplitter.dig + + + generic + bits:=2; + + + + + + countSplitter.dig + + + generic + bits:=3; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file