Introduction
While working with the Raspberry Pi (Rpi), thought it would be helpful to have Widgets showing information at hand on a position at the screen. A widget could be a Clock, EMail Listener, Chat, RSS Feed, LogViewer, Notifications, Weather Info, Info Screens etc.
Solution
B4J Non-UI app (=Standard Java) having an UI interface based on jFrame. No JavaFX required. It has a simple layout with few controls only.
The result is a rather small jar, running with good performance on the Raspberry Pi 2.
Note: The Widgets also run under Windows (8.1 tested with JDK8) - other OS not tested.
The Widget frame is composed out of a Frame Title, Heading Label and Message Editorpane. Note that this depends on the type of widget.
The labels accept HTML formatted text, like <HTML><H1>Hello World!</H1><HR></HTML>, but also CSS can be used.
The message editorpane has a scrollbar for multiline text and it accepts url's.
The frame has a utility style with a title and one close button.
When the widget is set to undecorated mode (on the RPi, right mouse click), to close the widget, double click on the message label.
Settings (key=value) are stored in a textfile widgetname.set in the dirapp folder.
Stored for all widgets are version, timer intervall (ms), position x,y and width, height, stayontop (1 for Yes or 0 for No). In addition, widget specific settings are set.
Use a texteditor to change the settings interval and stayontop. The other settings are stored when closing the widget. The last position will be set when starting the widget.
Important to set and use Keys in lowercase!
To start the Widget as a process, run as:
java -jar widgetname.jar &
On Raspberry Pi the PID will be given. This to use to stop the widget if required ($kill pid).
Develop Widgets
To develop other widgets, copy the folder templatewidget to a folder of choice, like logwidget.
Add the functionality of the new widget to widgetcode.bas.
To define specific settings for the new widget, use a settingsfile widgetname.set, like logwidget.set. Do not change widget.set.
Rename templatewidget.b4j to the new widgetname, like logwidget.b4j.
Start the B4J IDE and load the widgetname.b4j.
#One Clock Widget
Display actual time.
To change the layout, lookup widgetcode.bas. The settingsfile is oneclockwidget.set.
#Multi Clock Widget
Display actual time for multiple timezones.
The time zones are defined in the settings, like Clocks=2, Clock1=Europe/Madrid, Clock2=America/Chicago
To change the layout, lookup widgetcode.bas. The settingsfile is multiclockwidget.set.
#Time Zone Widget
Select a time zone from a combobox and display time pls GMT information.
To change the layout, lookup widgetcode.bas. The settingsfile is timezonewidget.set.
#Weather Widget
Obtain Weather information from Yahoo using the Where On Earth ID (Woeid).
To change the layout, lookup widgetcode.bas. The settingsfile is weatherwidget.set.
#WOEID Widget
Obtain Weather information from Yahoo using the Where On Earth ID (Woeid).
Select a woeid from a combobox.
To change the layout, lookup widgetcode.bas. The settingsfile is woeidwidget.set.
The woeids are defined in the settings, like WOEIDS=2, WOEID1=656958,Hamburg (Germany), WOEID2=753057,Arrecife (Spain)
TODO: Include a WOEID finder
#Log Widget
Read the first line of a logfile on a webserver (as an example, can be any file)
#Send EMail Widget
Send an email composed out of field To, Subject and Body. Only one receipient possible.
The settingsfile is sendemailwidget.set. In here, define the SMTP parameter, like
smptserver = smtp.gmail.com, user = yyyy@gmail.com, password = YYYY, smtpport = 465, interval = milliseconds
#EMail Monitor Widget
Monitor new emails. If new email(s) found on the server, the From and Subject will be shown in a list.
Clicking on a list entry, the From and Subject are showin in a Message Window.
A button indicates new emails (turning red). If clicked, means emails checked, the email list is cleared and the button turns green.
A label below the button shows if messages have been found from last server check for emails.
The settingsfile is emailmonitorwidget.set. In here, define the POP3 parameter, like
popserver = pop.gmail.com, user = yyyy@gmail.com, password = YYYY, popport = 995, deletefromserver=0|1 (to delete the emails after checking), interval = milliseconds
#Chat
Chat between a Server and a Client.
The settingsfile are for the chatserver chatserverwidget.set (define the chatname) and for the chatclient chatclientwidget.set (define the chatname and the server IP address).
After setting the right server IP address on the client, start the server first (java -jar chatserverwidget.jar) and then the client (java -jar chatclientwidget.jar).
On the client, connect to the server and ready to chat.
Tested between Raspberry Pi (as Server) and Windows (as Client), between Windows (as server) and Windows (as Client) and between Raspberry Pi's.
#LED On Off Widget (Raspberry Pi Experimental)
Turn an LED connected to PIN1 (Physical Pin is 18) on and off.
In addition can start a timer to switch LED on and off.
Source code attached. Start reading readme.txt.
While working with the Raspberry Pi (Rpi), thought it would be helpful to have Widgets showing information at hand on a position at the screen. A widget could be a Clock, EMail Listener, Chat, RSS Feed, LogViewer, Notifications, Weather Info, Info Screens etc.
Solution
B4J Non-UI app (=Standard Java) having an UI interface based on jFrame. No JavaFX required. It has a simple layout with few controls only.
The result is a rather small jar, running with good performance on the Raspberry Pi 2.
Note: The Widgets also run under Windows (8.1 tested with JDK8) - other OS not tested.
The Widget frame is composed out of a Frame Title, Heading Label and Message Editorpane. Note that this depends on the type of widget.
The labels accept HTML formatted text, like <HTML><H1>Hello World!</H1><HR></HTML>, but also CSS can be used.
The message editorpane has a scrollbar for multiline text and it accepts url's.
The frame has a utility style with a title and one close button.
When the widget is set to undecorated mode (on the RPi, right mouse click), to close the widget, double click on the message label.
Settings (key=value) are stored in a textfile widgetname.set in the dirapp folder.
Stored for all widgets are version, timer intervall (ms), position x,y and width, height, stayontop (1 for Yes or 0 for No). In addition, widget specific settings are set.
Use a texteditor to change the settings interval and stayontop. The other settings are stored when closing the widget. The last position will be set when starting the widget.
Important to set and use Keys in lowercase!
To start the Widget as a process, run as:
java -jar widgetname.jar &
On Raspberry Pi the PID will be given. This to use to stop the widget if required ($kill pid).
Develop Widgets
To develop other widgets, copy the folder templatewidget to a folder of choice, like logwidget.
Add the functionality of the new widget to widgetcode.bas.
To define specific settings for the new widget, use a settingsfile widgetname.set, like logwidget.set. Do not change widget.set.
Rename templatewidget.b4j to the new widgetname, like logwidget.b4j.
Start the B4J IDE and load the widgetname.b4j.
#One Clock Widget
Display actual time.
To change the layout, lookup widgetcode.bas. The settingsfile is oneclockwidget.set.
#Multi Clock Widget
Display actual time for multiple timezones.
The time zones are defined in the settings, like Clocks=2, Clock1=Europe/Madrid, Clock2=America/Chicago
To change the layout, lookup widgetcode.bas. The settingsfile is multiclockwidget.set.
#Time Zone Widget
Select a time zone from a combobox and display time pls GMT information.
To change the layout, lookup widgetcode.bas. The settingsfile is timezonewidget.set.
#Weather Widget
Obtain Weather information from Yahoo using the Where On Earth ID (Woeid).
To change the layout, lookup widgetcode.bas. The settingsfile is weatherwidget.set.
#WOEID Widget
Obtain Weather information from Yahoo using the Where On Earth ID (Woeid).
Select a woeid from a combobox.
To change the layout, lookup widgetcode.bas. The settingsfile is woeidwidget.set.
The woeids are defined in the settings, like WOEIDS=2, WOEID1=656958,Hamburg (Germany), WOEID2=753057,Arrecife (Spain)
TODO: Include a WOEID finder
#Log Widget
Read the first line of a logfile on a webserver (as an example, can be any file)
#Send EMail Widget
Send an email composed out of field To, Subject and Body. Only one receipient possible.
The settingsfile is sendemailwidget.set. In here, define the SMTP parameter, like
smptserver = smtp.gmail.com, user = yyyy@gmail.com, password = YYYY, smtpport = 465, interval = milliseconds
#EMail Monitor Widget
Monitor new emails. If new email(s) found on the server, the From and Subject will be shown in a list.
Clicking on a list entry, the From and Subject are showin in a Message Window.
A button indicates new emails (turning red). If clicked, means emails checked, the email list is cleared and the button turns green.
A label below the button shows if messages have been found from last server check for emails.
The settingsfile is emailmonitorwidget.set. In here, define the POP3 parameter, like
popserver = pop.gmail.com, user = yyyy@gmail.com, password = YYYY, popport = 995, deletefromserver=0|1 (to delete the emails after checking), interval = milliseconds
#Chat
Chat between a Server and a Client.
The settingsfile are for the chatserver chatserverwidget.set (define the chatname) and for the chatclient chatclientwidget.set (define the chatname and the server IP address).
After setting the right server IP address on the client, start the server first (java -jar chatserverwidget.jar) and then the client (java -jar chatclientwidget.jar).
On the client, connect to the server and ready to chat.
Tested between Raspberry Pi (as Server) and Windows (as Client), between Windows (as server) and Windows (as Client) and between Raspberry Pi's.
#LED On Off Widget (Raspberry Pi Experimental)
Turn an LED connected to PIN1 (Physical Pin is 18) on and off.
In addition can start a timer to switch LED on and off.
Source code attached. Start reading readme.txt.
Attachments
Last edited: