diff --git a/src/main/java/nl/digitalekabeltelevisie/controller/KVP.java b/src/main/java/nl/digitalekabeltelevisie/controller/KVP.java index 070fc2cc..7c8816cd 100644 --- a/src/main/java/nl/digitalekabeltelevisie/controller/KVP.java +++ b/src/main/java/nl/digitalekabeltelevisie/controller/KVP.java @@ -70,6 +70,32 @@ public class KVP{ public record DetailView(DetailSource detailSource, String label) {} + public enum NUMBER_DISPLAY { + DECIMAL, + HEX, + BOTH + } + + public enum STRING_DISPLAY{ + PLAIN, // plain + JAVASCRIPT, // javascript escaped (quotes removed) + HTML_FRAGMENTS, // HTML fragments '<' and '&' escaped, + HTML_AWT // AWT HTML (html segments include tag, otherwise plain text + } + + public enum FIELD_TYPE { + STRING, + BYTES, + INT, + LONG, + + LABEL, //used for a node that has no value associated with it + DVBSTRING, + HTML, // used for a node that has no separate value associated with , but a HTML fragment as value for presentation where possible, has to have a plain text alternative + + BIGINT + } + /** * maximum length of byte[] to be shown in JTree, only has meaning in case data is array of byte. */ @@ -86,43 +112,12 @@ public record DetailView(DetailSource detailSource, String label) {} private DVBString dvbStringValue; private BigInteger bigIntegerValue; - private static byte numberDisplay = 1; // 1 - decimal, 2 - - // hex, 3 both - // ,example "0xA0 - // (160)" - public static final byte NUMBER_DISPLAY_DECIMAL = 1; - public static final byte NUMBER_DISPLAY_HEX = 2; - public static final byte NUMBER_DISPLAY_BOTH = 3; - - private static byte stringDisplay = 1; - // 1 - plain, - // 2 - javascript escaped (quotes removed), - // 3 - HTML fragments '<' and '&' escaped, - // 4 - AWT HTML (html segments include tag, otherwise plain text - public static final byte STRING_DISPLAY_PLAIN = 1; - public static final byte STRING_DISPLAY_JAVASCRIPT = 2; - public static final byte STRING_DISPLAY_HTML_FRAGMENTS = 3; - public static final byte STRING_DISPLAY_HTML_AWT = 4; - - private FIELD_TYPE fieldType = FIELD_TYPE.STRING; - - public enum FIELD_TYPE { - STRING, - BYTES, - INT, - LONG, - - LABEL, //used for a node that has no value associated with it - DVBSTRING, - HTML, // used for a node that has no separate value associated with , but a HTML fragment as value for presentation where possible, has to have a plain text alternative - - BIGINT - - } + private static NUMBER_DISPLAY numberDisplay = NUMBER_DISPLAY.DECIMAL; // 1 - decimal, 2 - + private static STRING_DISPLAY stringDisplay = STRING_DISPLAY.PLAIN; + private FIELD_TYPE fieldType; private List detailViews = new ArrayList<>(); - /** * crumb's are used to be able to jump to any place in the tree, based on a url-like @@ -271,7 +266,7 @@ public String toString() { return toString(stringDisplay,numberDisplay); } - public String toString(byte stringFormat, byte numberFormat) { + public String toString(STRING_DISPLAY stringFormat, NUMBER_DISPLAY numberFormat) { StringBuilder b = new StringBuilder(label); if(!labelAppend.isEmpty()) { b.append(labelAppend); @@ -280,20 +275,20 @@ public String toString(byte stringFormat, byte numberFormat) { if ((fieldType != FIELD_TYPE.LABEL)&&(fieldType != FIELD_TYPE.HTML)) { appendValueAfterLabel(numberFormat, b); } - if((fieldType==FIELD_TYPE.HTML)&&(STRING_DISPLAY_PLAIN!=stringFormat)){ + if((fieldType==FIELD_TYPE.HTML)&&(STRING_DISPLAY.PLAIN!=stringFormat)){ b = replacePlainLabelWithHTML(stringFormat); } - if (stringFormat == STRING_DISPLAY_JAVASCRIPT) { + if (stringFormat == STRING_DISPLAY.JAVASCRIPT) { return b.toString().replace("\"", "\\\"").replace("\'", "\\\'"); } return b.toString(); } - private StringBuilder replacePlainLabelWithHTML(byte stringFormat) { - if(stringFormat==STRING_DISPLAY_HTML_AWT){ + private StringBuilder replacePlainLabelWithHTML(STRING_DISPLAY stringFormat) { + if(stringFormat==STRING_DISPLAY.HTML_AWT){ return new StringBuilder("").append(value).append(""); - }else if(stringFormat==STRING_DISPLAY_HTML_FRAGMENTS){ + }else if(stringFormat==STRING_DISPLAY.HTML_FRAGMENTS){ return new StringBuilder(value); } return new StringBuilder(); @@ -303,7 +298,7 @@ private StringBuilder replacePlainLabelWithHTML(byte stringFormat) { * @param numberFormat * @param b */ - private void appendValueAfterLabel(byte numberFormat, StringBuilder b) { + private void appendValueAfterLabel(NUMBER_DISPLAY numberFormat, StringBuilder b) { b.append(": "); switch (fieldType){ case STRING: @@ -366,10 +361,10 @@ private void appendString(StringBuilder b) { * @param numberFormat * @param b */ - private void appendLong(byte numberFormat, StringBuilder b) { - if (numberFormat == NUMBER_DISPLAY_DECIMAL) { + private void appendLong(NUMBER_DISPLAY numberFormat, StringBuilder b) { + if (numberFormat == NUMBER_DISPLAY.DECIMAL) { b.append(longValue); - } else if (numberFormat == NUMBER_DISPLAY_HEX) { + } else if (numberFormat == NUMBER_DISPLAY.HEX) { b.append("0x").append(Long.toHexString(longValue).toUpperCase()); } else { // assume both to be safe b.append("0x").append(Long.toHexString(longValue).toUpperCase()).append(" (").append(longValue) @@ -381,20 +376,20 @@ private void appendLong(byte numberFormat, StringBuilder b) { * @param numberFormat * @param b */ - private void appendInteger(byte numberFormat, StringBuilder b) { - if (numberFormat == NUMBER_DISPLAY_DECIMAL) { + private void appendInteger(NUMBER_DISPLAY numberFormat, StringBuilder b) { + if (numberFormat == NUMBER_DISPLAY.DECIMAL) { b.append(intValue); - } else if (numberFormat == NUMBER_DISPLAY_HEX) { + } else if (numberFormat == NUMBER_DISPLAY.HEX) { b.append("0x").append(Integer.toHexString(intValue).toUpperCase()); } else { // assume both to be safe b.append(getHexAndDecimalFormattedString(intValue)); } } - private void appendBigInteger(byte numberFormat, StringBuilder b) { - if (numberFormat == NUMBER_DISPLAY_DECIMAL) { + private void appendBigInteger(NUMBER_DISPLAY numberFormat, StringBuilder b) { + if (numberFormat == NUMBER_DISPLAY.DECIMAL) { b.append(bigIntegerValue.toString()); - } else if (numberFormat == NUMBER_DISPLAY_HEX) { + } else if (numberFormat == NUMBER_DISPLAY.HEX) { b.append("0x").append(bigIntegerValue.toString(16).toUpperCase()); } else { // assume both to be safe b.append(getHexAndDecimalFormattedString(bigIntegerValue)); @@ -402,29 +397,29 @@ private void appendBigInteger(byte numberFormat, StringBuilder b) { } - public static byte getNumberDisplay() { + public static NUMBER_DISPLAY getNumberDisplay() { return numberDisplay; } - public static void setNumberDisplay(byte intDisplay) { + public static void setNumberDisplay(NUMBER_DISPLAY intDisplay) { numberDisplay = intDisplay; } public static String formatInt(int intValue) { - if (numberDisplay == NUMBER_DISPLAY_DECIMAL) { + if (numberDisplay == NUMBER_DISPLAY.DECIMAL) { return Integer.toString(intValue); - } else if (numberDisplay == NUMBER_DISPLAY_HEX) { + } else if (numberDisplay == NUMBER_DISPLAY.HEX) { return ("0x") + Integer.toHexString(intValue).toUpperCase(); } else { // assume both to be safe - return ("0x" + Integer.toHexString(intValue).toUpperCase()) + " (" + Integer.toString(intValue) + (")"); + return ("0x" + Integer.toHexString(intValue).toUpperCase()) + " (" + intValue + (")"); } } - public static byte getStringDisplay() { + public static STRING_DISPLAY getStringDisplay() { return stringDisplay; } - public static void setStringDisplay(byte stringDisplay) { + public static void setStringDisplay(STRING_DISPLAY stringDisplay) { KVP.stringDisplay = stringDisplay; } /** @@ -436,7 +431,7 @@ public void setImageSource(ImageSource imageSource) { } public String getPlainText(){ - return toString(STRING_DISPLAY_PLAIN, NUMBER_DISPLAY_BOTH); + return toString(STRING_DISPLAY.PLAIN, NUMBER_DISPLAY.BOTH); } diff --git a/src/main/java/nl/digitalekabeltelevisie/main/DVBinspector.java b/src/main/java/nl/digitalekabeltelevisie/main/DVBinspector.java index b17f7de2..655eabe8 100644 --- a/src/main/java/nl/digitalekabeltelevisie/main/DVBinspector.java +++ b/src/main/java/nl/digitalekabeltelevisie/main/DVBinspector.java @@ -216,8 +216,8 @@ public static Map determinePidHandlers(final String[ public void run() { - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); - KVP.setStringDisplay(KVP.STRING_DISPLAY_HTML_AWT); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); + KVP.setStringDisplay(KVP.STRING_DISPLAY.HTML_AWT); javax.swing.SwingUtilities.invokeLater(() -> createAndShowGUI(transportStream)); } @@ -661,8 +661,8 @@ public void setTreeView(final DVBtree treeView) { private void updatePIDLists(final TransportStream tStream, final PIDDialog pDialog){ final ViewContext viewConfig = new ViewContext(); - final ArrayList used = new ArrayList<>(); - final ArrayList notUsed = new ArrayList<>(); + final List used = new ArrayList<>(); + final List notUsed = new ArrayList<>(); if(tStream!=null){ final short[] used_pids=tStream.getUsedPids(); diff --git a/src/main/java/nl/digitalekabeltelevisie/util/Utils.java b/src/main/java/nl/digitalekabeltelevisie/util/Utils.java index 805f9336..591a5c3c 100644 --- a/src/main/java/nl/digitalekabeltelevisie/util/Utils.java +++ b/src/main/java/nl/digitalekabeltelevisie/util/Utils.java @@ -2001,7 +2001,7 @@ public static StringBuilder getChildrenAsHTML(DefaultMutableTreeNode dmtn) { Object next = children.nextElement(); if(next instanceof DefaultMutableTreeNode child){ KVP chKVP = (KVP)child.getUserObject(); - res.append(chKVP.toString(KVP.STRING_DISPLAY_HTML_FRAGMENTS, KVP.NUMBER_DISPLAY_BOTH)).append(lineSep); + res.append(chKVP.toString(KVP.STRING_DISPLAY.HTML_FRAGMENTS, KVP.NUMBER_DISPLAY.BOTH)).append(lineSep); if(!child.isLeaf()){ res.append(getChildrenAsHTML(child)); } diff --git a/src/test/java/nl/digitalekabeltelevisie/controller/KVPTest.java b/src/test/java/nl/digitalekabeltelevisie/controller/KVPTest.java index d1455c17..3fc4a1af 100644 --- a/src/test/java/nl/digitalekabeltelevisie/controller/KVPTest.java +++ b/src/test/java/nl/digitalekabeltelevisie/controller/KVPTest.java @@ -71,11 +71,11 @@ public void testKVPLabelValueDescription() { @Test public void testKVPStringIntString() { KVP kvp = new KVP("LabelForInt",42,"Explanation"); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_DECIMAL); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.DECIMAL); assertEquals("LabelForInt: 42 => Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); assertEquals("LabelForInt: 0x2A (42) => Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_HEX); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.HEX); assertEquals("LabelForInt: 0x2A => Explanation",kvp.toString()); assertEquals("LabelForInt:42",kvp.getCrumb()); @@ -84,44 +84,44 @@ public void testKVPStringIntString() { @Test public void testKVPStringLongString() { KVP kvp = new KVP("LabelForLong",142L,"Loooooong Explanation"); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_DECIMAL); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.DECIMAL); assertEquals("LabelForLong: 142 => Loooooong Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); assertEquals("LabelForLong: 0x8E (142) => Loooooong Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_HEX); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.HEX); assertEquals("LabelForLong: 0x8E => Loooooong Explanation",kvp.toString()); kvp = new KVP("LabelForLong",142L,null); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_DECIMAL); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.DECIMAL); assertEquals("LabelForLong: 142",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); assertEquals("LabelForLong: 0x8E (142)",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_HEX); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.HEX); assertEquals("LabelForLong: 0x8E",kvp.toString()); } @Test public void testKVPStringBooleanString() { KVP kvp = new KVP("BooleanLabel",true,"Boooolean Explanation"); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_HEX); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.HEX); assertEquals("BooleanLabel: 0x1 => Boooolean Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); assertEquals("BooleanLabel: 0x1 (1) => Boooolean Explanation",kvp.toString()); kvp = new KVP("BooleanLabel",false,"Boooolean false Explanation"); assertEquals("BooleanLabel: 0x0 (0) => Boooolean false Explanation",kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_DECIMAL); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.DECIMAL); assertEquals("BooleanLabel: 0 => Boooolean false Explanation",kvp.toString()); } @Test public void testHtmlLabelString() { KVP kvp = new KVP("

Head

","bold label?"); - KVP.setStringDisplay(KVP.STRING_DISPLAY_HTML_AWT); + KVP.setStringDisplay(KVP.STRING_DISPLAY.HTML_AWT); assertEquals("

Head

",kvp.toString()); - KVP.setStringDisplay(KVP.STRING_DISPLAY_PLAIN); + KVP.setStringDisplay(KVP.STRING_DISPLAY.PLAIN); assertEquals("bold label?",kvp.toString()); - KVP.setStringDisplay(KVP.STRING_DISPLAY_HTML_FRAGMENTS); + KVP.setStringDisplay(KVP.STRING_DISPLAY.HTML_FRAGMENTS); assertEquals("

Head

",kvp.toString()); - KVP.setStringDisplay(KVP.STRING_DISPLAY_JAVASCRIPT); + KVP.setStringDisplay(KVP.STRING_DISPLAY.JAVASCRIPT); assertEquals("",kvp.toString()); } @@ -200,18 +200,18 @@ public void testKVPStringBigIntegerString() { BigInteger bg = new BigInteger(biggy); KVP kvp = new KVP("Big Number",bg,null); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_DECIMAL); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.DECIMAL); assertEquals("Big Number: "+biggy, kvp.toString()); // test non global formatting - assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600", kvp.toString(KVP.STRING_DISPLAY_PLAIN,KVP.NUMBER_DISPLAY_HEX)); - assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600 ("+biggy +")" , kvp.toString(KVP.STRING_DISPLAY_PLAIN,KVP.NUMBER_DISPLAY_BOTH)); + assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600", kvp.toString(KVP.STRING_DISPLAY.PLAIN,KVP.NUMBER_DISPLAY.HEX)); + assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600 ("+biggy +")" , kvp.toString(KVP.STRING_DISPLAY.PLAIN,KVP.NUMBER_DISPLAY.BOTH)); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_HEX); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.HEX); assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600", kvp.toString()); - KVP.setNumberDisplay(KVP.NUMBER_DISPLAY_BOTH); + KVP.setNumberDisplay(KVP.NUMBER_DISPLAY.BOTH); assertEquals("Big Number: 0x18EE90FF6C4FE9FCDC157A600 ("+biggy +")" , kvp.toString()); }