mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 09:54:49 -04:00
Fixed a ugly RuntimeException flaw
This commit is contained in:
parent
4a5a6bab73
commit
451bd9bf8f
@ -3,6 +3,7 @@ package de.neemann.digital.core.element;
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValues;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
|
||||
/**
|
||||
* A concrete element used for the simulation
|
||||
@ -26,8 +27,9 @@ public interface Element {
|
||||
* by calling <code>setInputs()</code>
|
||||
*
|
||||
* @return the list of outputs which are set by this element
|
||||
* @throws PinException PinException
|
||||
*/
|
||||
ObservableValues getOutputs();
|
||||
ObservableValues getOutputs() throws PinException;
|
||||
|
||||
/**
|
||||
* The element has to register its nodes to the model.
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.neemann.digital.core.element;
|
||||
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@ -184,8 +185,9 @@ public class ElementTypeDescription {
|
||||
*
|
||||
* @param elementAttributes the elements attributs
|
||||
* @return the list of input descriptions
|
||||
* @throws PinException PinException
|
||||
*/
|
||||
public PinDescriptions getOutputDescriptions(ElementAttributes elementAttributes) {
|
||||
public PinDescriptions getOutputDescriptions(ElementAttributes elementAttributes) throws PinException {
|
||||
return new PinDescriptions(elementFactory.create(elementAttributes).getOutputs());
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,8 @@ public class CustomElement implements Element {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValues getOutputs() {
|
||||
try {
|
||||
return circuit.getOutputNames();
|
||||
} catch (PinException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public ObservableValues getOutputs() throws PinException {
|
||||
return circuit.getOutputNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,6 +11,7 @@ import de.neemann.digital.core.memory.RAMDualPort;
|
||||
import de.neemann.digital.core.memory.RAMSinglePort;
|
||||
import de.neemann.digital.core.pld.*;
|
||||
import de.neemann.digital.core.wiring.*;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.elements.Tunnel;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.ieee.IEEEAndShape;
|
||||
@ -157,7 +158,7 @@ public final class ShapeFactory {
|
||||
}
|
||||
|
||||
private interface Creator {
|
||||
Shape create(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) throws NodeException;
|
||||
Shape create(ElementAttributes attributes, PinDescriptions inputs, PinDescriptions outputs) throws NodeException, PinException;
|
||||
}
|
||||
|
||||
|
||||
|
@ -236,7 +236,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
||||
help.add(new ToolTipAction(Lang.get("menu_help_elements")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
new ElementHelpDialog(Main.this, library, shapeFactory).setVisible(true);
|
||||
try {
|
||||
new ElementHelpDialog(Main.this, library, shapeFactory).setVisible(true);
|
||||
} catch (NodeException|PinException e) {
|
||||
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e).show(Main.this);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_help_elements_tt")).createJMenuItem());
|
||||
|
||||
@ -282,8 +286,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
||||
.setShortName(name);
|
||||
description.setDescription(circuit.getAttributes().get(Keys.DESCRIPTION));
|
||||
new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
|
||||
} catch (PinException e1) {
|
||||
new ErrorMessage().addCause(e1).show(Main.this);
|
||||
} catch (PinException | NodeException e1) {
|
||||
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(Main.this);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_viewHelp_tt"));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
@ -21,6 +22,7 @@ import de.neemann.digital.gui.SavedListener;
|
||||
import de.neemann.digital.gui.sync.NoSync;
|
||||
import de.neemann.digital.gui.sync.Sync;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import de.neemann.gui.ErrorMessage;
|
||||
import de.neemann.gui.IconCreator;
|
||||
import de.neemann.gui.StringUtils;
|
||||
import de.neemann.gui.ToolTipAction;
|
||||
@ -566,7 +568,11 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
attributeDialog.addButton(new ToolTipAction(Lang.get("attr_help")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
new ElementHelpDialog(attributeDialog, elementType, vp.getElementAttributes()).setVisible(true);
|
||||
try {
|
||||
new ElementHelpDialog(attributeDialog, elementType, vp.getElementAttributes()).setVisible(true);
|
||||
} catch (PinException|NodeException e1) {
|
||||
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("attr_help_tt")));
|
||||
if (attributeDialog.showDialog()) {
|
||||
|
@ -2,6 +2,7 @@ package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.element.*;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
@ -38,8 +39,10 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @param parent the parents dialog
|
||||
* @param elementType the type of the element
|
||||
* @param elementAttributes the attributes of this element
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public ElementHelpDialog(JDialog parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) {
|
||||
public ElementHelpDialog(JDialog parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) throws NodeException, PinException {
|
||||
super(parent, Lang.get("attr_help"), true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
StringWriter w = new StringWriter();
|
||||
@ -57,8 +60,10 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @param parent the parents frame
|
||||
* @param elementType the type of the element
|
||||
* @param elementAttributes the attributes of this element
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public ElementHelpDialog(JFrame parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) {
|
||||
public ElementHelpDialog(JFrame parent, ElementTypeDescription elementType, ElementAttributes elementAttributes) throws NodeException, PinException {
|
||||
super(parent, Lang.get("attr_help"), true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
StringWriter w = new StringWriter();
|
||||
@ -75,8 +80,10 @@ public class ElementHelpDialog extends JDialog {
|
||||
*
|
||||
* @param parent the parents dialog
|
||||
* @param library the elements library
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) {
|
||||
public ElementHelpDialog(JFrame parent, ElementLibrary library, ShapeFactory shapeFactory) throws NodeException, PinException {
|
||||
super(parent, Lang.get("attr_help"), true);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
MyURLStreamHandlerFactory.shapeFactory = shapeFactory;
|
||||
@ -99,7 +106,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
exportHTMLDocumentation(tmp, library, shapeFactory);
|
||||
File index = new File(tmp, "index.html");
|
||||
openWebpage(index.toURI());
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | PinException | NodeException e) {
|
||||
new ErrorMessage(Lang.get("err_openingDocumentation")).addCause(e).show(ElementHelpDialog.this);
|
||||
}
|
||||
}
|
||||
@ -111,9 +118,11 @@ public class ElementHelpDialog extends JDialog {
|
||||
*
|
||||
* @param library the library which parts are documented
|
||||
* @param imageHandler the imageHandler creates the url to get the image representing a concrete part
|
||||
* @throws IOException IOException
|
||||
* @throws IOException IOException
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public static void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException {
|
||||
public static void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException {
|
||||
ArrayList<String> chapter = new ArrayList<>();
|
||||
|
||||
String actPath = null;
|
||||
@ -181,7 +190,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 {
|
||||
private static void writeDetailedDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException, NodeException, PinException {
|
||||
w.write("<html><body>");
|
||||
writeHTMLDescription(w, et, elementAttributes);
|
||||
w.write("</body></html>");
|
||||
@ -193,9 +202,11 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @param w the StringBuilder to use
|
||||
* @param et the element to describe
|
||||
* @param elementAttributes the actual attributes of the element to describe
|
||||
* @throws IOException IOException
|
||||
* @throws IOException IOException
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public static void writeHTMLDescription(Writer w, ElementTypeDescription et, ElementAttributes elementAttributes) throws IOException {
|
||||
public static 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();
|
||||
@ -204,16 +215,12 @@ public class ElementHelpDialog extends JDialog {
|
||||
if (!descr.equals(translatedName))
|
||||
w.append("<p>").append(escapeHTML(et.getDescription(elementAttributes))).append("</p>\n");
|
||||
|
||||
try {
|
||||
PinDescriptions inputs = et.getInputDescription(elementAttributes);
|
||||
if (inputs != null && inputs.size() > 0) {
|
||||
w.append("<h4>").append(Lang.get("elem_Help_inputs")).append(":</h4>\n<dl>\n");
|
||||
for (PinDescription i : inputs)
|
||||
writeEntry(w, ElementAttributes.cleanLabel(i.getName()), i.getDescription());
|
||||
w.append("</dl>\n");
|
||||
}
|
||||
} catch (NodeException e) {
|
||||
e.printStackTrace();
|
||||
PinDescriptions inputs = et.getInputDescription(elementAttributes);
|
||||
if (inputs != null && inputs.size() > 0) {
|
||||
w.append("<h4>").append(Lang.get("elem_Help_inputs")).append(":</h4>\n<dl>\n");
|
||||
for (PinDescription i : inputs)
|
||||
writeEntry(w, ElementAttributes.cleanLabel(i.getName()), i.getDescription());
|
||||
w.append("</dl>\n");
|
||||
}
|
||||
|
||||
PinDescriptions outputs = et.getOutputDescriptions(elementAttributes);
|
||||
@ -290,7 +297,7 @@ public class ElementHelpDialog extends JDialog {
|
||||
}
|
||||
|
||||
private interface ImageHandler {
|
||||
String getUrl(ElementTypeDescription description) throws IOException;
|
||||
String getUrl(ElementTypeDescription description) throws IOException, PinException, NodeException;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,9 +306,11 @@ public class ElementHelpDialog extends JDialog {
|
||||
* @param targetPath the target folder to store the documentation
|
||||
* @param library the library to use
|
||||
* @param shapeFactory the shapeFactory to export the shapes
|
||||
* @throws IOException IOException
|
||||
* @throws IOException IOException
|
||||
* @throws PinException PinException
|
||||
* @throws NodeException NodeException
|
||||
*/
|
||||
public static void exportHTMLDocumentation(File targetPath, ElementLibrary library, ShapeFactory shapeFactory) throws IOException {
|
||||
public static void exportHTMLDocumentation(File targetPath, ElementLibrary library, ShapeFactory shapeFactory) throws IOException, NodeException, PinException {
|
||||
File images = new File(targetPath, "img");
|
||||
if (!images.mkdir())
|
||||
throw new IOException("could not create image folder " + images);
|
||||
@ -317,10 +326,10 @@ public class ElementHelpDialog extends JDialog {
|
||||
+ "</head>\n<body>\n");
|
||||
|
||||
writeFullHTMLDocumentation(w, library, description -> {
|
||||
final String name = description.getName();
|
||||
BufferedImage bi = new VisualElement(name).setShapeFactory(shapeFactory).getBufferedImage(0.75, 150);
|
||||
ImageIO.write(bi, "png", new File(images, name + ".png"));
|
||||
return "img/" + name + ".png";
|
||||
final String name1 = description.getName();
|
||||
BufferedImage bi = new VisualElement(name1).setShapeFactory(shapeFactory).getBufferedImage(0.75, 150);
|
||||
ImageIO.write(bi, "png", new File(images, name1 + ".png"));
|
||||
return "img/" + name1 + ".png";
|
||||
});
|
||||
w.write("</body>\n</html>");
|
||||
}
|
||||
|
@ -469,6 +469,7 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
|
||||
<string name="msg_test_N_Failed">{0}: Fehler</string>
|
||||
<string name="msg_testExp_N0_found_N1">E: {0} / F: {1}</string>
|
||||
<string name="msg_errorSavingData">Speichern der Daten fehlgeschlagen!</string>
|
||||
<string name="msg_creatingHelp">Fehler bei der Erzeugung der Hilfe!</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
<string name="rot_180">180°</string>
|
||||
|
@ -464,6 +464,7 @@ The icons are taken from the Tango Desktop Project.</string>
|
||||
<string name="msg_test_N_Failed">{0} failed</string>
|
||||
<string name="msg_testExp_N0_found_N1">E: {0} / F: {1}</string>
|
||||
<string name="msg_errorSavingData">Error writing the data!</string>
|
||||
<string name="msg_creatingHelp">Error creating the help!</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
<string name="rot_180">180°</string>
|
||||
|
@ -118,7 +118,7 @@ public class TestExecuter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestExecuter setOutputsOf(Element element) {
|
||||
public TestExecuter setOutputsOf(Element element) throws PinException {
|
||||
setOutputs(element.getOutputs());
|
||||
return this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user