Jinx is a Java library that provides access to the Flickr API. It is pure Java, with no external dependencies.

The package structure is straightforward. Each Flickr API section (activity, auth, blogs, etc) has a corresponding class in the net.jeremybrooks.jinx.api package. The API classes are named ActivityApi, AuthApi, BlogsApi, etc. Each API class is implemented as a singleton. You can obtain an instance of an API class with a call to getInstance():

1

BlogsApi bApi = BlogsApi.getInstance();

Each Flickr method has a corresponding method in the API class. So if you want to call the Flickr flickr.blogs.getList method, you will call the getList() method on BlogsApi:

1

BlogsApi.getInstance().getList();

The API methods that return data will generally return instances of the Data Transfer Objects located in the net.jeremybrooks.jinx.dto package. The DTO’s are very simple classes, containing getter and setter methods and no other logic. All DTO’s implement java.io.Serializable.

Flickr returns a status message along with data for every API call. Jinx will check that status message for you. If Flickr reports an error, an instance of net.jeremybrooks.jinx.JinxException will be thrown. The Flickr error code and error message can be retrieved by calling getErrorCode and getErrorMessage.

This project is currently being used in SuprSetr. Currently, the following Flickr API sections are implemented:

Activity

Auth

Blogs

Collections

Commons

Photos

Photosets

Other sections of the Flickr API will be implemented over time. If you want to use Jinx now, you can get the source code from github and build it with ant. If you just want the binary jar file, you can download it at the Jinx home page. Javadocs are located here.

The test directory contains sample code showing how to use Jinx to access the Flickr API. Here is the TestAuthorization class, showing how to authorize an application to use Flickr:

// Send user to the login URL// In a real application, you would probably do this in a GUI// of some sortSystem.out.println("Please go to this URL and allow access: "+ frob.getLoginUrl());System.out.println("After you have authorized this application, press a key.");

// The token can be stored for future use, and is valid until// the user revokes access
token.store(newFile("/tmp/myToken"));}}catch(Exception e){System.out.println("Oops, something went wrong!");
e.printStackTrace();}}}

When developing a desktop application, there are times when you want to prevent the user from interacting with the GUI. For example, you may be doing work in the background, and want to make sure you finish before allowing the user to continue. Perhaps the most obvious way to do this is to disable each component in the GUI. This works, but is not a very elegant or maintainable solution. The appearance of each GUI component changes when disabled, and if you add a new component to the window in the future, you will have to remember to disable it as well.

Fortunantly, Swing provides a better way to do this: The glass pane. The glass pane is one of the layers of a JRootPane. It is transparent and normally not visible. However, if you set it as visible, you can effectively block all user interaction with the contents of the window.

Carrying this one step further, it is possible to set the glass pane to be a panel of your own design. By doing this, you can effectively overlay anything you want on top of the current window, including messages to the user, animated progress icons, etc. The screen shot below shows the BlockerPanel in action. The icon and text are on the glass pane, which intercepts all user interaction with the window.

BlockerPanel Demo

The code to implement a BlockerPanel is straightforward, and the resulting class is easy to use. You can download my BlockerPanel class along with a simple demonstration program and use it in any of your projects. The source code is released with no restrictions, so feel free to improve upon it. There are many useful features that could be added, and there are parts of the code that could be improved. I’ll leave this as an exercise for the reader.