Skip to content

Commit

Permalink
feat: Added Formated and Scientific displays
Browse files Browse the repository at this point in the history
- Corrected an annoyance with the Cell text having trailing zero on floats
- Bumping version to 0.1.4.26
- New screenshots

Closes: #2
  • Loading branch information
gcarreno committed Feb 1, 2021
1 parent 66e0d97 commit 0f43694
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 39 deletions.
30 changes: 20 additions & 10 deletions data/test1.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"TestNull" : null,
"TestInteger" : 255,
"TestInt64" : 123124125126,
"TestFloat" : 120.3,
"TestString" : "String Value",
"TestBoolean" : false,
"TestArray" : [ null, 1, 2.2, "String Value", true ],
"TestObject" : {
"TestObjectString" : "String Value"
}
"TestNull" : null,
"TestInteger" : 255,
"TestInt64" : 123124125126,
"TestFloat" : 120.3,
"TestString" : "String Value",
"TestBoolean" : false,
"TestArray" : [
null,
0,
-1,
-1024,
2.2,
1024.03,
-0.425,
"String Value",
true
],
"TestObject" : {
"TestObjectString" : "String Value"
}
}
Binary file modified images/lazJSONViewer-picture1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/lazJSONViewer-picture2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/lazJSONViewer-picture3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/application/ljv.application.version.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
interface

const
cVersion = '0.1.3.26';
cVersion = '0.1.4.26';
cVersionMajor = 0;
cVersionMinor = 1;
cVersionRevision = 3;
cVersionRevision = 4;
cVersionBuild = 26;

implementation
Expand Down
3 changes: 1 addition & 2 deletions src/forms/ljv.forms.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ object frmMain: TfrmMain
ClientWidth = 1017
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '2.1.0.0'
object psMain: TPairSplitter
Cursor = crDefault
Left = 224
Expand Down Expand Up @@ -36,7 +35,7 @@ object frmMain: TfrmMain
Header.Columns = <
item
Position = 0
Width = 400
Width = 398
end>
Header.Options = [hoAutoResize, hoColumnResize, hoDrag, hoShowSortGlyphs]
TabOrder = 0
Expand Down
91 changes: 67 additions & 24 deletions src/forms/ljv.forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ implementation
rsLabelCountObject = 'Members: %d';
rsLabelCountNA = 'N/A';

rsLabelFormated = 'Formated';
rsLabelBinary = 'Binary';
rsLabelHexadecimal = 'Hexadecimal';
rsLabelDateTime = 'Date';
rsLabelBytes = 'Bytes';
rsLabelScientific = 'Scientific';

rsBytes = ' B';
rsKiloBytes = ' KB';
Expand All @@ -140,6 +142,10 @@ implementation
const
cDateTimeFormat = 'yyyy/mm/dd hh:nn:ss';

cNumberFormatInteger = '#,##0';
cNumberFormatFloat = '#,##0.###############';
cNumberFormatFloatScientific = '0.###############E+0';

{ TfrmMain }

procedure TfrmMain.FormCreate(Sender: TObject);
Expand Down Expand Up @@ -307,7 +313,7 @@ procedure TfrmMain.vstJSONGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
CellText:= Format('%s: %d', [treeNode^.NodeName, jNumber.AsInt64]);
end;
ntFloat:begin
CellText:= Format('%s: %n', [treeNode^.NodeName, jNumber.AsFloat]);
CellText:= Format('%s: %s', [treeNode^.NodeName, FloatToStr(jNumber.AsFloat)]);
end;
ntQWord:begin
CellText:= Format('%s: %d', [treeNode^.NodeName, jNumber.AsQWord]);
Expand All @@ -326,7 +332,7 @@ procedure TfrmMain.vstJSONGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
CellText:= Format('%d: %d', [treeNode^.NodeIndex, jNumber.AsInt64]);
end;
ntFloat:begin
CellText:= Format('%d: %n', [treeNode^.NodeIndex, jNumber.AsFloat]);
CellText:= Format('%d: %s', [treeNode^.NodeIndex, FloatToStr(jNumber.AsFloat)]);
end;
ntQWord:begin
CellText:= Format('%d: %d', [treeNode^.NodeIndex, jNumber.AsQWord]);
Expand All @@ -343,7 +349,7 @@ procedure TfrmMain.vstJSONGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
CellText:= Format('%d', [jNumber.AsInt64]);
end;
ntFloat:begin
CellText:= Format('%n', [jNumber.AsFloat]);
CellText:= FloatToStr(jNumber.AsFloat);
end;
ntQWord:begin
CellText:= Format('%d', [jNumber.AsQWord]);
Expand Down Expand Up @@ -624,9 +630,8 @@ procedure TfrmMain.UpdateTreeFromNode(const ANode: PVirtualNode;
procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
var
posY: Integer;
lbl, lblBin, lblHex, lblBytes, lblDateTime: TLabel;
edt, edtBin, edtHex, edtBytes, edtDateTime, edtFloat: TEdit;
//tmpInt64: Int64;
lbl, lblFormated, lblBin, lblHex, lblBytes, lblDateTime, lblScientific: TLabel;
edt, edtFormated, edtBin, edtHex, edtBytes, edtDateTime, edtScientific: TEdit;
mem: TMemo;
begin
repeat
Expand All @@ -643,6 +648,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
jtNumber:begin
posY:= 8;

// Value
edt:= TEdit.Create(panValue);
edt.Parent:= panValue;
edt.Top:= posY;
Expand All @@ -652,8 +658,51 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edt.ReadOnly:= True;
Inc(posY, 50);

// Formated
lblFormated:= TLabel.Create(panValue);
lblFormated.Parent:= panValue;
lblFormated.Top:= posY;
lblFormated.Left:=8;
if TJSONNumber(AJSONData).NumberType = ntFloat then
begin
lblFormated.Caption:= Format('%s (%s)',[rsLabelFormated, cNumberFormatFloat]);;
end
else
begin
lblFormated.Caption:= Format('%s (%s)',[rsLabelFormated, cNumberFormatInteger]);;
end;
Inc(posY, 17);

edtFormated:= TEdit.Create(panValue);
edtFormated.Parent:= panValue;
edtFormated.Top:= posY;
edtFormated.Left:= 8;
edtFormated.Width:= panValue.ClientWidth - 16;
edtFormated.Anchors:= [akTop, akLeft, akRight];
edtFormated.ReadOnly:= True;
Inc(posY, 34);

// Scientific
lblScientific:= TLabel.Create(panValue);
lblScientific.Parent:= panValue;
lblScientific.Top:= posY;
lblScientific.Left:=8;
lblScientific.Caption:= rsLabelScientific;
lblScientific.Caption:= Format('%s (%s)',[rsLabelScientific, cNumberFormatFloatScientific]);;
Inc(posY, 17);

edtScientific:= TEdit.Create(panValue);
edtScientific.Parent:= panValue;
edtScientific.Top:= posY;
edtScientific.Left:= 8;
edtScientific.Width:= panValue.ClientWidth - 16;
edtScientific.Anchors:= [akTop, akLeft, akRight];
edtScientific.ReadOnly:= True;
Inc(posY, 34);

if TJSONNumber(AJSONData).NumberType in [ntInteger, ntInt64, ntQWord] then
begin
// Binary
lblBin:= TLabel.Create(panValue);
lblBin.Parent:= panValue;
lblBin.Top:= posY;
Expand All @@ -670,6 +719,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edtBin.ReadOnly:= True;
Inc(posY, 34);

// Hexadecimal
lblHex:= TLabel.Create(panValue);
lblHex.Parent:= panValue;
lblHex.Top:= posY;
Expand All @@ -686,6 +736,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edtHex.ReadOnly:= True;
Inc(posY, 34);

// Bytes
lblBytes:= TLabel.Create(panValue);
lblBytes.Parent:= panValue;
lblBytes.Top:= posY;
Expand All @@ -702,6 +753,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edtBytes.ReadOnly:= True;
Inc(posY, 34);

// DateTime
lblDateTime:= TLabel.Create(panValue);
lblDateTime.Parent:= panValue;
lblDateTime.Top:= posY;
Expand All @@ -719,43 +771,34 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
Inc(posY, 34);
end;

if TJSONNumber(AJSONData).NumberType = ntFloat then
begin
edtFloat:= TEdit.Create(panValue);
edtFloat.Parent:= panValue;
edtFloat.Top:= posY;
edtFloat.Left:= 8;
edtFloat.Width:= panValue.ClientWidth - 16;
edtFloat.Anchors:= [akTop, akLeft, akRight];
edtFloat.ReadOnly:= True;
Inc(posY, 34);
end;

case TJSONNumber(AJSONData).NumberType of
ntInteger:begin
edt.Text:= Format('%d', [AJSONData.AsInteger]);
edtFormated.Text:= FormatFloat(cNumberFormatInteger, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
edtBin.Text:= IntToBin(AJSONData.AsInt64, 32);
edtHex.Text:= IntToHex(AJSONData.AsInteger, 16);
edtBytes.Text:= FormatBytes(AJSONData.AsInteger);
edtDateTime.Text:= FormatDateTime(cDateTimeFormat, UnixToDateTime(AJSONData.AsInteger));
end;
ntInt64:begin
//tmpInt64:= AJSONData.AsInt64;
edt.Text:= Format('%d', [AJSONData.AsInt64]);

{ #todo -ogcarreno : Need to fix IntToBin only outputting 32 bits }
edtFormated.Text:= FormatFloat(cNumberFormatInteger, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
edtBin.Text:= IntToBin(AJSONData.AsInt64, 64);

edtHex.Text:= IntToHex(AJSONData.AsInt64, 16);
edtBytes.Text:= FormatBytes(AJSONData.AsInt64);
edtDateTime.Text:= FormatDateTime(cDateTimeFormat, UnixToDateTime(AJSONData.AsInt64));
end;
ntFloat:begin
edt.Text:= Format('%n', [AJSONData.AsFloat]);
edtFloat.Text:= AJSONData.AsString;
edt.Text:= FloatToStr(AJSONData.AsFloat);
edtFormated.Text:= FormatFloat(cNumberFormatFloat, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
end;
ntQWord:begin
edt.Text:= Format('%d', [AJSONData.AsQWord]);
edtFormated.Text:= FormatFloat(cNumberFormatInteger, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
edtBin.Text:= IntToBin(AJSONData.AsInt64, 64);
edtHex.Text:= IntToHex(AJSONData.AsQWord, 16);
edtBytes.Text:= FormatBytes(AJSONData.AsQWord);
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ msgstr ""
msgid "Date"
msgstr ""

#: ljv.forms.main.rslabelformated
msgid "Formated"
msgstr ""

#: ljv.forms.main.rslabelhexadecimal
msgid "Hexadecimal"
msgstr ""
Expand All @@ -80,6 +84,10 @@ msgstr ""
msgid "Name: \"%s\""
msgstr ""

#: ljv.forms.main.rslabelscientific
msgid "Scientific"
msgstr ""

#: ljv.forms.main.rslabeltype
#, object-pascal-format
msgid "Type: %s"
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ msgstr "Membros: %d"
msgid "Date"
msgstr "Data"

#: ljv.forms.main.rslabelformated
msgid "Formated"
msgstr "Formatado"

#: ljv.forms.main.rslabelhexadecimal
msgid "Hexadecimal"
msgstr "Hexadecimal"
Expand All @@ -81,6 +85,10 @@ msgstr "Nome/Índice do Nó"
msgid "Name: \"%s\""
msgstr "Nome: \"%s\""

#: ljv.forms.main.rslabelscientific
msgid "Scientific"
msgstr "Cientifico"

#: ljv.forms.main.rslabeltype
#, object-pascal-format
msgid "Type: %s"
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pt_PT.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ msgstr "Membros: %d"
msgid "Date"
msgstr "Data"

#: ljv.forms.main.rslabelformated
msgid "Formated"
msgstr "Formatado"

#: ljv.forms.main.rslabelhexadecimal
msgid "Hexadecimal"
msgstr "Hexadecimal"
Expand All @@ -81,6 +85,10 @@ msgstr "Nome/Índice do Nó"
msgid "Name: \"%s\""
msgstr "Nome: \"%s\""

#: ljv.forms.main.rslabelscientific
msgid "Scientific"
msgstr "Cientifico"

#: ljv.forms.main.rslabeltype
#, object-pascal-format
msgid "Type: %s"
Expand Down
2 changes: 1 addition & 1 deletion src/lazJSONViewer.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<VersionInfo>
<UseVersionInfo Value="True"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="3"/>
<RevisionNr Value="4"/>
<BuildNr Value="26"/>
<Language Value="0809"/>
</VersionInfo>
Expand Down
Binary file modified src/lazJSONViewer.res
Binary file not shown.

0 comments on commit 0f43694

Please sign in to comment.