Sunny San Francisco
August 22nd, 2007I finally had a nice clear sunny day in San Francisco and a chance to take a couple pictures.
I finally had a nice clear sunny day in San Francisco and a chance to take a couple pictures.
A couple weeks ago I needed to write some Java2D code to draw a water droplet. If you have ever tried coding bezier paths off the top of you head it is not the simplest of things and can be frustrating. So I ended up drawing it in Illustrator and saving as SVG. The next stage was hacking with some code I had from before to take the path and spit out Java2D code for the shape. I have been thinking since that I could cleanup the code when I get the time and make a little application for extracting path shapes from SVG and writing out the Java2D code for them. Well I finally got the time and here is what I came up with.

Download:
SvgShapeExtractor.jar (Executable Jar)
SvgShapeExtractorSrc.zip (Src)
Hopefully you will find this useful next time you need to write some Java2D shape code.
I have updated the SPAR project that I released with the code from my JavaOne talk on “Why Spaghetti is not Tasty - Architecting Large Scale Applications”. I have fixed issues stopping it working on Java 6 and improved the ant build process to make it simpler to build and run the Demo Application. There are now two ways to build and run the Spar Demo. If you have IntelliJ then you can just open the provided IntelliJ project and hit run, otherwise you can use Ant. Here are the instructions to get the demo and build and run it with Ant:
svn checkout https://spar.dev.java.net/svn/spar/trunk/code spar --username {username} where {username} is your dev.java.net login.spar/spardemoant -f build-scripts/build.xmlant -f build-scripts/build.xml runThe spar demo app at the moment is a very simple app that just brings up a UI with one of each of the main UI component types: SidePanels, Documents, Menus,Toolbars and Statusbars. As soon as I get time I will put some more work into making it a fully fledged simple application using the event bus and all the core functionality of the SPAR platform. It uses the JIDE docking framework at the moment though a abstraction layer, I have made a start on making a InfoNode plugin that will provide a alternative implementation.
I hope you have a more success now getting the demo application to run, any problems send me an email, Jasper
So it has been a while since I blogged about Nimbus, Java One has come and gone and I am sure you are all wondering whats happening to it. Well things have changed for Nimbus since it was announced at Desktop Matters conference in March. The initial plan was for Nimbus to be a open source project jointly run by Ben Galbraith and myself. In early prototype I hacked together thats available from nimbus.dev.java.net was very well accepted both inside Sun and in the swing community. As a result a decision was made to bring the Nimbus L&F into the JDK as part of the new Consumer JRE. What this means for is it will be available as part of the JDK 6 sometime early 2008. If you would like to read more about the Consumer JRE then read here.

I think this is amazing news for Nimbus L&F as it will hugely strengthen its adoptance. I am now working full time on getting Nimbus done with the tight deadlines to get it to you for early next year. The final version should be complete around August at which point I will try and get it released back to the open source project. Hopefully then we can get a good chunk of testing done on many different applications so we have a great version for the JDK. Ben has said that he will help with the effort to take it at that point and do a backport to run on JDK 5.
Here is my personal list of objectives for Nimbus L&F:
Command C on Mac and Ctrl C on Windows for copy. Also to try and have the File Chooser for have a layout and functionalty as the native L&F one but with Nimbus skin.These are what I would like to achieve with the Nimbus L&F, how much I can manage within the tight deadlines we will have to see. If features don’t get in then hopefully we can add them to the open source project and later back into the JDK. Animation is on the would really like to get it in pile but there as a lot to do before I get there.
I am very interested to hear any feedback you have on Nimbus, like feature X is crucial to my company using Nimbus or feature Y is not important to me. I will do my best to accommodate any good suggestions into Nimbus.
I came across a common problem the other day that I am sure many of you have. As it had been ages since I last solved it I turned to Google hoping it would come to my rescue. Well either I wasn’t guessing the right search terms or the answer is not out there. So I thought I would help the situation by writing a blog with the answer.
So the problem is you have some component in a scroll pane and when its preferred height is less than the scollpane area then you want it to stretch to fill the scollpane. But when it grows bigger than the scollpane area you would like it show the scrollbars. This is very useful when you want to be able to click in the spare space to clear selection or in the case of drag and drop where you want to be able to drop into the empty area. There was a bug fixed in JDK 6 that made this possible for JTable with setFillsViewportHeight(true). So here is how you do it for your own components: You need to make the component that is in the JScrollPane implement javax.swing.Scrollable and below is a skeleton implementation for you.
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return (orientation == SwingConstants.HORIZONTAL)? visibleRect.width : visibleRect.height;
}
public boolean getScrollableTracksViewportHeight() {
boolean tracks = false;
if (getParent() instanceof JViewport) {
tracks = getPreferredSize().getHeight() <
((JViewport) getParent()).getExtentSize().getHeight();
}
return tracks;
}
public boolean getScrollableTracksViewportWidth() {
return true;
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return getScrollableBlockIncrement(visibleRect, orientation, direction)/5;
}
The key part of this is the getScrollableTracksViewportHeight() method that adjusts its returned value based on the relationship between preferred height and visible height. You could use something similar for getScrollableTracksViewportWidth() if you want a similar effect in that direction. Now I just have to remember to look at my blog next time I need to do this