Wednesday, November 27, 2013

Enzo part II

And another one...
This time let me tell you something about another control in the lcd package...the LcdClock. To give you an idea what I'm talking about...here is a little screenshot



As you can see it looks similar to the Lcd control and indeed it is based on the Lcd control and supports all the Lcd styles that I showed in the last post.
Because this is just a simple clock there not so many features that you can adjust. The main things are

  • title
  • alarms
  • locale
  • dateFormat
  • dateSeparator

The title is just a simple text that will be shown on top of the LcdClock. When I created the LcdClock I remembered the time on the University where we had to spent some time in the CleanRoom and observe some processes. Most of the times we use a little AlarmClock with either a countdown timer or with a simple alarm to remind us on running processes etc.
So the idea was to have the ability to add one or more alarms to the LcdClock that will fire an event and can also execute something by themselves. So let me give you an example.

class Commando implements Alarm.Command {
    @Override public void execute() {
        System.out.println("This will be executed by the alarm");
    }
}

Alarm alarm = 
    new Alarm(Alarm.Repitition.ONCE,
              LocalDateTime.now().plusSeconds(30),
              Alarm.ARMED,
              "Some text",
              new Commando());

The Alarm class that I use here offers different features

  • time
  • repetition
  • armed
  • text
  • command

The time specifies the alarm time and the repitition defines if this alarm will be triggered only once or if it will be triggered in intervals. Possible values are

  • Alarm.Repetition.ONCE
  • Alarm.Repetition.HOURLY
  • Alarm.Repetition.DAILY
  • Alarm.Repetition.WEEKLY

You can arm or unarm an alarm by calling the setArmed(boolean) method on the alarm instance. 
Each alarm can have it's own text that you can use as an alarm message or for whatever you like. And at least we have the Command interface that simply has an execute() method which will be called when the alarm is due. 
The alarm indicator in the LcdClock will be visible as long as there are alarms in the internal list.
You can add and remove Alarms in the LcdClock and if an Alarm is due it will be removed from the list of Alarms if it has a repetition of Alarm.Repetition.ONCE.

Please keep in mind that this control (like all others in Enzo) was not made for production code and might contain bugs but if you like it you can fork it on bitbucket


https://bitbucket.org/hansolo/enzo/wiki/Home

That's it for today...so enjoy JavaFX and keep coding...

No comments:

Post a Comment