Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim lv As ListView
Dim fsv As JavaObject
Dim swingUtils As JavaObject
Dim directory As String = ""
Dim depth As List
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
depth.Initialize
fsv.InitializeStatic("javax.swing.filechooser.FileSystemView")
swingUtils.InitializeStatic("javafx.embed.swing.SwingFXUtils")
directory = "c:/temp"
lv.Initialize("lv")
MainForm.RootPane.AddNode(lv,10,10,500,500)
If Not(directory.EndsWith("/")) Then directory=directory&"/"
depth.Add(directory)
buildFileList(directory)
End Sub
Sub buildFileList(root As String)
lv.Items.Clear
lv.Items.Add(buildPane(new("java.io.File",Array(root)),True))
For Each f As Object In File.ListFiles(root)
lv.Items.Add(buildPane(new("java.io.File",Array(root & f)),False))
Next
End Sub
Sub lv_SelectedIndexChanged(Index As Int)
If Index = -1 Then Return
If Index = 0 And depth.Size > 1 Then
directory=depth.Get(depth.Size - 2)
depth.RemoveAt(depth.Size-1)
buildFileList(directory)
Return
End If
If File.IsDirectory(directory,asLabel(asPane(lv.Items.Get(Index)).GetNode(1)).Text) Then
directory = directory & asLabel(asPane(lv.Items.Get(Index)).GetNode(1)).Text&"/"
depth.Add(directory)
buildFileList(directory)
Return
End If
Log("You chose : " & asLabel(asPane(lv.Items.Get(Index)).GetNode(1)).Text)
End Sub
Sub getIcon(s As JavaObject) As Image
Return swingUtils.RunMethod("toFXImage",Array(fsv.RunMethodJO("getFileSystemView",Null).RunMethodjo("getSystemIcon",Array(s)).RunMethod("getImage",Null),Null))
End Sub
Sub buildPane(fi As JavaObject,r As Boolean) As Pane
Dim p As Pane
p.Initialize("")
Dim iv As ImageView
iv.Initialize("")
Dim lab,lab1,lab2 As Label
lab.Initialize("")
lab1.Initialize("")
lab2.Initialize("")
iv.SetImage(getIcon(fi))
lab.text = fsv.RunMethodJO("getFileSystemView",Null).RunMethod("getSystemDisplayName",Array(fi))
lab.TooltipText = lab.text & CRLF & _
fileSize(fi.RunMethod("length",Null))
lab1.Text ="["& fsv.RunMethodJO("getFileSystemView",Null).RunMethod("getSystemTypeDescription",Array(fi))&"]"
Dim offset As Int = 20
If r Then offset = 0
p.AddNode(iv,offset+0,0,20,20)
p.AddNode(lab,offset+25,0,200,20)
p.AddNode(lab1,250,0,200,20)
Return p
End Sub
Sub new(className As String,args() As Object) As JavaObject
Dim j As JavaObject
Return j.InitializeNewInstance(className,args)
End Sub
Sub asLabel(l As Object) As Label
Return l
End Sub
Sub asPane(p As Object) As Pane
Return p
End Sub
Sub fileSize(s As Long) As String
Dim t As Double
Dim gb As Long = 1024*1024*1024
Dim mb As Long = 1024*1024
Dim kb As Long = 1024
Select True
Case s>gb
t = s/gb
Return NumberFormat(t,1,0)& "GB"
Case s>mb
t = s/mb
Return NumberFormat(t,1,0)& " MB"
Case s>kb
t = s/kb
Return NumberFormat(t,1,0)& " KB"
Case Else
Return s&" Bytes"
End Select
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub