From 141c4c4635ce39d0737a97568136c39c39e690f1 Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 7 Jul 2016 15:40:36 +0200 Subject: [PATCH] better color model, passed tests are green --- .../digital/gui/components/test/TestResult.java | 11 +++++++---- .../gui/components/test/TestResultDialog.java | 14 +++++++++----- src/main/resources/lang/lang_de.xml | 3 ++- src/main/resources/lang/lang_en.xml | 1 + .../gui/components/test/TestResultTest.java | 8 ++++---- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/neemann/digital/gui/components/test/TestResult.java b/src/main/java/de/neemann/digital/gui/components/test/TestResult.java index f9b75ac1e..09a996ae8 100644 --- a/src/main/java/de/neemann/digital/gui/components/test/TestResult.java +++ b/src/main/java/de/neemann/digital/gui/components/test/TestResult.java @@ -22,7 +22,7 @@ public class TestResult implements TableModel { private final ArrayList names; private final ArrayList lines; - private final ArrayList results; + private final ArrayList results; private boolean allPassed; /** @@ -60,11 +60,11 @@ public class TestResult implements TableModel { for (Value[] row : lines) { - MatchedValue[] res = new MatchedValue[row.length]; + Value[] res = new Value[row.length]; for (TestSignal in : inputs) { row[in.index].setTo(in.value); - res[in.index] = new MatchedValue(row[in.index], in.value); + res[in.index] = row[in.index]; } model.doStep(); @@ -89,6 +89,9 @@ public class TestResult implements TableModel { } private int getIndexOf(String name) throws DataException { + if (name==null || name.length()==0) + throw new DataException(Lang.get("err_unnamedSignal", name)); + for (int i = 0; i < names.size(); i++) { String n = names.get(i); if (n.equals(name)) @@ -144,7 +147,7 @@ public class TestResult implements TableModel { * @param columnIndex columnIndex * @return the value */ - public MatchedValue getValue(int rowIndex, int columnIndex) { + public Value getValue(int rowIndex, int columnIndex) { return results.get(rowIndex)[columnIndex]; } diff --git a/src/main/java/de/neemann/digital/gui/components/test/TestResultDialog.java b/src/main/java/de/neemann/digital/gui/components/test/TestResultDialog.java index 22f30d54d..3a3bd9b74 100644 --- a/src/main/java/de/neemann/digital/gui/components/test/TestResultDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/test/TestResultDialog.java @@ -21,6 +21,7 @@ import java.util.Collections; */ public class TestResultDialog extends JDialog { private static final Color FAILED_COLOR = new Color(255, 200, 200); + private static final Color PASSED_COLOR = new Color(200, 255, 200); /** * Creates a new result dialog. @@ -31,7 +32,7 @@ public class TestResultDialog extends JDialog { * @param library the library to use * @throws NodeException NodeException * @throws DataException DataException - * @throws PinException PinException + * @throws PinException PinException */ public TestResultDialog(JFrame owner, ArrayList tsl, Circuit circuit, ElementLibrary library) throws NodeException, DataException, PinException { super(owner, Lang.get("msg_testResult"), false); @@ -92,15 +93,18 @@ public class TestResultDialog extends JDialog { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel comp = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - MatchedValue v = (MatchedValue) value; + Value v = (Value) value; comp.setText(v.toString()); comp.setHorizontalAlignment(JLabel.CENTER); - if (v.isPassed()) + if (v instanceof MatchedValue) { + if (((MatchedValue) v).isPassed()) + comp.setBackground(PASSED_COLOR); + else + comp.setBackground(FAILED_COLOR); + } else comp.setBackground(Color.WHITE); - else - comp.setBackground(FAILED_COLOR); return comp; } diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index bc95921bb..3375484b6 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -168,8 +168,9 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen. Unerwartetes Ende des Ausdrucks Wert {0} in Zeile {1} ist keine Zahl! Erwarte {0} anstelle von {1} Werten in Zeile {2}! - Signal {0} ist im Testvector nicht vorhanden! + Signal {0} ist im Testvektor nicht vorhanden! Keine Testdaten vorhanden. + Es gibt ein unbenanntes Signal Adress Bits Datenbits Farbe diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 08fa7c34c..171515b2c 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -170,6 +170,7 @@ To analyse you can run the circuit in single gate step mode. Expected {0} but found {1} values in line {2}! Signal {0} is not present in test vector! Not test data found. + There is a unnamed signal! Address Bits Data Bits Color diff --git a/src/test/java/de/neemann/digital/gui/components/test/TestResultTest.java b/src/test/java/de/neemann/digital/gui/components/test/TestResultTest.java index 1b081a01c..17f93340c 100644 --- a/src/test/java/de/neemann/digital/gui/components/test/TestResultTest.java +++ b/src/test/java/de/neemann/digital/gui/components/test/TestResultTest.java @@ -55,10 +55,10 @@ public class TestResultTest extends TestCase { + "1 1 0\n"); TestResult tr = new TestResult(data).create(model); assertFalse(tr.allPassed()); - assertEquals(true, tr.getValue(0,2).isPassed()); - assertEquals(true, tr.getValue(1,2).isPassed()); - assertEquals(true, tr.getValue(2,2).isPassed()); - assertEquals(false, tr.getValue(3,2).isPassed()); + assertEquals(true, ((MatchedValue)tr.getValue(0,2)).isPassed()); + assertEquals(true, ((MatchedValue)tr.getValue(1,2)).isPassed()); + assertEquals(true, ((MatchedValue)tr.getValue(2,2)).isPassed()); + assertEquals(false, ((MatchedValue)tr.getValue(3,2)).isPassed()); } public void testResultErrorDC() throws Exception {