Skip to content

Commit e4ac6df

Browse files
Merge pull request #78 from EricBerendsen/kvp_node
Made KVP extend DefaultMutableTreeNode, and cleaned up constructors and setters. From now on getJTreeNode should return KVPs. Not retrofitted it to all code (yet?), so interface TreeNode still has getJTreeNode(int modus) return a DefaultMutableTreeNode. All generated trees should be identical, except for KVP for DVB String. Now encoding and length are auto generated child nodes, no more need to explicit creating them. Als DVBString nodes now have auto HTMLSource, which displays raw bytes and formatted string.
2 parents ed7f9d7 + 51d52f7 commit e4ac6df

File tree

79 files changed

+1858
-2595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1858
-2595
lines changed

src/main/java/nl/digitalekabeltelevisie/controller/KVP.java

+102-91
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737

3838
import javax.swing.JMenuItem;
39+
import javax.swing.tree.DefaultMutableTreeNode;
3940

4041
import nl.digitalekabeltelevisie.gui.*;
4142

@@ -65,7 +66,7 @@
6566
* @author Eric Berendsen
6667
*
6768
*/
68-
public class KVP{
69+
public class KVP extends DefaultMutableTreeNode{
6970

7071

7172
public record DetailView(DetailSource detailSource, String label) {}
@@ -91,7 +92,6 @@ public enum FIELD_TYPE {
9192

9293
LABEL, //used for a node that has no value associated with it
9394
DVBSTRING,
94-
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
9595

9696
BIGINT
9797
}
@@ -101,7 +101,7 @@ public enum FIELD_TYPE {
101101
*/
102102
private static final int BYTE_DATA_MAX_LEN = 100;
103103
private String label;
104-
private String value;
104+
private String stringValue;
105105
private String description;
106106

107107
private int intValue;
@@ -132,163 +132,155 @@ public enum FIELD_TYPE {
132132
private JMenuItem subMenu;
133133
private Object owner;
134134
private String labelAppend = "";
135+
private String htmlLabel;
135136

136137
public KVP(String label) {
137138
this.label = label;
138139
this.fieldType = FIELD_TYPE.LABEL;
139140
}
140141

141-
public KVP(String label, ImageSource imageSource) {
142+
public KVP(String label, String stringValue) {
142143
this.label = label;
143-
this.fieldType = FIELD_TYPE.LABEL;
144-
detailViews.add(new DetailView(imageSource,""));
145-
}
146-
public KVP(String label, String value, String description) {
147-
this.label = label;
148-
if(value==null){ // just a label
149-
this.fieldType = FIELD_TYPE.LABEL;
150-
}else{
151-
this.value = value;
152-
this.description = description;
153-
this.fieldType = FIELD_TYPE.STRING;
144+
this.stringValue = stringValue;
145+
this.fieldType = FIELD_TYPE.STRING;
154146

155-
}
156147
}
157148

158-
public KVP(String label, int value, String description) {
149+
public KVP(String label, String stringValue, String description) {
150+
this(label,stringValue);
151+
setDescription(description);
152+
153+
}
154+
155+
public KVP(String label, int intValue) {
159156
this.label = label;
160-
this.intValue = value;
161-
this.description = description;
157+
this.intValue = intValue;
162158
this.fieldType = FIELD_TYPE.INT;
163159
}
164160

165-
public KVP(String label, long value, String description) {
166-
this.label = label;
167-
this.longValue = value;
168-
this.description = description;
169-
this.fieldType = FIELD_TYPE.LONG;
161+
public KVP(String label, int intValue, String description) {
162+
this(label,intValue);
163+
setDescription(description);
170164
}
171165

172-
public KVP(String label, boolean value, String description) {
173-
this(label, value ? 1 : 0, description);
166+
public KVP(String label, long longValue) {
167+
this.label = label;
168+
this.longValue = longValue;
169+
this.fieldType = FIELD_TYPE.LONG;
174170
}
175171

176-
public KVP(String html, String label) {
177-
this.value = html;
178-
this.label = label; // text representation of the HTML string
179-
this.fieldType = FIELD_TYPE.HTML;
172+
public KVP(String label, long longValue, String description) {
173+
this(label,longValue);
174+
setDescription(description);
180175
}
181176

182-
183-
184-
/**
185-
* @param label
186-
* @param value
187-
* @param description
188-
*/
189-
public KVP(String label, byte[] value, String description) {
190-
this.label = label;
191-
this.byteValue = value;
177+
public KVP(String label, byte[] byteArray) {
178+
this.label = label;
179+
this.byteValue = byteArray;
192180
this.byteStart = 0;
193-
this.byteLen = value.length;
194-
this.description = description;
181+
this.byteLen = byteArray.length;
195182
this.fieldType = FIELD_TYPE.BYTES;
196-
detailViews.add(new DetailView((HTMLSource)() -> getHTMLHexview(byteValue, byteStart, byteLen),"Hex View"));
183+
addHTMLSource(() -> getHTMLHexview(byteValue, byteStart, byteLen), "Hex View");
197184
}
198185

199-
public KVP(String label, byte[] value, int offset, int len, String description) {
200-
this.label = label;
201-
this.byteValue = value;
186+
public KVP(String label, byte[] byteArray, String description) {
187+
this(label, byteArray);
188+
setDescription(description);
189+
}
190+
191+
public KVP(String label, byte[] byteArray, int offset, int len) {
192+
this.label = label;
193+
this.byteValue = byteArray;
202194
this.byteStart = offset;
203195
this.byteLen = len;
204-
this.description = description;
205196
this.fieldType = FIELD_TYPE.BYTES;
206-
detailViews.add(new DetailView((HTMLSource)() -> getHTMLHexview(byteValue, byteStart, byteLen),"Hex View"));
197+
addHTMLSource(() -> getHTMLHexview(byteValue, byteStart, byteLen), "Hex View");
207198
}
208199

209-
public KVP(String label, DVBString value, String description) {
210-
this.label = label;
211-
this.dvbStringValue = value;
212-
this.description = description;
213-
this.fieldType = FIELD_TYPE.DVBSTRING;
200+
public KVP(String label, byte[] byteArray, int offset, int len, String description) {
201+
this(label, byteArray, offset, len);
202+
setDescription(description);
214203
}
215204

216-
public KVP(String label, HTMLSource htmlSource) {
205+
public KVP(String label, DVBString dvbStringValue) {
217206
this.label = label;
218-
this.fieldType = FIELD_TYPE.LABEL;
219-
detailViews.add(new DetailView(htmlSource,""));
207+
this.dvbStringValue = dvbStringValue;
208+
this.fieldType = FIELD_TYPE.DVBSTRING;
209+
this.add(new KVP("encoding", dvbStringValue.getEncodingString()));
210+
this.add(new KVP("length", dvbStringValue.getLength()));
211+
this.addHTMLSource(
212+
() ->"<b>Encoding:</b> " + dvbStringValue.getEncodingString()
213+
+ "<br><br><b>Data:</b><br>" + getHTMLHexview(dvbStringValue.getData(), dvbStringValue.getOffset() + 1, dvbStringValue.getLength())
214+
+ "<br><b>Formatted:</b><br>" + dvbStringValue.toEscapedHTML(),
215+
"DVB String");
220216
}
221217

222-
public KVP(String label, BigInteger value, String description) {
218+
219+
public KVP(String label, BigInteger bigIntegerValue) {
223220

224221
this.label = label;
225-
this.bigIntegerValue = value;
222+
this.bigIntegerValue = bigIntegerValue;
226223
this.fieldType = FIELD_TYPE.BIGINT;
227-
this.description = description;
228224
}
229225

226+
public KVP(String label, BigInteger bigIntegerValue, String description) {
227+
this(label, bigIntegerValue);
228+
setDescription(description);
229+
}
230+
230231
public String getDescription() {
231232
return description;
232233
}
233234

234-
public void setDescription(String description) {
235+
public KVP setDescription(String description) {
235236
this.description = description;
237+
return this;
236238
}
237239

238240
public String getLabel() {
239241
return label;
240242
}
241243

242-
public void setLabel(String label) {
244+
public KVP setLabel(String label) {
243245
this.label = label;
246+
return this;
244247
}
245248

246249
// put appends in separate String, so original label is constant and available for path
247250
public void appendLabel(String labelAppend) {
248251
this.labelAppend = this.labelAppend + labelAppend;
249252
}
250253

251-
public String getValue() {
252-
return value;
253-
}
254-
255-
public void setValue(String value) {
256-
this.value = value;
257-
}
258254

259255
@Override
260256
public String toString() {
261257
return toString(stringDisplay,numberDisplay);
262258
}
263259

264260
public String toString(STRING_DISPLAY stringFormat, NUMBER_DISPLAY numberFormat) {
265-
StringBuilder b = new StringBuilder(label);
261+
StringBuilder b = new StringBuilder();
262+
if ((htmlLabel != null) && (STRING_DISPLAY.PLAIN != stringFormat)) {
263+
b.append(htmlLabel);
264+
} else {
265+
b.append(label);
266+
}
266267
if(!labelAppend.isEmpty()) {
267268
b.append(labelAppend);
268269
}
269270

270-
if ((fieldType != FIELD_TYPE.LABEL)&&(fieldType != FIELD_TYPE.HTML)) {
271+
if (fieldType != FIELD_TYPE.LABEL) {
271272
appendValueAfterLabel(numberFormat, b);
272273
}
273-
if((fieldType==FIELD_TYPE.HTML)&&(STRING_DISPLAY.PLAIN!=stringFormat)){
274-
b = replacePlainLabelWithHTML(stringFormat);
275-
}
276274
if (stringFormat == STRING_DISPLAY.JAVASCRIPT) {
277-
return b.toString().replace("\"", "\\\"").replace("\'", "\\\'");
275+
return b.toString().replace("\"", "\\\"").replace("\'", "\\\'");
276+
}
277+
if ((htmlLabel != null) && (stringFormat == STRING_DISPLAY.HTML_AWT)) {
278+
return new StringBuilder("<html>").append(b).append("</html>").toString();
278279
}
279280
return b.toString();
280281
}
281282

282283

283-
private StringBuilder replacePlainLabelWithHTML(STRING_DISPLAY stringFormat) {
284-
if(stringFormat==STRING_DISPLAY.HTML_AWT){
285-
return new StringBuilder("<html>").append(value).append("</html>");
286-
}else if(stringFormat==STRING_DISPLAY.HTML_FRAGMENTS){
287-
return new StringBuilder(value);
288-
}
289-
return new StringBuilder();
290-
}
291-
292284
/**
293285
* @param numberFormat
294286
* @param b
@@ -349,7 +341,7 @@ private void appendHexBytes(StringBuilder b) {
349341
* @param b
350342
*/
351343
private void appendString(StringBuilder b) {
352-
b.append(value);
344+
b.append(stringValue);
353345
}
354346

355347
/**
@@ -435,16 +427,18 @@ public JMenuItem getSubMenu() {
435427
* @param subMenu the subMenu to set
436428
* @param owner the owner to set
437429
*/
438-
public void setSubMenuAndOwner(JMenuItem subMenu, Object owner) {
430+
public KVP setSubMenuAndOwner(JMenuItem subMenu, Object owner) {
439431
this.subMenu = subMenu;
440432
this.owner = owner;
433+
return this;
441434
}
442435

443436
/**
444437
* @param subMenu the subMenu to set
445438
*/
446-
public void setSubMenu(JMenuItem subMenu) {
439+
public KVP setSubMenu(JMenuItem subMenu) {
447440
this.subMenu = subMenu;
441+
return this;
448442
}
449443

450444
/**
@@ -485,28 +479,45 @@ public String getCrumb() {
485479

486480

487481

488-
public void setCrumb(String path) {
482+
public KVP setCrumb(String path) {
489483
this.crumb = path;
484+
return this;
490485
}
491486

492487
public List<DetailView> getDetailViews() {
493488
return detailViews;
494489
}
495490

496-
public void addHTMLSource(HTMLSource htmlSource, String label) {
491+
public KVP addHTMLSource(HTMLSource htmlSource, String label) {
497492
detailViews.add(new DetailView(htmlSource, label));
493+
return this;
498494
}
499495

500-
public void addImageSource(ImageSource imageSource, String label) {
496+
public KVP addImageSource(ImageSource imageSource, String label) {
501497
detailViews.add(new DetailView(imageSource, label));
498+
return this;
502499
}
503500

504-
public void addTableSource(TableSource tableSource, String label) {
501+
public KVP addTableSource(TableSource tableSource, String label) {
505502
detailViews.add(new DetailView(tableSource, label));
503+
return this;
506504
}
507505

508-
public void addXMLSource(XMLSource xmlSource, String label) {
506+
public KVP addXMLSource(XMLSource xmlSource, String label) {
509507
detailViews.add(new DetailView(xmlSource, label));
508+
return this;
510509
}
511510

511+
@Override
512+
public Object getUserObject() {
513+
return this;
514+
}
515+
516+
public KVP setHtmlLabel(String htmlLabel) {
517+
this.htmlLabel = htmlLabel;
518+
return this;
519+
}
520+
521+
522+
512523
}

src/main/java/nl/digitalekabeltelevisie/data/mpeg/AVCHDPacket.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public int getArrivalTimestamp() {
7474
@Override
7575
public DefaultMutableTreeNode getJTreeNode(final int modus) {
7676

77-
final DefaultMutableTreeNode t = new DefaultMutableTreeNode(new KVP(buildNodeLabel(),this));
77+
final KVP kvp = new KVP(buildNodeLabel());
78+
kvp.addHTMLSource(this, "AVCHD Packet");
79+
final DefaultMutableTreeNode t = new DefaultMutableTreeNode(kvp);
7880
final DefaultMutableTreeNode tpHeaderNode = new DefaultMutableTreeNode(new KVP("tp_extra_header",tp_extra_header,null));
7981
tpHeaderNode.add(new DefaultMutableTreeNode(new KVP("Copy_permission_indicator",getCopyPermissionIndicator(),null)));
8082
tpHeaderNode.add(new DefaultMutableTreeNode(new KVP("Arrival_time_stamp",arrivalTimestamp,printPCRTime(arrivalTimestamp))));

src/main/java/nl/digitalekabeltelevisie/data/mpeg/PSI.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
package nl.digitalekabeltelevisie.data.mpeg;
2929

30-
import javax.swing.tree.DefaultMutableTreeNode;
31-
3230
import nl.digitalekabeltelevisie.controller.KVP;
3331
import nl.digitalekabeltelevisie.data.mpeg.dsmcc.DSMCCs;
3432
import nl.digitalekabeltelevisie.data.mpeg.psi.*;
@@ -67,9 +65,9 @@ public class PSI {
6765
private final M7Fastscan m7fastscan = new M7Fastscan(this);
6866

6967

70-
public DefaultMutableTreeNode getJTreeNode(final int modus){
68+
public KVP getJTreeNode(final int modus){
7169

72-
final DefaultMutableTreeNode t = new DefaultMutableTreeNode(new KVP("PSI"));
70+
final KVP t = new KVP("PSI");
7371
t.add(pat.getJTreeNode(modus));
7472
t.add(cat.getJTreeNode(modus));
7573
t.add(bat.getJTreeNode(modus));

0 commit comments

Comments
 (0)