Jun 26 2007

Favorite Programming Tumblelogs

According to wikipedia, a tumblelog is a variation of a blog, that favors short-form, mixed-media posts over the longer editorial posts frequently associated with blogging. I like to think of a tumblelog as a miniblog. Here are some of my favorite programming related tumblelogs.

  • Anarchaia – This might have been the first tumblelog, according to Kottke.
  • Dr Nic’s Journey – Dr Nic writes about “the small things in my day so I don’t clutter the Dr Nic site.” He writes mostly about Ruby, Rails, JavaScript, and popular culture.
  • technoweenie, wtf – Technoweenie writes about his tumblelog, “Probably a lame project.ioni.st wannabe.” Mostly popular culture form this well known Rubyist and Railer.
  • Application Error – “application-error.com is a tumblelog; an assorted buffé of rubbish presented by your host for the night Johan Sørensen.”
  • Projectionist – This tumblelog is contributed by Rubyists Marcel Molina, Sam Stephenson, Chad Fowler, and others.
  • ni.hili.st* – A classic tumblelog covering programming and popular culture.
  • A Rubyist Railstastic Adventure – This is my own Ruby/Rails tumblelog which supplements some of the Ruby related writing found on this site.
  • Java Musings – This is my Java related tumblog. It contains mostly quotes, most often than not from the Java Posse.
  • Happy Coder’s Daily Digest – This is my tumblelog RSS feed reader. It gets the feeds for programmers such as James Gosling, Graeme Rocher, Nick Sieger, Romain Guy, Peter Cooper, Charles Nutter, Tor Norbye, Joel on Software, Chad Fowler, and _Why.

Technorati Tags: , , , , , , ,


Jun 20 2007

Multiscreen Dialogs and the JFileChooser

I develop software on two monitors, one monitor dedicated for the IDE/debugger and one for running the application. But when you develop on two monitors you will soon notice that your dialogs will not always pop up on top on your application. I’ve already written a bit about dual monitor environments when talking about the GraphicsEnvironment class.

In this post, I’ll go over some code borrowed from a YourKit forum post on how to support multiscreen pop up dialogs in Java. A typical pops up dialog, like a file chooser, should be located on the center of the main application window, no matter on which monitor the main window is sitting on. To open and center a dialog on the currently selected frame you can use code like the following.

[source:java]
public static Point calculateCenter(Container popupFrame) {
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Window windowFrame = kfm.getFocusedWindow();
Point frameTopLeft = windowFrame.getLocation();
Dimension frameSize = windowFrame.getSize();
Dimension popSize = popupFrame.getSize();

int x = (int)(frameTopLeft.getX() + (frameSize.width/2) – (popSize.width/2));
int y = (int)(frameTopLeft.getY() + (frameSize.height/2) – (popSize.height/2));
Point center = new Point(x, y);
return center;
}
[/source]

If you are working with two monitors, you will also need to explicitly set the location on a JFileChooser object. If you don’t set the location on the file chooser and your main application in on the secondary monitory, the chooser will pop up on the primary. The problem with JFileChooser is that it does not respect the values you specify when you call the setLocation method.

Someone entered a bug on the JFileChooser because the x,y values on the setLocation method are ignored. The fix of this issue you need to subclass the JFileChooser.

[source:java]
JFileChooser chooser = new JFileChooser() {
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
// …
Point p = calculateCenter(dialog);
dialog.setLocation(p.x, p.y);
return dialog;
}
};
int returnVal = chooser.showOpenDialog(this);
[/source]

Technorati Tags: , , , ,


Jun 20 2007

Chain JavaScript Events

In JavaScript there can be only one JavaScript onload event handler. This is a somewhat an issue if you have all sort of third party libraries that want to run some piece of JavaScript code when the page finishes loading. You can use the YUI! Event library add and chain event listeners to a DOM element, but adding another resource dependency to you application might not always be the right answer. I recently had to chain some onload event handlers for a simple script I was writing and I didn’t want to require any additional files. Here is my poor man’s version of a JavaScript event chain gang.

// The loaders array will contain a
// list of event handlers
if(!window.loaders) {
  window.loaders = new Array(0);
}
// Save the current event handler
if(window.onload) {
  window.loaders.push(window.onload);
}
// Attach new onload event handler
window.onload = function() {
  // Execute previous cached event handlers.
  for(var i=0; i < window.loaders.length; i++) {
    var func = window.loaders[i];
    func();
  }

  // New event handler code goes here...
}

With code like this you can guarantee that the old even handler code will run before your new code.


Jun 13 2007

JavaOne 2007 Conference Notes

Here are all my notes taken at CommunityOne and JavaOne 2007. I was in San Francisco for 5 days and attended over 40 technical and birds of a feather sessions and managed to put together this 30 page document. For you download pleasure you can find a PDF version of all my conference notes.

CommunityOne 2007: Monday
Welcome to CommunityOne 2007
Getting Started and what’s New in GlassFish v2
Lunch with the Java Posse
Ajax Applications Made Easy with jMaki and Scripting
Swing GUI Building with Matisse: Chapter II
JRuby: Understanding the Fuss
Up the Stack
G2One

JavaOne 2007: Tuesday
Tuesday General Session
JRuby on Rails – Agility for the Enterprise
Evolutionary Java – General Session
Java Puzzlers
Using jMaki in a Visual Development Environment
Java Persistence API – Best Practices and Tips
Developing a Real-World Web Application with NetBeans 5.5 Visual Web Pack
Grails, Sails, and Trails – Rails Through a Coffee Filter
Rapid Seam Application Development with the NetBeans IDE

JavaOne 2007: Wednesday
Wednesday General Session
Swing Vector Graphics
Effective Java Reloaded – This Time It’s for Real
Building JavaServer Faces Applications with Spring and Hibernate
Extreme GUI Makeover 2007
Anatomy of an Eclipse RCP Application
Tricks and Tips with NIO
Dive into the GlassFish Aquarium
Seamless Web Browser Integration
Putting a Swing Front End on a Web Application

JavaOne 2007: Thursday
Thursday General Session
Being Productive with Swing
Technical Overview of GlassFish v2
JavaScript FX
Why Spaghetti is Not Tasty
Beans Binding
Write a 3D Game in Java
Web 3.0 – This is the Semantic Web
The Java 3D API and Java Binding for OpenGL
Glossitope – An Open-Source Java-based Widget Container

JavaOne 2007: Friday
Friday General Session
Bringing Life to Swing Desktop Applications
Ajax and JavaServer Faces Tooling in Eclipse
Bytecode Manipulation Techniques for Dynamic Applications for the JVM
Filthy-Rich Clients – Talk Dirty to Me
Writing Games with Project Darkstar

Technorati Tags: , , , , , , , , , ,


Jun 12 2007

Writing Games with Project Darkstar

For the last session of JavaOne 2007, I attended the Writing Games with Porject Darkstar technical session presented by Chris Melissinos, Sun’s Chief Gaming Officer, and Jeffrey Kesselman, Chief Darkstar Architect. Project Darkstart is Sun’s Gaming Server (SGS). Chris told the crowd of gamers that there is a huge demand for online game develop to lower costs. He also described how it is easier to make 15 games that generate $1M than to develop one game that will generate $15M. With that said, Chris elaborated that the purpose of Project Darkstar is to make practical, massively multi-player online (MMO) games. Current MMO games scale only by zoning users into different shards. The design goals for Darkstar are similar to those of GlassFish, Darkstar is to be a distributed, persistent, fault-tolerant server that is economical to develop for and administer.

There was also time for a quick discussion on how to develop a game on Darkstar. Someone spoke about their experience writing Bunny Hunter Online, a 2D multiplayer action game.

Technorati Tags: , , , , , ,


Jun 12 2007

Filthy-Rich Clients – Talk Dirty to Me

Romain Guy, of Google, and Chet Hasse, of Sun, presented on their forth coming book Filthy Rich Clients which is based on a previous JavaOne technical session of the same name. They described this session as “the presentation based on the book based on the presentation.”

The session began with a slide listing Data Binding as a goal for the talk. Romain then said, “Data Binding is the most critical development of Swing today, but is it not here yet.” The next slide crossed out Data Binding and listed Applications Framework which is subsequently scratched out for ‘Cooler Applications.’

The ingredients, or agenda, for developing cooler applications according to these filthy rich engineers is based on graphics, performance, animation, and effects. Romain suggested that you override the paintComponent method instead of the paint method for custom components. Overriding the paint method may clobber some painting code that should really happen, like appropriately calling paintBorder, paintChildren, etc. The session titled Bring Life to Swing Desktop Applications talked about overriding the paint method.

For the performance portion of the talk, Romain was mostly concerned with the performance of scaling images, such as creating thumbnails, applying effects, etc. For these types of image operations quality and performance matter. Romain explain how there are simply to many options to scale images in Java. The best performing methods to scale an image down is to use the drawImage method using the default interpolation (NEAREST), the second best method is to use drawImage with BILINEAR, followed with BICUBIC.

Another common sense piece of advice offered here was to request repaints only for the area where the UI has changed, this is generally known as clipping. To repaint just what you need you can use the repaint(x, y, w, h) method on the component.

In regards to animating your Swing application, Romain and Chet recommend you use the Timing Framework from the SwingLabs for scheduling and running animations. The Timing framework has an Animator class that can run a instance of a TimingTarget which has the animating code.

For effects they recommend the blur, drop shadow, spring (ghost effect), morphing, and animated transitions. The SwingLabs has a GaussianBlurFilter, ShadowRenderer, Morphing2D class to achieve blurs, drop shadows, and morphings.

The idea of using animated transitions such as fading in and out is to lead your users, not leave them. Romain and Chet are working on an Animated Transitions project related to the book.

Technorati Tags: , , , , , ,