Translated name is also shown in circuit pane

This commit is contained in:
hneemann 2016-04-15 10:34:41 +02:00
parent e903f427ff
commit ef6d88a4a1
7 changed files with 52 additions and 20 deletions

View File

@ -33,6 +33,10 @@
<visualElement> <visualElement>
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry>
<string>Description</string>
<string>Setzen</string>
</entry>
<entry> <entry>
<string>Label</string> <string>Label</string>
<string>J</string> <string>J</string>
@ -117,6 +121,10 @@
<visualElement> <visualElement>
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry>
<string>Description</string>
<string>Rücksetzen</string>
</entry>
<entry> <entry>
<string>Label</string> <string>Label</string>
<string>K</string> <string>K</string>

View File

@ -1,6 +1,7 @@
package de.neemann.digital.core.element; package de.neemann.digital.core.element;
import de.neemann.digital.core.NodeException; import de.neemann.digital.core.NodeException;
import de.neemann.digital.lang.Lang;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,6 +15,7 @@ import java.util.ArrayList;
*/ */
public class ElementTypeDescription { public class ElementTypeDescription {
private final String name; private final String name;
private final String translatedName;
private String shortName; private String shortName;
private final ElementFactory elementFactory; private final ElementFactory elementFactory;
private final PinDescription[] inputPins; private final PinDescription[] inputPins;
@ -60,7 +62,10 @@ public class ElementTypeDescription {
*/ */
public ElementTypeDescription(String name, ElementFactory elementFactory, PinDescription... inputPins) { public ElementTypeDescription(String name, ElementFactory elementFactory, PinDescription... inputPins) {
this.name = name; this.name = name;
this.shortName = name; this.shortName = null;
String n = Lang.getNull("elem_" + name);
if (n != null) this.translatedName = n;
else this.translatedName = name;
this.elementFactory = elementFactory; this.elementFactory = elementFactory;
this.inputPins = inputPins; this.inputPins = inputPins;
for (PinDescription p : inputPins) for (PinDescription p : inputPins)
@ -76,9 +81,19 @@ public class ElementTypeDescription {
* @return the shortname * @return the shortname
*/ */
public String getShortName() { public String getShortName() {
if (shortName == null)
return getTranslatedName();
else
return shortName; return shortName;
} }
/**
* @return returns the translated element name
*/
public String getTranslatedName() {
return translatedName;
}
/** /**
* Sets a short name which should be used to draw it on the shape. * Sets a short name which should be used to draw it on the shape.
* *
@ -109,9 +124,9 @@ public class ElementTypeDescription {
* @return the description * @return the description
*/ */
public String getDescription(ElementAttributes elementAttributes) { public String getDescription(ElementAttributes elementAttributes) {
if (description == null) if (description == null) {
return name; return translatedName;
else } else
return description; return description;
} }

View File

@ -5,6 +5,7 @@ import de.neemann.digital.core.element.AttributeKey;
import de.neemann.digital.core.element.Element; import de.neemann.digital.core.element.Element;
import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.ElementTypeDescription; import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.lang.Lang;
import java.io.File; import java.io.File;
@ -24,7 +25,9 @@ public class ROM extends Node implements Element {
/** /**
* The ROMs {@link ElementTypeDescription} * The ROMs {@link ElementTypeDescription}
*/ */
public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(ROM.class, input("A"), input("sel")) public static final ElementTypeDescription DESCRIPTION = new ElementTypeDescription(ROM.class,
input("A", Lang.get("elem_ROM_pin_address")),
input("sel", Lang.get("elem_ROM_pin_sel")))
.addAttribute(AttributeKey.Rotate) .addAttribute(AttributeKey.Rotate)
.addAttribute(AttributeKey.Bits) .addAttribute(AttributeKey.Bits)
.addAttribute(AttributeKey.AddrBits) .addAttribute(AttributeKey.AddrBits)
@ -51,7 +54,7 @@ public class ROM extends Node implements Element {
*/ */
public ROM(ElementAttributes attr) { public ROM(ElementAttributes attr) {
int bits = attr.get(AttributeKey.Bits); int bits = attr.get(AttributeKey.Bits);
output = new ObservableValue("D", bits, true); output = new ObservableValue("D", bits, true).setDescription(Lang.get("elem_ROM_pin_data"));
data = attr.get(AttributeKey.Data); data = attr.get(AttributeKey.Data);
addrBits = attr.get(AttributeKey.AddrBits); addrBits = attr.get(AttributeKey.AddrBits);
showList = attr.get(AttributeKey.ShowListing); showList = attr.get(AttributeKey.ShowListing);

View File

@ -90,7 +90,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
private void add(ElementTypeDescription description, String treePath) { private void add(ElementTypeDescription description, String treePath) {
addDescription(description); addDescription(description);
list.add(new ElementContainer(description.getName(), treePath)); list.add(new ElementContainer(description, treePath));
} }
/** /**
@ -151,24 +151,23 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
* Used to store a elements name and its position in the elements menu. * Used to store a elements name and its position in the elements menu.
*/ */
public static class ElementContainer { public static class ElementContainer {
private final String name; private final ElementTypeDescription name;
private final String treePath; private final String treePath;
/** /**
* Creates anew instance * Creates anew instance
* * @param typeDescription the elements typeDescription
* @param name the elements name
* @param treePath the elements menu path * @param treePath the elements menu path
*/ */
public ElementContainer(String name, String treePath) { public ElementContainer(ElementTypeDescription typeDescription, String treePath) {
this.name = name; this.name = typeDescription;
this.treePath = treePath; this.treePath = treePath;
} }
/** /**
* @return the elements name * @return the elements name
*/ */
public String getName() { public ElementTypeDescription getDescription() {
return name; return name;
} }

View File

@ -106,8 +106,8 @@ public class LibrarySelector implements ElementNotFoundNotification {
parts.add(subMenu); parts.add(subMenu);
lastPath = path; lastPath = path;
} }
subMenu.add(new InsertAction(elementContainer.getName(), insertHistory, circuitComponent) subMenu.add(new InsertAction(elementContainer.getDescription(), insertHistory, circuitComponent)
.setToolTip(createToolTipText(elementContainer.getName())) .setToolTip(createToolTipText(elementContainer.getDescription().getTranslatedName()))
.createJMenuItem()); .createJMenuItem());
} }
@ -148,9 +148,9 @@ public class LibrarySelector implements ElementNotFoundNotification {
private final InsertHistory insertHistory; private final InsertHistory insertHistory;
private final CircuitComponent circuitComponent; private final CircuitComponent circuitComponent;
private InsertAction(String name, InsertHistory insertHistory, CircuitComponent circuitComponent) { private InsertAction(ElementTypeDescription typeDescription, InsertHistory insertHistory, CircuitComponent circuitComponent) {
super(createShortName(name), new VisualElement(name).setShapeFactory(shapeFactory).createIcon(75)); super(typeDescription.getTranslatedName(), new VisualElement(typeDescription.getName()).setShapeFactory(shapeFactory).createIcon(75));
this.name = name; this.name = typeDescription.getName();
this.insertHistory = insertHistory; this.insertHistory = insertHistory;
this.circuitComponent = circuitComponent; this.circuitComponent = circuitComponent;
} }
@ -175,7 +175,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
.setShortName(createShortName(file)); .setShortName(createShortName(file));
library.addDescription(description); library.addDescription(description);
InsertAction insertAction = new InsertAction(description.getName(), insertHistory, circuitComponent); InsertAction insertAction = new InsertAction(description, insertHistory, circuitComponent);
String descriptionText = circuit.getAttributes().get(AttributeKey.Description); String descriptionText = circuit.getAttributes().get(AttributeKey.Description);
if (descriptionText != null && descriptionText.length() > 0) if (descriptionText != null && descriptionText.length() > 0)
insertAction.setToolTip(descriptionText); insertAction.setToolTip(descriptionText);

View File

@ -73,6 +73,9 @@ elem_D_FF=D_FF
elem_T_FF=T_FF elem_T_FF=T_FF
elem_Register=Register elem_Register=Register
elem_ROM=ROM elem_ROM=ROM
elem_ROM_pin_address=Adresse des Datenwortes welches ausgelesen werden soll.
elem_ROM_pin_sel=Ist dieser Pin high (1) ist der Ausgang aktiviert. Ist er low (0) ist der Ausgang hochohmig.
elem_ROM_pin_data=Hier wird das Datenwort ausgegeben, wenn der Baustein aktiviert ist.
elem_RAMDualPort=RAMDualPort elem_RAMDualPort=RAMDualPort
elem_RAMSinglePort=RAMSinglePort elem_RAMSinglePort=RAMSinglePort
elem_Counter=Z\u00E4hler elem_Counter=Z\u00E4hler

View File

@ -87,6 +87,10 @@ elem_D_FF=D_FF
elem_T_FF=T_FF elem_T_FF=T_FF
elem_Register=Register elem_Register=Register
elem_ROM=ROM elem_ROM=ROM
elem_ROM_pin_address=Address of data word to output on data output pin.
elem_ROM_pin_sel=If the pin is high, the output is activated. If it is low, the data pin is in high Z state.
elem_ROM_pin_data=The selected data word. Only readable if select pin is high.
elem_RAMDualPort=RAMDualPort elem_RAMDualPort=RAMDualPort
elem_RAMDualPort_tt=A RAM module with separate inputs for storing and output for reading the stored data. elem_RAMDualPort_tt=A RAM module with separate inputs for storing and output for reading the stored data.
elem_RAMSinglePort=RAMSinglePort elem_RAMSinglePort=RAMSinglePort