-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.b4j
96 lines (83 loc) · 2.21 KB
/
main.b4j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
AppType=JavaFX
Build1=Default,serialnotification.solutionbase.co.uk
File1=617954.png
File2=Blue.png
File3=popup.bjl
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
Group=Default Group
Library1=jcore
Library2=jfx
Library3=jsystemtray
Library4=jserial
NumberOfFiles=3
NumberOfLibraries=4
NumberOfModules=0
Version=6.01
@EndOfDesignText@
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private Serial As Serial
Private Timer As Timer
Private Ports As List
Private tray As SystemTray
Private Icon1 As TrayIcon
Private SerialImage As Image
Private lbl As Label
End Sub
Sub AppStart (Form1 As Form, Args() As String)
SerialImage = fx.LoadImage(File.DirAssets, "617954.png")
tray.Initialize
Dim MenuItems() As String = Array As String("Exit")
Icon1.Initialize("Icon1", SerialImage, MenuItems)
Icon1.ToolTip = "Displays serial port notifiations when new port detected. Right click to show menu."
tray.AddTrayIcon(Icon1)
Serial.Initialize("")
Timer.Initialize("Timer", 1500)
Timer.Enabled = True
Ports = Serial.ListPorts
End Sub
Sub Timer_Tick()
Dim pl As List = Serial.ListPorts
For i = 0 To pl.Size - 1
If Ports.IndexOf(pl.Get(i)) == -1 Then
Display(pl.Get(i))
End If
Next
Ports = Serial.ListPorts
End Sub
Sub Display(text As String)
Dim popup As Form
popup.Initialize("popup", 140, 46)
popup.Icon = SerialImage
popup.AlwaysOnTop = True
popup.SetFormStyle("TRANSPARENT")
popup.BackColor = fx.Colors.Transparent
popup.RootPane.LoadLayout("popup")
popup.WindowLeft = fx.PrimaryScreen.MaxX - 140 - 10
popup.WindowTop = fx.PrimaryScreen.MaxY - 46 - 10
lbl.Text = text
popup.Show
popup.RootPane.Alpha = 0
popup.RootPane.SetAlphaAnimated(750, 1)
Wait For (popup.RootPane) popup_AnimationCompleted
Sleep(2000)
popup.RootPane.SetAlphaAnimated(750, 0)
Wait For (popup.RootPane) popup_AnimationCompleted
popup.Close
End Sub
Sub Icon1_MenuClick (Text As String)
Select Text
Case "Exit"
ExitApplication
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