Better formatting of help text. See graphic RAM.

This commit is contained in:
hneemann 2016-10-29 17:39:00 +02:00
parent 2b166795ee
commit 841b5dd759
11 changed files with 113 additions and 57 deletions

View File

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes>
<entry>
<string>Description</string>
<string>Eine einfache &quot;Grafikkarte&quot;. Sie enthält ein Grafik-RAM um die eigentliche Grafik anzuzeigen.</string>
</entry>
</attributes>
<visualElements>
<visualElement>
<elementName>In</elementName>

View File

@ -4,7 +4,7 @@
<attributes>
<entry>
<string>Description</string>
<string>Programmzähler</string>
<string>Programmzähler. Hier wird der aktuelle Programmzähler gespeicher. Über die verschiedenen Eingänge kann beeinflußt werden, wie der Programmzähler mit dem Takt verändert wird.</string>
</entry>
<entry>
<string>Width</string>
@ -29,7 +29,6 @@
</entry>
</elementAttributes>
<pos x="260" y="140"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -48,7 +47,6 @@
</entry>
</elementAttributes>
<pos x="160" y="340"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Add</elementName>
@ -63,7 +61,6 @@
</entry>
</elementAttributes>
<pos x="420" y="160"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Const</elementName>
@ -74,7 +71,6 @@
</entry>
</elementAttributes>
<pos x="400" y="180"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Const</elementName>
@ -85,7 +81,6 @@
</entry>
</elementAttributes>
<pos x="400" y="200"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -104,7 +99,6 @@
</entry>
</elementAttributes>
<pos x="640" y="160"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -127,7 +121,6 @@
</entry>
</elementAttributes>
<pos x="340" y="420"/>
<rotate>3</rotate>
</visualElement>
<visualElement>
<elementName>Add</elementName>
@ -142,7 +135,6 @@
</entry>
</elementAttributes>
<pos x="580" y="320"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -157,7 +149,6 @@
</entry>
</elementAttributes>
<pos x="160" y="160"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Const</elementName>
@ -168,7 +159,6 @@
</entry>
</elementAttributes>
<pos x="560" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Multiplexer</elementName>
@ -179,7 +169,6 @@
</entry>
</elementAttributes>
<pos x="680" y="280"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Multiplexer</elementName>
@ -190,7 +179,6 @@
</entry>
</elementAttributes>
<pos x="760" y="300"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -209,7 +197,6 @@
</entry>
</elementAttributes>
<pos x="780" y="420"/>
<rotate>1</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -228,13 +215,11 @@
</entry>
</elementAttributes>
<pos x="700" y="420"/>
<rotate>1</rotate>
</visualElement>
<visualElement>
<elementName>Not</elementName>
<elementAttributes/>
<pos x="180" y="160"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Reset</elementName>
@ -245,7 +230,6 @@
</entry>
</elementAttributes>
<pos x="220" y="220"/>
<rotate>0</rotate>
</visualElement>
</visualElements>
<wires>

View File

@ -265,7 +265,6 @@
<long>20222</long>
<long>6369</long>
<long>27151</long>
<bits>16</bits>
</data>
</entry>
<entry>

View File

@ -4,7 +4,7 @@
<attributes>
<entry>
<string>Description</string>
<string>Die 16 Prozessorregister</string>
<string>In diesem Block befinden sich die Die 16 Prozessorregister.</string>
</entry>
<entry>
<string>Width</string>
@ -29,7 +29,6 @@
</entry>
</elementAttributes>
<pos x="580" y="120"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -48,7 +47,6 @@
</entry>
</elementAttributes>
<pos x="160" y="120"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -67,7 +65,6 @@
</entry>
</elementAttributes>
<pos x="580" y="240"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -86,7 +83,6 @@
</entry>
</elementAttributes>
<pos x="580" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -105,7 +101,6 @@
</entry>
</elementAttributes>
<pos x="580" y="480"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -124,7 +119,6 @@
</entry>
</elementAttributes>
<pos x="580" y="600"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -143,7 +137,6 @@
</entry>
</elementAttributes>
<pos x="580" y="720"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -162,7 +155,6 @@
</entry>
</elementAttributes>
<pos x="580" y="840"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -181,7 +173,6 @@
</entry>
</elementAttributes>
<pos x="580" y="960"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -200,7 +191,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1080"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -219,7 +209,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1220"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -238,7 +227,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1340"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -257,7 +245,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1460"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -276,7 +263,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1580"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -295,7 +281,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1700"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -314,7 +299,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1820"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Register</elementName>
@ -333,7 +317,6 @@
</entry>
</elementAttributes>
<pos x="580" y="1940"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Demultiplexer</elementName>
@ -344,7 +327,6 @@
</entry>
</elementAttributes>
<pos x="180" y="200"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -359,7 +341,6 @@
</entry>
</elementAttributes>
<pos x="160" y="620"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -382,7 +363,6 @@
</entry>
</elementAttributes>
<pos x="1000" y="1000"/>
<rotate>1</rotate>
</visualElement>
<visualElement>
<elementName>Multiplexer</elementName>
@ -397,7 +377,6 @@
</entry>
</elementAttributes>
<pos x="980" y="140"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Multiplexer</elementName>
@ -412,7 +391,6 @@
</entry>
</elementAttributes>
<pos x="980" y="640"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -431,7 +409,6 @@
</entry>
</elementAttributes>
<pos x="160" y="560"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>In</elementName>
@ -446,7 +423,6 @@
</entry>
</elementAttributes>
<pos x="160" y="360"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -465,7 +441,6 @@
</entry>
</elementAttributes>
<pos x="1040" y="300"/>
<rotate>0</rotate>
</visualElement>
<visualElement>
<elementName>Out</elementName>
@ -484,7 +459,6 @@
</entry>
</elementAttributes>
<pos x="1040" y="800"/>
<rotate>0</rotate>
</visualElement>
</visualElements>
<wires>

View File

@ -2,6 +2,7 @@ package de.neemann.digital.core.element;
import de.neemann.digital.core.NodeException;
import de.neemann.digital.lang.Lang;
import de.neemann.gui.StringUtils;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
@ -210,7 +211,7 @@ public class ElementTypeDescription {
sb.append(getTranslatedName()).append("\n");
String descr = getDescription(elementAttributes);
if (!descr.equals(getTranslatedName()))
sb.append("\n").append(getDescription(elementAttributes)).append("\n");
sb.append("\n").append(StringUtils.breakLines(getDescription(elementAttributes))).append("\n");
try {
PinDescriptions inputs = getInputDescription(elementAttributes);

View File

@ -12,6 +12,7 @@ import de.neemann.digital.gui.components.CircuitComponent;
import de.neemann.digital.gui.state.State;
import de.neemann.digital.lang.Lang;
import de.neemann.gui.ErrorMessage;
import de.neemann.gui.StringUtils;
import de.neemann.gui.ToolTipAction;
import javax.swing.*;
@ -121,14 +122,8 @@ public class LibrarySelector implements ElementNotFoundNotification {
}
}
private String createToolTipText(String elementName) {
String toolTipText = Lang.getNull("elem_" + elementName + "_tt");
if (toolTipText == null)
return null;
if (toolTipText.indexOf('\n') >= 0)
toolTipText = "<html>" + toolTipText.replace("\n", "<br>") + "</html>";
return toolTipText;
private static String createToolTipText(String elementName) {
return StringUtils.textToHTML(Lang.getNull("elem_" + elementName + "_tt"));
}
/**

View File

@ -17,6 +17,7 @@ import de.neemann.digital.gui.sync.NoSync;
import de.neemann.digital.gui.sync.Sync;
import de.neemann.digital.lang.Lang;
import de.neemann.gui.IconCreator;
import de.neemann.gui.StringUtils;
import de.neemann.gui.ToolTipAction;
import javax.swing.*;
@ -227,7 +228,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
if (tt != null && tt.length() == 0)
return null;
else
return tt;
return StringUtils.textToHTML(tt);
}
/**

View File

@ -1,5 +1,7 @@
package de.neemann.gui;
import de.neemann.digital.lang.Lang;
/**
* Some helper functions concerning strings
*/
@ -46,4 +48,72 @@ public final class StringUtils {
return sb.toString();
}
/**
* Formats text to html if it contains line breaks.
* Short texts are unchanged.
*
* @param text the text
* @return the unchanged text or a HTML segment
*/
public static String textToHTML(String text) {
String toolTipText = StringUtils.breakLines(text);
if (toolTipText == null)
return null;
if (toolTipText.indexOf('\n') >= 0)
toolTipText = "<html>" + toolTipText.replace("\n", "<br>") + "</html>";
return toolTipText;
}
/**
* Breaks a string separate lines, all multiple spaces and line breaks are removed.
* calls {@code breakLines(text, 60)}.
*
* @param text the text to format
* @return the formatted text
*/
public static String breakLines(String text) {
return breakLines(text, 60);
}
/**
* Breaks a string into separate lines, all multiple blanks and line breaks are removed.
*
* @param text the text to format
* @param cols the number of columns
* @return the formatted text
*/
public static String breakLines(String text, int cols) {
if (text == null)
return null;
StringBuilder sb = new StringBuilder();
int pos = 0;
boolean wasBlank = false;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
switch (c) {
case '\n':
case '\r':
case ' ':
if (!wasBlank) {
if (pos > cols) {
sb.append('\n');
pos = 0;
} else {
sb.append(' ');
}
}
wasBlank = true;
break;
default:
sb.append(c);
wasBlank = false;
pos++;
}
}
return sb.toString();
}
}

View File

@ -98,7 +98,10 @@ Ein gibt einen Eingang für das Beschreiben und einen Ausgang für das Auslesen
<string name="elem_RAMSinglePort_pin_str">Ist dieser Eingang 1 wird mit steigendem Takt das Datenwort gespeichert.</string>
<string name="elem_RAMSinglePort_tt">Ein RAM Module mit einem bidirektionellem Anschluss für das Lesen und Schreiben von Daten.</string>
<string name="elem_GraphicCard">Grafik-RAM</string>
<string name="elem_GraphicCard_tt">Wird verwendet um Bitmap Grafiken anzuzeigen.</string>
<string name="elem_GraphicCard_tt">Wird verwendet um Bitmap Grafiken anzuzeigen. Der Baustein verhält sich wie ein
RAM-Baustein mit dem unterschied, dass der RAM-Inhalt als Grafik angezeigt wird. Jede Speicherstelle definiert die Farbe
eines Pixels. Es werden zwei Grafikseiten abgelegt, so das ein Screen-Switching möglich ist (Siehe Eingang B).
Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherzellen.</string>
<string name="elem_GraphicCard_pin_B">Auswahl der anzuzeigenden Seite.</string>
<string name="elem_ROM">ROM</string>
<string name="elem_ROM_pin_address">Adresse des Datenwortes welches ausgelesen werden soll.</string>

View File

@ -97,7 +97,9 @@ So this gate can emulate every combinatorial gate.</string>
<string name="elem_RAMSinglePort_pin_str">If this input is high when the clock becomes high, the the data is stored.</string>
<string name="elem_RAMSinglePort_tt">A RAM module with a bidirectional connection for reading and writing the data.</string>
<string name="elem_GraphicCard">Graphic RAM</string>
<string name="elem_GraphicCard_tt">Used to show bitmap graphic</string>
<string name="elem_GraphicCard_tt">Used to show a bitmap graphic. This element works similar to a RAM. In addition it
shows its content on a grahic screen. Every pixel is represented by a memory address. There are to screens supported
to implement screen switching (See input B).</string>
<string name="elem_GraphicCard_pin_B">Selects the buffer to show</string>
<string name="elem_ROM">ROM</string>
<string name="elem_ROM_pin_address">Address of data word to output.</string>

View File

@ -0,0 +1,21 @@
package de.neemann.gui;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by hneemann on 29.10.16.
*/
public class StringUtilsTest extends TestCase {
public void testBreakLines() throws Exception {
assertEquals("this is a test string", StringUtils.breakLines("this \n\n is \n a test \n\r string", 60));
assertEquals("this is a test\nstring", StringUtils.breakLines("this \n\n is \n a test \n\r string", 10));
assertEquals("This is a test string. This\n" +
"is a test string. This is a\n" +
"test string.", StringUtils.breakLines("This is a test string. This is a test string. This is a test string.", 20));
}
}