From 4f3154958f5e4cbeb776379592a06356c35732c5 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sun, 30 Apr 2017 10:12:15 +0200 Subject: [PATCH] removed StringUtils --- .../digital/draw/library/LibraryNode.java | 6 +- .../gui/components/CircuitComponent.java | 4 +- .../digital/gui/components/EditorFactory.java | 6 +- .../components/testing/TestResultDialog.java | 4 +- .../java/de/neemann/gui/ErrorMessage.java | 20 +++++- src/main/java/de/neemann/gui/StringUtils.java | 64 ------------------- 6 files changed, 29 insertions(+), 75 deletions(-) delete mode 100644 src/main/java/de/neemann/gui/StringUtils.java diff --git a/src/main/java/de/neemann/digital/draw/library/LibraryNode.java b/src/main/java/de/neemann/digital/draw/library/LibraryNode.java index 9a3fc7346..a9c8339ca 100644 --- a/src/main/java/de/neemann/digital/draw/library/LibraryNode.java +++ b/src/main/java/de/neemann/digital/draw/library/LibraryNode.java @@ -6,7 +6,7 @@ import de.neemann.digital.draw.shapes.ShapeFactory; import de.neemann.digital.lang.Lang; import de.neemann.gui.IconCreator; -import de.neemann.gui.StringUtils; +import de.neemann.gui.LineBreaker; import javax.swing.*; import java.io.File; @@ -316,11 +316,11 @@ public String getToolTipText() { if (description == null) return Lang.get("msg_fileNotImportedYet"); else - return StringUtils.textToHTML(description.getDescription(new ElementAttributes())); + return new LineBreaker().toHTML().breakLines(description.getDescription(new ElementAttributes())); } else return Lang.get("msg_fileIsNotUnique"); } else - return StringUtils.textToHTML(Lang.getNull("elem_" + getName() + "_tt")); + return new LineBreaker().toHTML().breakLines(Lang.getNull("elem_" + getName() + "_tt")); } /** diff --git a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java index 53896e2ee..f6323769e 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -21,7 +21,7 @@ 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.LineBreaker; import de.neemann.gui.ToolTipAction; import javax.swing.*; @@ -292,7 +292,7 @@ private String checkToolTip(String tt) { if (tt != null && tt.length() == 0) return null; else - return StringUtils.textToHTML(tt); + return new LineBreaker().toHTML().breakLines(tt); } /** diff --git a/src/main/java/de/neemann/digital/gui/components/EditorFactory.java b/src/main/java/de/neemann/digital/gui/components/EditorFactory.java index 40d518282..6b7826b3c 100644 --- a/src/main/java/de/neemann/digital/gui/components/EditorFactory.java +++ b/src/main/java/de/neemann/digital/gui/components/EditorFactory.java @@ -14,7 +14,7 @@ import de.neemann.digital.lang.Lang; import de.neemann.digital.testing.TestData; import de.neemann.gui.ErrorMessage; -import de.neemann.gui.StringUtils; +import de.neemann.gui.LineBreaker; import de.neemann.gui.ToolTipAction; import de.neemann.gui.language.Bundle; import de.neemann.gui.language.Language; @@ -95,7 +95,7 @@ public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttribute JLabel label = new JLabel(key.getName() + ": "); if (labelAtTop) label.setVerticalAlignment(JLabel.TOP); - final String description = StringUtils.textToHTML(key.getDescription()); + final String description = new LineBreaker().toHTML().breakLines(key.getDescription()); label.setToolTipText(description); panel.add(label, DialogLayout.LABEL); JComponent component = getComponent(elementAttributes); @@ -211,7 +211,7 @@ private final static class BooleanEditor implements Editor { public BooleanEditor(Boolean value, Key key) { bool = new JCheckBox(key.getName(), value); - bool.setToolTipText(StringUtils.textToHTML(key.getDescription())); + bool.setToolTipText(new LineBreaker().toHTML().breakLines(key.getDescription())); } @Override diff --git a/src/main/java/de/neemann/digital/gui/components/testing/TestResultDialog.java b/src/main/java/de/neemann/digital/gui/components/testing/TestResultDialog.java index 447ef1a59..090222635 100644 --- a/src/main/java/de/neemann/digital/gui/components/testing/TestResultDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/testing/TestResultDialog.java @@ -11,7 +11,7 @@ import de.neemann.digital.testing.*; import de.neemann.gui.ErrorMessage; import de.neemann.gui.IconCreator; -import de.neemann.gui.StringUtils; +import de.neemann.gui.LineBreaker; import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; @@ -79,7 +79,7 @@ public TestResultDialog(JFrame owner, ArrayList tsl, Circuit circuit, E tp.addTab(tabName, tabIcon, new JScrollPane(table)); if (tr.toManyResults()) - tp.setToolTipTextAt(i, StringUtils.textToHTML(Lang.get("msg_test_missingLines_tt"))); + tp.setToolTipTextAt(i, new LineBreaker().toHTML().breakLines(Lang.get("msg_test_missingLines_tt"))); i++; } if (errorTabIndex >= 0) diff --git a/src/main/java/de/neemann/gui/ErrorMessage.java b/src/main/java/de/neemann/gui/ErrorMessage.java index 49e17d394..f1cdb7d9f 100644 --- a/src/main/java/de/neemann/gui/ErrorMessage.java +++ b/src/main/java/de/neemann/gui/ErrorMessage.java @@ -43,10 +43,28 @@ public ErrorMessage addCause(Throwable e) { if (message.length() > 0) message.append('\n'); - message.append(StringUtils.getExceptionMessage(e)); + addExceptionMessage(e); return this; } + /** + * Creates a exception message + * + * @param e the {@link Throwable} instance + */ + private void addExceptionMessage(Throwable e) { + while (e != null) { + final String m = e.getMessage(); + if (m != null && m.length() > 0) + message.append(m); + else + message.append(e.getClass().getSimpleName()); + e = e.getCause(); + if (e != null) + message.append("\ncaused by: "); + } + } + /** * Shows the error message * diff --git a/src/main/java/de/neemann/gui/StringUtils.java b/src/main/java/de/neemann/gui/StringUtils.java deleted file mode 100644 index dd9ff32f6..000000000 --- a/src/main/java/de/neemann/gui/StringUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.neemann.gui; - -/** - * Some helper functions concerning strings - */ -public final class StringUtils { - - - private StringUtils() { - } - - /** - * Adds a list to a {@link StringBuilder} - * - * @param sb the StringBuilder - * @param i the list - * @param separator the separator to use - */ - public static void addList(StringBuilder sb, Iterable i, String separator) { - boolean first = true; - for (Object o : i) { - if (first) - first = false; - else - sb.append(separator); - sb.append(o.toString()); - } - } - - /** - * Creates a exception message - * - * @param e the {@link Throwable} instance - * @return the message - */ - public static String getExceptionMessage(Throwable e) { - StringBuilder sb = new StringBuilder(); - - while (e != null) { - final String m = e.getMessage(); - if (m != null && m.length() > 0) - sb.append(m); - else - sb.append(e.getClass().getSimpleName()); - e = e.getCause(); - if (e != null) - sb.append("\ncaused by: "); - } - - return sb.toString(); - } - - /** - * Formats text to html if it contains line breaks. - * Short texts are unchanged. Ignores the containing line breaks. - * - * @param text the text - * @return the unchanged text or a HTML segment - */ - public static String textToHTML(String text) { - return new LineBreaker().toHTML().breakLines(text); - } - -}