@@ -70,6 +70,32 @@ public class KVP{
70
70
71
71
public record DetailView (DetailSource detailSource , String label ) {}
72
72
73
+ public enum NUMBER_DISPLAY {
74
+ DECIMAL ,
75
+ HEX ,
76
+ BOTH
77
+ }
78
+
79
+ public enum STRING_DISPLAY {
80
+ PLAIN , // plain
81
+ JAVASCRIPT , // javascript escaped (quotes removed)
82
+ HTML_FRAGMENTS , // HTML fragments '<' and '&' escaped,
83
+ HTML_AWT // AWT HTML (html segments include <html> tag, otherwise plain text
84
+ }
85
+
86
+ public enum FIELD_TYPE {
87
+ STRING ,
88
+ BYTES ,
89
+ INT ,
90
+ LONG ,
91
+
92
+ LABEL , //used for a node that has no value associated with it
93
+ 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
95
+
96
+ BIGINT
97
+ }
98
+
73
99
/**
74
100
* maximum length of byte[] to be shown in JTree, only has meaning in case data is array of byte.
75
101
*/
@@ -86,43 +112,12 @@ public record DetailView(DetailSource detailSource, String label) {}
86
112
private DVBString dvbStringValue ;
87
113
private BigInteger bigIntegerValue ;
88
114
89
- private static byte numberDisplay = 1 ; // 1 - decimal, 2 -
90
- // hex, 3 both
91
- // ,example "0xA0
92
- // (160)"
93
- public static final byte NUMBER_DISPLAY_DECIMAL = 1 ;
94
- public static final byte NUMBER_DISPLAY_HEX = 2 ;
95
- public static final byte NUMBER_DISPLAY_BOTH = 3 ;
96
-
97
- private static byte stringDisplay = 1 ;
98
- // 1 - plain,
99
- // 2 - javascript escaped (quotes removed),
100
- // 3 - HTML fragments '<' and '&' escaped,
101
- // 4 - AWT HTML (html segments include <html> tag, otherwise plain text
102
- public static final byte STRING_DISPLAY_PLAIN = 1 ;
103
- public static final byte STRING_DISPLAY_JAVASCRIPT = 2 ;
104
- public static final byte STRING_DISPLAY_HTML_FRAGMENTS = 3 ;
105
- public static final byte STRING_DISPLAY_HTML_AWT = 4 ;
106
-
107
- private FIELD_TYPE fieldType = FIELD_TYPE .STRING ;
108
-
109
- public enum FIELD_TYPE {
110
- STRING ,
111
- BYTES ,
112
- INT ,
113
- LONG ,
114
-
115
- LABEL , //used for a node that has no value associated with it
116
- DVBSTRING ,
117
- 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
118
-
119
- BIGINT
120
-
121
- }
115
+ private static NUMBER_DISPLAY numberDisplay = NUMBER_DISPLAY .DECIMAL ; // 1 - decimal, 2 -
116
+ private static STRING_DISPLAY stringDisplay = STRING_DISPLAY .PLAIN ;
122
117
118
+ private FIELD_TYPE fieldType ;
123
119
124
120
private List <DetailView > detailViews = new ArrayList <>();
125
-
126
121
127
122
/**
128
123
* 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() {
271
266
return toString (stringDisplay ,numberDisplay );
272
267
}
273
268
274
- public String toString (byte stringFormat , byte numberFormat ) {
269
+ public String toString (STRING_DISPLAY stringFormat , NUMBER_DISPLAY numberFormat ) {
275
270
StringBuilder b = new StringBuilder (label );
276
271
if (!labelAppend .isEmpty ()) {
277
272
b .append (labelAppend );
@@ -280,20 +275,20 @@ public String toString(byte stringFormat, byte numberFormat) {
280
275
if ((fieldType != FIELD_TYPE .LABEL )&&(fieldType != FIELD_TYPE .HTML )) {
281
276
appendValueAfterLabel (numberFormat , b );
282
277
}
283
- if ((fieldType ==FIELD_TYPE .HTML )&&(STRING_DISPLAY_PLAIN !=stringFormat )){
278
+ if ((fieldType ==FIELD_TYPE .HTML )&&(STRING_DISPLAY . PLAIN !=stringFormat )){
284
279
b = replacePlainLabelWithHTML (stringFormat );
285
280
}
286
- if (stringFormat == STRING_DISPLAY_JAVASCRIPT ) {
281
+ if (stringFormat == STRING_DISPLAY . JAVASCRIPT ) {
287
282
return b .toString ().replace ("\" " , "\\ \" " ).replace ("\' " , "\\ \' " );
288
283
}
289
284
return b .toString ();
290
285
}
291
286
292
287
293
- private StringBuilder replacePlainLabelWithHTML (byte stringFormat ) {
294
- if (stringFormat ==STRING_DISPLAY_HTML_AWT ){
288
+ private StringBuilder replacePlainLabelWithHTML (STRING_DISPLAY stringFormat ) {
289
+ if (stringFormat ==STRING_DISPLAY . HTML_AWT ){
295
290
return new StringBuilder ("<html>" ).append (value ).append ("</html>" );
296
- }else if (stringFormat ==STRING_DISPLAY_HTML_FRAGMENTS ){
291
+ }else if (stringFormat ==STRING_DISPLAY . HTML_FRAGMENTS ){
297
292
return new StringBuilder (value );
298
293
}
299
294
return new StringBuilder ();
@@ -303,7 +298,7 @@ private StringBuilder replacePlainLabelWithHTML(byte stringFormat) {
303
298
* @param numberFormat
304
299
* @param b
305
300
*/
306
- private void appendValueAfterLabel (byte numberFormat , StringBuilder b ) {
301
+ private void appendValueAfterLabel (NUMBER_DISPLAY numberFormat , StringBuilder b ) {
307
302
b .append (": " );
308
303
switch (fieldType ){
309
304
case STRING :
@@ -366,10 +361,10 @@ private void appendString(StringBuilder b) {
366
361
* @param numberFormat
367
362
* @param b
368
363
*/
369
- private void appendLong (byte numberFormat , StringBuilder b ) {
370
- if (numberFormat == NUMBER_DISPLAY_DECIMAL ) {
364
+ private void appendLong (NUMBER_DISPLAY numberFormat , StringBuilder b ) {
365
+ if (numberFormat == NUMBER_DISPLAY . DECIMAL ) {
371
366
b .append (longValue );
372
- } else if (numberFormat == NUMBER_DISPLAY_HEX ) {
367
+ } else if (numberFormat == NUMBER_DISPLAY . HEX ) {
373
368
b .append ("0x" ).append (Long .toHexString (longValue ).toUpperCase ());
374
369
} else { // assume both to be safe
375
370
b .append ("0x" ).append (Long .toHexString (longValue ).toUpperCase ()).append (" (" ).append (longValue )
@@ -381,50 +376,50 @@ private void appendLong(byte numberFormat, StringBuilder b) {
381
376
* @param numberFormat
382
377
* @param b
383
378
*/
384
- private void appendInteger (byte numberFormat , StringBuilder b ) {
385
- if (numberFormat == NUMBER_DISPLAY_DECIMAL ) {
379
+ private void appendInteger (NUMBER_DISPLAY numberFormat , StringBuilder b ) {
380
+ if (numberFormat == NUMBER_DISPLAY . DECIMAL ) {
386
381
b .append (intValue );
387
- } else if (numberFormat == NUMBER_DISPLAY_HEX ) {
382
+ } else if (numberFormat == NUMBER_DISPLAY . HEX ) {
388
383
b .append ("0x" ).append (Integer .toHexString (intValue ).toUpperCase ());
389
384
} else { // assume both to be safe
390
385
b .append (getHexAndDecimalFormattedString (intValue ));
391
386
}
392
387
}
393
388
394
- private void appendBigInteger (byte numberFormat , StringBuilder b ) {
395
- if (numberFormat == NUMBER_DISPLAY_DECIMAL ) {
389
+ private void appendBigInteger (NUMBER_DISPLAY numberFormat , StringBuilder b ) {
390
+ if (numberFormat == NUMBER_DISPLAY . DECIMAL ) {
396
391
b .append (bigIntegerValue .toString ());
397
- } else if (numberFormat == NUMBER_DISPLAY_HEX ) {
392
+ } else if (numberFormat == NUMBER_DISPLAY . HEX ) {
398
393
b .append ("0x" ).append (bigIntegerValue .toString (16 ).toUpperCase ());
399
394
} else { // assume both to be safe
400
395
b .append (getHexAndDecimalFormattedString (bigIntegerValue ));
401
396
}
402
397
}
403
398
404
399
405
- public static byte getNumberDisplay () {
400
+ public static NUMBER_DISPLAY getNumberDisplay () {
406
401
return numberDisplay ;
407
402
}
408
403
409
- public static void setNumberDisplay (byte intDisplay ) {
404
+ public static void setNumberDisplay (NUMBER_DISPLAY intDisplay ) {
410
405
numberDisplay = intDisplay ;
411
406
}
412
407
413
408
public static String formatInt (int intValue ) {
414
- if (numberDisplay == NUMBER_DISPLAY_DECIMAL ) {
409
+ if (numberDisplay == NUMBER_DISPLAY . DECIMAL ) {
415
410
return Integer .toString (intValue );
416
- } else if (numberDisplay == NUMBER_DISPLAY_HEX ) {
411
+ } else if (numberDisplay == NUMBER_DISPLAY . HEX ) {
417
412
return ("0x" ) + Integer .toHexString (intValue ).toUpperCase ();
418
413
} else { // assume both to be safe
419
- return ("0x" + Integer .toHexString (intValue ).toUpperCase ()) + " (" + Integer . toString ( intValue ) + (")" );
414
+ return ("0x" + Integer .toHexString (intValue ).toUpperCase ()) + " (" + intValue + (")" );
420
415
}
421
416
}
422
417
423
- public static byte getStringDisplay () {
418
+ public static STRING_DISPLAY getStringDisplay () {
424
419
return stringDisplay ;
425
420
}
426
421
427
- public static void setStringDisplay (byte stringDisplay ) {
422
+ public static void setStringDisplay (STRING_DISPLAY stringDisplay ) {
428
423
KVP .stringDisplay = stringDisplay ;
429
424
}
430
425
/**
@@ -436,7 +431,7 @@ public void setImageSource(ImageSource imageSource) {
436
431
}
437
432
438
433
public String getPlainText (){
439
- return toString (STRING_DISPLAY_PLAIN , NUMBER_DISPLAY_BOTH );
434
+ return toString (STRING_DISPLAY . PLAIN , NUMBER_DISPLAY . BOTH );
440
435
}
441
436
442
437
0 commit comments