Open Source & Free ❤️

Flat Themes, DPI's & Static Initializers

Flat Themes, DPI's & Static Initializers

Header Image

With the release of 3.0 we were overwhelmed with a lot of last minute features and improvements. It seems
that we neglected to mention a lot of features that made it into the final 3.0 product.
One of the nicest new features is a set of new flat themes with various colors in the designer and the project
wizard. We found that a lot of developers prefer themes with more control over the look, themes that look
more similar across platform yet have a more modern “flat” feel.

A long time request has been to add the additional DPI resolutions we added for higher density devices into
the designer tool. We now support these additional densities in the designer tool both in the multi image import
and when editing a specific resolution.

On a different subject, we noticed a couple of developers had one of those hard to track down bugs that boiled
down to using the FileSystemStorage API from static context. E.g. this:

public static final String MY_HOME_DIR = FileSystemStorage.getInstance().getAppHomePath();

This seems like code that should work and annoyingly enough it works on the simulator. However, because of the
way classloaders work this code will probably fail on devices. Static context can be initialized at any time and since
the initialization of the implementation code might occur after the initialization of static context the static variable
might not work well…
You should pay attention to such code where you invoke implementation classes from static context and try to avoid
it, ideally we’d make this fail on the simulator but that is a bit tricky.

8 Comments

  • rhg1968 says:

    I see the new templates in NetBeans but not in IntelliJ 14.1.3

  • Shai Almog says:

    Can you file an issue on that?
    We’ll need to add them there too. As a workaround you can just create a new project with a native theme. Open the designer tool, delete the “Theme” entry and create a new theme, you should have these options there assuming you are using the latest plugin.

  • rhg1968 says:

    Thanks for the reply. I just put the issue on GitHub. I am using plugin 3.0.2 and I don’t have any updates so I believe I am using the latest. I also refreshed the libraries but I don’t see the theme in the GUI builder if I try to add a new theme to an existing project.

  • Shai Almog says:

    Its possible the IDEA plugin doesn’t update the designer to the latest version too. We’ll look into it as part of the bug.

  • J.C says:

    Shai, to clarify about static initializers for some people, it would be clearer to enclose the statement you illustrated inside static {}.

    For example, is this what you mean?

    Avoid:

    public static final String MY_HOME_DIR;
    static {
    MY_HOME_DIR = FileSystemStorage.getInstance().getAppHomePath();
    }

    If not, please clarify and include an example that says: Don’t {….} and Do{…} etc..if its not too much trouble :).

  • Shai Almog says:

    That would be a problem. Use a getter that invokes that method. Don’t store it in that static context.

  • J.C says:

    Hmm, so what you are saying is, in general, avoid storing values returned by methods that is initializing underlying platform implementations into static variables when a class is created?

  • Shai Almog says:

    No. Avoid access to Codename One API’s from static context since it might get initialized before the Codename One API gets initialized.

Leave a Reply