Skip to main content

Tag: Java8

WorldClock and Lambdas

The second Java 8 feature to use in WorldClock are the Lambdas.

The simplest way to start using them seems to apply Netbeans refactoring hints.

These hints are of two kinds for WorldClock:

  • Iterations:

PreJava8:

for (City city : cities) {
   city.paint(g, width, height, isFullScreen);
}

Java8:

cities.stream().forEach((city) -> {
    city.paint(g, width, height, isFullScreen);
});

It may not bring much in this instance though.

  • Single method anonymous inner classes:

PreJava8:

mnuiShow.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e)       {
        showWindow();
      }
});

WorldClock and JSR310

With JSR310 (Date and Time API) in Java 8 and the small 0.7 release of WorldClock done, I can update WorldClock to the new API.

First the time used for day and night drawing:

(in WorldClockBoard)

PreJava8:

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(“GMT”));
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR);
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);

Java8:

OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
int day = now.getDayOfMonth();
int month = now.getMonthValue(); int year = now.getYear();
int hours = now.getHour();
int minutes = now.getMinute();
int seconds = now.getSecond();

Jigsaw and Maven: Take 2, a Maven plugin

Last updated: 2012-11-01

This post will create a Maven plugin for Jigsaw. This plugin is based on HK2 Maven plugin.
The post includes all the code needed to build the plugin.
(the resulting source code, except for changes in Jigsaw’s source, is available at: https://svn.kenai.com/svn/lh-playground~svn/jigsaw )

Setting up the environment:

  1. Build Jigsaw

  2. Get Subversion

sudo apt-get install subversion

  1. Get Maven

sudo apt-get install maven2

  1. Set JAVA_HOME

export JAVA_HOME=’/usr/lib/jvm/java-7-openjdk-i386'

Custom Plexus Javac Component:

Jigsaw: Worldclock with the Maven plugin

Last updated: 2012-02-02

In the previous post I created a Maven plugin for Jigsaw, now I’ll adapt Worldclock to use it.

The transformed source code is also available at:

https://svn.java.net/svn/worldclock-application~svn/tags/application6-jigsaw-maven 

  1. Create the directory

mkdir -p ~/dev/worldclock

2. Get the source

cd ~/dev/worldclock
svn checkout https://svn.java.net/svn/worldclock-application~svn/tags/application6-jigsaw ~/dev/worldclock/application

  1. Cleanup

Remove the files that are not needed.

rm -rf ~/dev/worldclock/application/*.*
rm -rf ~/dev/worldclock/application/src/META-INF

  1. Code adjustment

The current combinaison of Jigsaw/JDK8/Ubuntu does not support the sytem tray properly, so adjust the Worldclock.java to bypass it