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

View File

@ -1,6 +1,7 @@
package de.neemann.digital.core.element;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.lang.Lang;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
@ -14,6 +15,7 @@ import java.util.ArrayList;
*/
public class ElementTypeDescription {
private final String name;
private final String translatedName;
private String shortName;
private final ElementFactory elementFactory;
private final PinDescription[] inputPins;
@ -60,7 +62,10 @@ public class ElementTypeDescription {
*/
public ElementTypeDescription(String name, ElementFactory elementFactory, PinDescription... inputPins) {
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.inputPins = inputPins;
for (PinDescription p : inputPins)
@ -76,7 +81,17 @@ public class ElementTypeDescription {
* @return the shortname
*/
public String getShortName() {
return shortName;
if (shortName == null)
return getTranslatedName();
else
return shortName;
}
/**
* @return returns the translated element name
*/
public String getTranslatedName() {
return translatedName;
}
/**
@ -109,9 +124,9 @@ public class ElementTypeDescription {
* @return the description
*/
public String getDescription(ElementAttributes elementAttributes) {
if (description == null)
return name;
else
if (description == null) {
return translatedName;
} else
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.ElementAttributes;
import de.neemann.digital.core.element.ElementTypeDescription;
import de.neemann.digital.lang.Lang;
import java.io.File;
@ -24,7 +25,9 @@ public class ROM extends Node implements Element {
/**
* 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.Bits)
.addAttribute(AttributeKey.AddrBits)
@ -51,7 +54,7 @@ public class ROM extends Node implements Element {
*/
public ROM(ElementAttributes attr) {
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);
addrBits = attr.get(AttributeKey.AddrBits);
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) {
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.
*/
public static class ElementContainer {
private final String name;
private final ElementTypeDescription name;
private final String treePath;
/**
* Creates anew instance
*
* @param name the elements name
* @param typeDescription the elements typeDescription
* @param treePath the elements menu path
*/
public ElementContainer(String name, String treePath) {
this.name = name;
public ElementContainer(ElementTypeDescription typeDescription, String treePath) {
this.name = typeDescription;
this.treePath = treePath;
}
/**
* @return the elements name
*/
public String getName() {
public ElementTypeDescription getDescription() {
return name;
}

View File

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

View File

@ -73,6 +73,9 @@ elem_D_FF=D_FF
elem_T_FF=T_FF
elem_Register=Register
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_RAMSinglePort=RAMSinglePort
elem_Counter=Z\u00E4hler

View File

@ -87,6 +87,10 @@ elem_D_FF=D_FF
elem_T_FF=T_FF
elem_Register=Register
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_tt=A RAM module with separate inputs for storing and output for reading the stored data.
elem_RAMSinglePort=RAMSinglePort