use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.
the class Main method createViewMenu.
private void createViewMenu(JMenuBar menuBar, JToolBar toolBar) {
ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) {
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.fitCircuit();
}
}.setAccelerator("F1");
ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOM_IN) {
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.scaleCircuit(1 / 0.9);
}
}.setAccelerator("control PLUS");
// enable [+] which is SHIFT+[=] on english keyboard layout
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
circuitComponent.getActionMap().put(zoomIn, zoomIn);
ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.scaleCircuit(0.9);
}
}.setAccelerator("control MINUS");
// enable [+] which is SHIFT+[=] on english keyboard layout
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK, false), zoomOut);
circuitComponent.getActionMap().put(zoomOut, zoomOut);
ToolTipAction viewHelp = new ToolTipAction(Lang.get("menu_viewHelp"), ICON_HELP) {
@Override
public void actionPerformed(ActionEvent e) {
final Circuit circuit = circuitComponent.getCircuit();
final String name = Lang.get("msg_actualCircuit");
File file = filename;
if (file == null)
file = new File(name);
try {
ElementLibrary.ElementTypeDescriptionCustom description = new ElementLibrary.ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, library), circuit);
description.setShortName(name);
description.setDescription(circuit.getAttributes().get(Keys.DESCRIPTION));
new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
} catch (PinException | NodeException e1) {
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(Main.this);
}
}
}.setToolTip(Lang.get("menu_viewHelp_tt"));
JCheckBoxMenuItem treeCheckBox = new JCheckBoxMenuItem(Lang.get("menu_treeSelect"));
treeCheckBox.setToolTipText(Lang.get("menu_treeSelect_tt"));
treeCheckBox.addActionListener(actionEvent -> {
getContentPane().remove(componentOnPane);
if (treeCheckBox.isSelected()) {
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
treeModel = new LibraryTreeModel(library);
split.setLeftComponent(new JScrollPane(new SelectTree(treeModel, circuitComponent, shapeFactory, insertHistory)));
split.setRightComponent(circuitComponent);
getContentPane().add(split);
componentOnPane = split;
} else {
if (treeModel != null) {
library.removeListener(treeModel);
treeModel = null;
}
getContentPane().add(circuitComponent);
componentOnPane = circuitComponent;
}
revalidate();
});
treeCheckBox.setAccelerator(KeyStroke.getKeyStroke("F5"));
if (Settings.getInstance().get(Keys.SETTINGS_DEFAULT_TREESELECT))
SwingUtilities.invokeLater(treeCheckBox::doClick);
toolBar.add(viewHelp.createJButtonNoText());
toolBar.add(zoomIn.createJButtonNoText());
toolBar.add(zoomOut.createJButtonNoText());
toolBar.add(maximize.createJButtonNoText());
JMenu view = new JMenu(Lang.get("menu_view"));
menuBar.add(view);
view.add(maximize.createJMenuItem());
view.add(zoomOut.createJMenuItem());
view.add(zoomIn.createJMenuItem());
view.addSeparator();
view.add(treeCheckBox);
view.addSeparator();
view.add(viewHelp.createJMenuItem());
}
use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.
the class TestAnd method testAnd.
/**
* Reads a file and sets up a model from it.
* After that the model - a simple AND gate - is tested to be a working AND gate.
*
* @throws Exception
*/
public void testAnd() throws Exception {
File filename = new File(Resources.getRoot(), "dig/and.dig");
Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
ModelCreator md = new ModelCreator(circuit, library);
Model model = md.createModel(false);
List<Node> nodes = model.getNodes();
assertEquals(1, nodes.size());
// get inputs and outputs
List<ModelEntry> inputs = md.getEntries("In");
assertEquals(2, inputs.size());
List<ModelEntry> outputs = md.getEntries("Out");
assertEquals(1, outputs.size());
// check the inputs state: the input itself has an output
assertEquals(0, inputs.get(0).getIoState().inputCount());
assertEquals(1, inputs.get(0).getIoState().outputCount());
assertEquals(0, inputs.get(1).getIoState().inputCount());
assertEquals(1, inputs.get(1).getIoState().outputCount());
// check the output state: the output itself has an input
assertEquals(1, outputs.get(0).getIoState().inputCount());
assertEquals(0, outputs.get(0).getIoState().outputCount());
// setup the test executer
TestExecuter te = new TestExecuter(model).setInputs(inputs).setOutputs(outputs);
te.check(0, 0, 0);
te.check(0, 1, 0);
te.check(1, 0, 0);
te.check(1, 1, 1);
}
use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.
the class DocuTest method writeXML.
private void writeXML(Writer w, File images, String language, File libFile) throws IOException, NodeException, PinException {
w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
w.append("<?xml-stylesheet type=\"text/xsl\" href=\"elem2html.xslt\"?>\n");
w.append("<root titel=\"").append(Lang.get("digital")).append("\" titleImage=\"").append(new File(Resources.getRoot(), "../../../screenshot.png").toURI().toString()).append("\" images=\"").append(new File(Resources.getRoot(), "docu/images/").toURI().toString()).append("\" toc=\"").append(Lang.get("tableOfContent")).append("\" lang=\"").append(language).append("\" rev=\"").append(System.getProperty("buildnumber")).append("\" revt=\"").append(Lang.get("revision")).append("\" date=\"").append(System.getProperty("buildtime")).append("\" datet=\"").append(Lang.get("date")).append("\" general=\"").append(Lang.get("general")).append("\" components=\"").append(Lang.get("menu_elements")).append("\" lib=\"").append(Lang.get("menu_library")).append("\" static=\"").append(new File(Resources.getRoot(), "docu/static_" + language + ".xml").toURI().toString()).append("\" library=\"").append(libFile.toURI().toString()).append("\">\n");
ElementLibrary library = new ElementLibrary();
ShapeFactory shapeFactory = new ShapeFactory(library, language.equals("en"));
String actPath = null;
for (ElementLibrary.ElementContainer e : library) {
String p = e.getTreePath();
if (!p.equals(actPath)) {
if (actPath != null)
w.append(" </lib>\n");
actPath = p;
w.append(" <lib name=\"").append(actPath).append("\">\n");
}
final ElementTypeDescription etd = e.getDescription();
String imageName = etd.getName() + "_" + language;
File imageFile = new File(images, imageName + ".svg");
w.append(" <element name=\"").append(escapeHTML(etd.getTranslatedName())).append("\" img=\"").append(imageFile.toURI().toString()).append("\">\n");
writeSVG(imageFile, new VisualElement(etd.getName()).setShapeFactory(shapeFactory));
final ElementAttributes attr = new ElementAttributes();
w.append(" <descr>").append(escapeHTML(etd.getDescription(attr))).append("</descr>\n");
final PinDescriptions inputDescription = etd.getInputDescription(attr);
if (!inputDescription.isEmpty()) {
w.append(" <inputs name=\"").append(Lang.get("elem_Help_inputs")).append("\">\n");
writePins(w, inputDescription);
w.append(" </inputs>\n");
}
final PinDescriptions outputDescriptions = etd.getOutputDescriptions(attr);
if (!outputDescriptions.isEmpty()) {
w.append(" <outputs name=\"").append(Lang.get("elem_Help_outputs")).append("\">\n");
writePins(w, outputDescriptions);
w.append(" </outputs>\n");
}
if (etd.getAttributeList().size() > 0) {
w.append(" <attributes name=\"").append(Lang.get("elem_Help_attributes")).append("\">\n");
for (Key k : etd.getAttributeList()) {
w.append(" <attr name=\"").append(escapeHTML(k.getName())).append("\">");
w.append(escapeHTML(k.getDescription()));
w.append("</attr>\n");
}
w.append(" </attributes>\n");
}
w.append(" </element>\n");
}
w.append(" </lib>\n");
w.append("</root>");
}
use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.
the class CircuitBuilderTest method testBuilderCombinatorial.
public void testBuilderCombinatorial() throws Exception {
Variable a = new Variable("a");
Variable b = new Variable("b");
// xor
Expression y = and(or(a, b), not(and(a, b)));
ElementLibrary library = new ElementLibrary();
Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addCombinatorial("y", y).createCircuit();
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0, 0);
te.check(0, 1, 1);
te.check(1, 0, 1);
te.check(1, 1, 0);
}
use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.
the class CircuitBuilderTest method testBuilderSequential.
public void testBuilderSequential() throws Exception {
Variable y0 = new Variable("Y_0");
Variable y1 = new Variable("Y_1");
// counter
Expression y0s = not(y0);
Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
ElementLibrary library = new ElementLibrary();
Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0);
te.checkC(1, 0);
te.checkC(0, 1);
te.checkC(1, 1);
te.checkC(0, 0);
}
Aggregations