mapjfx now supports filled polygons

I just released mapjfx versions 1.21.0 and 2.2.0, they will be available in maven central:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.21.0</version>
  </dependency>
  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>2.2.0</version>
  </dependency>

Now it is possible to close CoordinateLines to polygons with a fill color:


Comments and contributions welcome.

mapjfx 2.1.1 and 1.20.1 using OpenLayers 5.3.0

I just released mapjfx versions 1.20.1 and 2.1.1, they will be available in maven central:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.20.1</version>
  </dependency>
  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>2.1.1</version>
  </dependency>

mapjfx now uses OpenLayers version 5.3.0.

Version 1.20.1 is built using OracleJDK8, whereas version 2.1.1 is built with OpenJDK11.

mapjfx 2.1.0 and 1.20.0 released, now built with JDK8 and JDK11

The new versions are 1.20.0 and 2.1.o, available in maven central:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.20.0</version>
  </dependency>
  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>2.1.0</version>
  </dependency>

Version 1.20.0 is built using OracleJDK8, whereas version 2.1.0 is built with OpenJDK11.

mapjfx version 1.17.0 reporting the map’s extent and using OpenLayers 4.6.5

I just released mapjfx version 1.17.0 it should be found shortly at maven central, the artifact coordinates are:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.17.0</version>
  </dependency>

The source is available at GitHub.

mapjfx now ow uses OpenLayers 4.6.5.

As a new feature, the MapView object now emits events whenever the extent of the map changes. This happens when the center of the map is changed, the zoom value is changed or when the map’s window size is changed. The event can be processed like this:

// add an event handler for extent changes and display them in the status label
mapView.addEventHandler(MapViewEvent.MAP_BOUNDING_EXTENT, event -> {
  event.consume();
  labelExtent.setText(event.getExtent().toString());
});

processing meta annotations with Java

Everybody who is using Spring these days knows that Spring has many annotations that are just used to group together a couple of other annotations and so to keep the number of annotations small. For example the @RestController annotation combines basically the @Controller and the @ResponseBody annotation so that the user only needs to annotate his class with one annotation instead of two annotations.

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
    String value() default "";
}

The JEE @Stereotype annotation works basically the same way.

In this post I show how to define and evaluate such meta annotations in plain Java without using Spring or JEE.

The annotations

I define the annotations for the example within one class I called WorkingDays. I define one annotation for each day of the week and two annotations that group working days and weekend days by referencing the other annotations:

public class WorkingDays {

    @Retention(RUNTIME)
    @interface OnMonday { }

    @Retention(RUNTIME)
    @interface OnTuesday { }

    @Retention(RUNTIME)
    @interface OnWednesday { }

    @Retention(RUNTIME)
    @interface OnThursday { }

    @Retention(RUNTIME)
    @interface OnFriday { }

    @Retention(RUNTIME)
    @interface OnSaturday { }

    @Retention(RUNTIME)
    @interface OnSunday { }

    @Retention(RUNTIME)
    @OnMonday @OnTuesday @OnWednesday @OnThursday @OnFriday
    @interface OnWorkday { }

    @Retention(RUNTIME)
    @OnSaturday @OnSunday
    @interface OnWeekend { }

    public static List&lt;Class&lt;? extends Annotation&gt;&gt; dayOfWeekAnnotations() {
        return Arrays.asList(WorkingDays.OnMonday.class, WorkingDays.OnTuesday.class, WorkingDays.OnWednesday.class,
                WorkingDays.OnThursday.class, WorkingDays.OnFriday.class, WorkingDays.OnSaturday.class,
                WorkingDays.OnSunday.class);
    }
}

In addition to that there is a method dayOfWeekAnnotations() which returns the annotations for the single days, but not the grouping ones.

The class using the annotations

I define a class Employee with three nested subclasses, one is using the @OnWorkday annotation, another one the @OnWeekend annotation and the third one both of them. Please notice, that the annotations for the separate days are not used here:

public class Employee {

    @OnWorkday
    public static class OnlyOnWorkdayEmployee extends Employee {
    }

    @OnWeekend
    public static class OnlyOnWeekendEmployee extends Employee {
    }

    @OnWorkday @OnWeekend
    public static class EveryDayEmployee extends Employee {
    }

    public String simpleClassName() {
        return getClass().getSimpleName();
    }
}

The class evaluating the annotations

To evaluate this, I create a class named Office in which I first create three different employees, each of a different type.

Then I iterate over all the annotations for the single days – remember, the employees use the meta annotations, not the ones for the days –  and print out which of the employees works on which day. For this I use a utility class MetaAnnotationUtil which I will show after the output.

public class Office {
    private static final Logger LOGGER = LoggerFactory.getLogger(Office.class);

    public static void main(String[] args) {
        List<Employee> employees = getEmployees();

        WorkingDays.dayOfWeekAnnotations()
                .forEach(dayAnnotation -> {
                    LOGGER.info("\n{}", dayAnnotation.getSimpleName());
                    employees.forEach(employee ->
                            LOGGER.info(" {} is working: {}", employee.simpleClassName(),
                                    employeeWorksOn(employee, dayAnnotation)));
                });
    }

    private static boolean employeeWorksOn(Employee employee, Class<? extends Annotation> dayAnnotation) {
        return MetaAnnotationUtil.hasMetaAnnotation(employee.getClass(), dayAnnotation);
    }

    @NotNull
    private static List<Employee> getEmployees() {
        List<Employee> employees = new ArrayList<>();
        employees.add(new Employee.EveryDayEmployee());
        employees.add(new Employee.OnlyOnWorkdayEmployee());
        employees.add(new Employee.OnlyOnWeekendEmployee());
        return employees;
    }
}

This is the output when running the program:

13:04:18.302 [main] INFO  com.sothawo.annotations.Office - 
OnMonday
13:04:18.342 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.342 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: true
13:04:18.343 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: false
13:04:18.343 [main] INFO  com.sothawo.annotations.Office - 
OnTuesday
13:04:18.343 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.343 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: true
13:04:18.343 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: false
13:04:18.343 [main] INFO  com.sothawo.annotations.Office - 
OnWednesday
13:04:18.344 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.344 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: true
13:04:18.344 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: false
13:04:18.344 [main] INFO  com.sothawo.annotations.Office - 
OnThursday
13:04:18.344 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.344 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: true
13:04:18.345 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: false
13:04:18.345 [main] INFO  com.sothawo.annotations.Office - 
OnFriday
13:04:18.346 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.346 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: true
13:04:18.346 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: false
13:04:18.347 [main] INFO  com.sothawo.annotations.Office - 
OnSaturday
13:04:18.347 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.347 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: false
13:04:18.347 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: true
13:04:18.348 [main] INFO  com.sothawo.annotations.Office - 
OnSunday
13:04:18.349 [main] INFO  com.sothawo.annotations.Office -  EveryDayEmployee is working: true
13:04:18.349 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWorkdayEmployee is working: false
13:04:18.349 [main] INFO  com.sothawo.annotations.Office -  OnlyOnWeekendEmployee is working: true

The class doing the magic

In the MetaAnnotationUtil class I setup a Set to collect the annotations and then add the found annotations if I have them not in the set already and recursively process the annotations of the current annotation:

public abstract class MetaAnnotationUtil {

    /**
     * checks wether an annotated element has an annotaion directly or as a meta annotation (annotation on annotation)
     *
     * @param annotatedElement
     *         the annotated element
     * @param annotationClass
     *         the annotation class to search
     * @return true if the annotaion class is found
     */
    public static boolean hasMetaAnnotation(@NotNull final AnnotatedElement annotatedElement,
                                            @NotNull Class<? extends Annotation> annotationClass) {
        final Set<Class<? extends Annotation>> foundAnnotations = new HashSet<>();
        findAllAnnotations(annotatedElement, foundAnnotations);
        return foundAnnotations.contains(annotationClass);
    }

    /**
     * do a meta (recursive) search on the annotated element and ignore annotations that have already been found
     *
     * @param annotatedElement
     *         the annotated element
     * @param foundAnnotations
     *         the already found annotations
     */
    private static void findAllAnnotations(@NotNull final AnnotatedElement annotatedElement,
                                           @NotNull final Set<Class<? extends Annotation>> foundAnnotations) {
        Arrays.stream(annotatedElement.getDeclaredAnnotations())
                .map(Annotation::annotationType)
                .filter(annotation -> !foundAnnotations.contains(annotation))
                .forEach(aClass -> {
                    foundAnnotations.add(aClass);
                    findAllAnnotations(aClass, foundAnnotations);
                });
    }
}

 

Conclusion

This post has shown that with a little recursive implementation, meta annotations can easily be processed. In a real life scenario I would add caching mechanisms to make sure that the annotations for classes and methods are not repeatedly searched. They can be cached as they are created on compile time and do not change when running.

And, when you are already using Spring and just need to add some custom meta annotations to your project: Use Spring Core’s AnnotationUtil class and do not write something of your own!

mapjfx 1.15.0 using OpenLayers 4.6.4

I just released mapjfx version 1.15.0 it should be found shortly at maven central, the artifact coordinates are:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.15.0</version>
  </dependency>

The source is available at GitHub.

Now uses OpenLayers 4.6.4.

Comments and contributions welcome.

mapjfx 1.14.0 released

I just released mapjfx version 1.14.0 it should be found shortly at maven central, the artifact coordinates are:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.14.0</version>
  </dependency>

The source is available at GitHub.

  • There are new events that are triggered on mouse entry and exit on markers and labels. Thanks to skinkie for that.
  • The CSS style property of a Label is now an observed property and changes will be reflected on the map immediately.
  • Now uses OpenLayers 4.4.0

Comments and contributions welcome.

mapjfx 1.13.2 using OpenLayers 4.3.2

I just released mapjfx version 1.13.2 it should be found shortly at maven central, the artifact coordinates are:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.13.2</version>
  </dependency>

The source is available at GitHub.

Now uses OpenLayers 4.3.2.

Comments and contributions welcome.

mapjfx 1.13.1 using OpenLayers 4.2.0

I just released mapjfx version 1.13.1 it should be found shortly at maven central, the artifact coordinates are:

  <dependency>
    <groupId>com.sothawo</groupId>
    <artifactId>mapjfx</artifactId>
    <version>1.13.1</version>
  </dependency>

The source is available at GitHub.

Now uses OpenLayers 4.2.0.

Comments and contributions welcome.