|
|
||
Richard Bair's BlogCommunity: JavaDesktop ArchivesNimbus BugsPosted by rbair on October 02, 2007 at 08:18 AM | Permalink | Comments (1)So you want to file a bug against Nimbus? First, thank you very much! Jasper and I want Nimbus to be rock solid, and welcome all the bug reports we can get. Bugs are filed in the same way as all other bugs in Swing: via bugs.sun.com. You can use this link to view current bugs. As you will see, all Nimbus bugs are prefixed either with Nimbus LAF or Nimbus L&F. Please continue this naming convention, as it helps us locate which bugs belong to Nimbus. That's really all there is to it! App Framework JavaPolis Talk OnlinePosted by rbair on May 22, 2007 at 10:53 AM | Permalink | Comments (0)Short blog, but be sure to check out Hans Muller's talk from this past JavaPolis on the Swing Application Framework JSR (JSR 296). It is hosted over at Parleys.com. Properties in Java? Hoorah!Posted by rbair on January 08, 2007 at 02:09 PM | Permalink | Comments (45)Properties in Java? Awesome! As with any new language feature, there has been a lot of debate over whether this is an improvement to the language, or a detriment. And of course, every language-designer-wannabe (myself included!) is pounding the pulpit, declaring the One True Way to Property bliss. Well, sit back and enjoy as I pound the pulpit. Because seriously, I really do have the right solution! I promise! A Brief Overview of JavaBeansThe JavaBeans spec has been with us for quite a while. Virtually everybody knows about the JavaBeans POJO pattern:
Before throwing any monkey wrenches into the works, I'm going to explain a bit about some of the darker corners of the JavaBeans spec. At least, darker to the majority of developers out there. Many of you are probably familiar with the Reflection APIs. For example, given the class above, I could call the "getSurname()" method using Reflection like so:
Built above these core APIs is the JavaBeans Introspector, BeanInfo, PropertyDescriptor, and associated classes. These classes inspect an Object for methods that follow the JavaBean pattern, and create various descriptors automatically representing these "properties". You can even write your own PropertyDescriptors, or specify your own BeanInfos, if you don't want them to be automatically generated. Here's an example which get's all the properties for a bean and prints the name of the property and its value to System.out:
The java.beans package is widely used by frameworks and GUI builders. Swing is a huge user of the Bean APIs and patterns. JSR 295 (beans binding) is based on these APIs as well. XMLHttpRequest and SwingPosted by rbair on August 31, 2006 at 05:01 PM | Permalink | Comments (11)For a while now (since well before we started the SwingX-WS project) I've been interested in making Swing accessible to the hordes of web authors out there. This demographic is being actively persued by Adobe(Flex) and Microsoft. Web folks are doing more and more to enhance their web applications via AJAX in order to get closer to a rich client experience. At some point it makes sense to use a rich client toolkit -- and each of us (Flex/Flash, Avalon/XAML/WPF, and Swing) want to be the toolkit used. This space (called Rich Internet Application or Smart Clients) is, I believe, a real growth area. Our job, on the Swing team, is to ensure that when a development team hits that inflection point and wants to write a rich client app, they can do so in Java with Swing with the minimum amount of fuss. It is in this vein that XMLHttpRequest -- the Java implementation -- came to be. In SwingLabs and on the Swing team we've long been aware of the difficulties people face when trying to write responsive GUI apps due to the inherent difficulties in writing threaded apps. In the past I've blogged about SwingWorker and BackgroundWorker -- two different approaches to this problem. Both of these are reasonable ways to simplify threading issues. The XMLHttpRequest code I'm introducing today also deals with threading issues -- but isn't as general purpose as SwingWorker or BackgroundWorker. In this installment (I'm getting to the point, I promise!) I introduce the XMLHttpRequest and JSONHttpRequest beans, both part of the SwingX-WS project. I based the design and implementation on the W3C Working Draft Specification for XMLHttpRequest. So the good news is, for those of you familiar with XHR, you have essentially the same API available now for your Swing apps. NOTE: The classes mentioned in this blog have been refactored into the org.jdesktop.http.async package of SwingX-WS. Also, the class HttpRequest has been renamed AsyncHttpRequest. Before I get into the mechanics of making the call (if you care, just scroll down to the examples below), I want to take a few bytes of bandwidth and describe the kind of applications that would care about XMLHttpRequest. If you have an application that makes calls to REST web services (either structured or ad hoc), you'd probably care. If you are writing a fairly lightweight application -- heavy on graphics and light on data objects -- that uses, say, online photos, you'd care. If you were an AJAX saavy developer who wanted to try your hand at a little Swing -- you'd care. At the heart of the API is a class called HttpRequest. This little fella is really where all the fun is. It implements almost all of the API (all, in fact, except for getResponseXML) defined in the aforementioned W3C specification. The general concepts are pretty simple to grasp. Here's a basic code sample:
Those familiar with XMLHttpRequest will find this code to be really straitforward. In fact, the course grained API calls are all exactly the same:
This basic mechanism could be used rather cleanly for all kinds of scenarios. In this example I use it as a mechanism for deserializing some Customer java bean. I could also have passed the In addition to getting data,
This example reverses the last -- it constructs XML representing this customer bean and, using HTTP POST, sends this data to the web server. For convenience, I extended JSON is another alternative. Not as expressive or structured as XML but much faster to parse and easy to work with loosey-goosey. I hope you found this interesting. Hopefully in a future installment I'll get to showing a real live Swing demo doing something useful, besides printing junk out to System.out. Romain? Come on buddy, give a brother a hand! A (Barely) Better Looking Yahoo! News DemoPosted by rbair on July 10, 2006 at 06:27 PM | Permalink | Comments (7)I was greeted this afternoon by a retching Hans Muller who begged me to upload a better looking demo for the Yahoo! News web service I posted about last time. He likened last week's entry to a fat man in a speedo. Yikes. Here's a barely better demo (pun intended). (Note: This one also uses Mustang. Get it here!). As before, you can download YahooNewsDemo.java, as well as the source files and libs. For the impatient:
Simple Yahoo! News ReaderPosted by rbair on June 30, 2006 at 03:52 PM | Permalink | Comments (0)My last few blogs have been on using web services in Swing. This time I've created a simple Yahoo! News RSS reader JavaBean you can use in your own apps. And yes, this time I went all the way and wrote a JNLP. But beware, it is only running on 1.6 for now. I didn't even know I was developing on 1.6 until I tested the deploy, and now I'm headed out on vacation. Here's a screenshot, for those you can't or won't run the demo: It is a very ugly demo. Again, vacation and all that. But, here's basically what it does. You enter the name of the feed you'd like to see in the combo box on the top. Or you can pick one of the predefined ones, its up to you. Then click the "Refresh" button. On a background thread (there ya go, vtech!) I get the feed results, parse them, and then back on the UI thread I load them into the JTextArea. The results are raw output from the ROME RSS reader which I use to do all the heavy lifting. The point here isn't to show off some slick looking application -- its the work that went into creating it. Or the lack thereof. Read the source code yourself. You can also download the sources and rebuild the project (but good luck getting it to load up in NetBeans. Sorry no time to make it pretty, vacation calls). For the impatient, here's the source code boiled down. First, I created a YahooNews bean (well, after creating the UI). I then created a BackgroundWorker bean called "worker". I then filled in the BackgroundWorker's event handlers, and wrote an action listener for the "Refresh" button. Here's all the magic:
Aerith is free!Posted by rbair on June 28, 2006 at 02:00 PM | Permalink | Comments (9)The Aerith source code has just been released to the aerith.dev.java.net project. With this milestone I thought I'd just blog a bit about the backstory that went into Aerith. Hopefully, by the time you're done reading this, you won't stone us for some pretty hacked up code. Aerith was a really fun project to work on. We sort of had an idea for what we wanted to do for JavaOne. We had a lot of fun doing the Joplin music player the year before and really wanted to get back up on stage this year with something even cooler. Romain had a lot of demos lying around. The client group had this sweet intro screen idea and Romain had already mocked up a UI that would form the basis of the Aerith look. Every year James Gosling holds a kind of "tryouts" for keynote demos. We didn't know when those tryouts would be held, so we sent a few emails to find out. What we found was that we had about a week to get the demo finished before the tryouts. I was at home at the time and had to say goodbye to the wife and kid for the next few days. Romain, Josh and I setup a war room in one of the conference rooms here on campus. As all good war rooms, ours was stocked with food, liquid nourishment (water for me, on a diet :-)), and pizza (so much for the diet). Oh, and chocolate cake. No "Romain" war room is complete without chocolate cake. In three days of intense coding (Thursday, Friday, and Saturday. Usually about 18 hours+ each day) we wrote the entire map viewer and editor, and part of the applet. The original applet contained only the 3d "twinkle" code. (For those familiar with Romain's blog, Twinkle is one of the projects he released that we reused for this demo). With that, the demo was more or less feature complete. Later that week I added what we called the "Indiana Jones" viewer in the applet. Otherwise, bugfixes occupied our time. And endless tweaks to get things up to Romains standards. It was also a lot of fun to tryout for James' keynote and finally make it into Jeff Jackson's keynote on Tuesday morning. I always have a blast at JavaOne, and love getting up on stage. Even if I am boring to watch :-). The moral of this story (if there is one, besides diet's and war rooms not getting along so well) is that a sizeable portion of the Aerith code is very, very raw. It wasn't written as a "best practices" application, or to be maintained. It has a lot of bugs, is difficult to setup, needs a better build script, and nobody knows how the 3d stuff works besides Romain. It was written to show off what is possible with Swing/Java. It was written to demo well. And it was written because it was fun to do. I think in all three respects it was a home run. Especially the last one: it was a lot of fun. I think there is a great deal of potential in Aerith as a consumer application. We're looking for individuals who want to move Aerith to the next level. I'd be stoked to see it deployed and working with real people's data in real world situations. That'd really make my day. So, this makes 3 blogs in 3 days. If I keep this up, I'll have my yearly quota down by the end of the week! Swing, JAX-WS, and JavaBeansPosted by rbair on June 26, 2006 at 01:29 PM | Permalink | Comments (6)On the SwingLabs Forums we have been discussing Web Services and Swing. In particular, I want to start/retrofit a project on java.net where we can build both visual (like the Aerith map viewer) and non visual components. Some examples of non visual JavaBean components could include a Flickr bean, YahooSearch bean, YahooWeather bean, and so on. During the discussion, Adam expressed some concern about focusing on potentially gimicky web services like Flickr at the expense of more mainstream services such as those that would be developed in house at your local enterprise. I decided to take a shot at that situation and see what the development landscape looked like from the enterprise angle, especially when using the latest JEE 5 features. What I found was surprisingly easy, and very... uh... addicting. There's no webstart demo, because I don't have a webserver ready to handle the server side tasks. I guess you'll just have to trust me that it works. Or better yet, try it yourself :-) SetupJAX-WS can be daunting. The most difficult aspect of it is the setup and configuation of the build environment. This will become a bit more clear as we go along. I've chosen to sidestep the whole issue and just try NetBeans 5.5 with the Enterprise development pack This really made the setup process a lot easier for a lowly desktop guy like myself. I went to the NetBeans 5.5 download area and downloaded both the NetBeans IDE 5.5 Beta Installer and the NetBeans Enterprise Pack 5.5 EA Installer. I then downloaded and installed NetBeans 5.5, followed by the Enterprise Pack. I chose to install the SJAS 9 application server as part of the Enterprise Pack install. This was to make sure I had a Java EE 5 compatible server handy to test the new featuers. Note, I'm running on an Intel Mac with Mustang, and was surprised that everything *almost* worked. The only thing I had to do special was configure my netbeans.conf file to point to the JDK. This may have been because I've been messing with my JDK settings on MacOSX to get Mustang running. Finally, after installing everything and starting NetBeans, I had to enter the Server Manager and configure SJAS 9 as a web server. This is important, because later when we create our web application a Java EE 5 compatible server needs to be available. Now that I had everything installed and configured, I created two projects: Swing-WS-Website and Swing-WS. Swing-WS-Website is a normal NetBeans Web Application project type. The only special requirement was to make sure SJAS 9 was selected as the target server, and that JEE 5 is selected as the target. The Swing-WS project was just a normal Java Application project type. Nothing special. Creating the Web ServiceI chose a really simple and pointless web service as an example -- a random number generator. In NetBeans, I created a new Web Service. I altered the code to look like this:
There really isn't much to this code. I simply marked the RandomNumbers class with the @WebService annotation, and then marked the generateRandomNumbers method with the @WebMethod annotation. By creating this class with the NetBeans wizard, it made sure that the appropriate build configuration was done so that at this point, all I have to do is deploy. In SJAS 9 I can test my web service by going to the admin site. By default this is installed at http://localhost:4848. I won't go into any more detail on this product. I've found it very easy to use, and you can find info on the net for it. Writing the ClientNow that I knew my service was deployed and working, I was ready to write the client. First, I had to make the client project aware of the web service. When doing this by hand, this is where the nasty part is. All SOAP web services (which is what NetBeans created and deployed for me) have a WSDL file. This file describes the service in a language neutral manner. The same WSDL can be used by .NET clients or Java clients, for instance. In Java EE 5, the wsimport command line program reads WSDL files and generates java source files. You can then call these Java classes from within your client. I've tried doing all this by hand in the past and found it to be a huge pain. Tool support makes this experience much, much better. In NetBeans, I opened the New File wizard and selected Web Service Client. I then pointed it at my RandomNumbers web service (note: in the IDE I didn't even have to deal with the WSDL directly, NB hid all this mess from me). NetBeans automatically called wsimport and created the source files for the web service for me. The only problem I had was that I never saw these source files. Even though I'd specified a source package. As it turns out, NB 5.5 puts the source files in the "build" directory (which normally just contains class files). I guess they're trying to be clever and hide the sources from your source tree (no point cluttering it up). I'd have preferred that they generated a jar file and put it on my classpath, or at least told me what was going on. It took a while to figure out what was happening. Now that I know, it isn't so bad. Once the web service was imported into the project, I wrote a quick main method to test it out:
Before running the sample I opened the SJAS admin webapp in my browser to check the logs and see what happened when the webservice was called. I then ran the client. Bingo. Worked perfectly. So that's cool, but now how do I write a Swing application with this knowledge? Here's what I'd like it to look like (please Romain, don't laugh ;-)) <SIDETRACK> Sally is a server side super-engineer. She dreams in XML. Not just any XML, but we're talking namespace-declared, Schema-validated, fully robust XML. She's written a few web services to make available to the masses within her company. To help facilitate their work, she bundles the generated client stubs (generated by wsimport) along with a set of simple JavaBeans. Clint is a client side desktop kind of guy. He has more work to do than time to do it. All departments in the company want him to write their apps because he gets them done fast, and they work pretty well. Clint needs to access Sally's web services. No problem. He gets her web service bundle (including the client side stubs and JavaBeans) and adds them to his project. He takes the JavaBeans and adds them to his Visual editor's palette. He then creates a new form, adds the WS JavaBeans to the palette, configures them (and the rest of the UI) in his editor, compiles, tests, and deploys. All as fast as his little hands can type... er, click, since he uses the visual designer as much as possible to simplify his life. Funny enough, Wally the Web App guru also needs to write some clients. He also takes advantage of Sally's hard work and imports the JavaBeans into his JSF visual environment. Since I don't know enough about writing webapps, I'll stop the story here. Except to say that there is no fundemental difference between writing desktop and web applications when it comes to these simple JavaBeans. Ok, enough of the somewhat silly story, but perhaps you can see a bit of the vision. So, how do we write these JavaBeans? For this example, it is really quite simple. Basically, my RandomNumbersWS bean needs to allow the developer to specify the count -- the number of random numbers to return. In a real example it may take your Yahoo application id and search params. But that's another blog. Here's the code:
JavaBean is a convenience class in SwingX that I can extend. It makes writing these non visual beans a lot easier because it handles the infrastructure for a lot of the property change notification. You'll notice that this bean isn't doing much: it's simply a wrapper for the RandomNumbers client side proxy (called a "port" in JAX-WS). Now, let's see how to use it. I created my Swing GUI with Matisse -- took a minute, maybe two (Note for Scott: I didn't get any baseline support for JSpinner). I then wrote this code in the actionPerformed event handler for the generate button:
If bean binding was ready to go, this would have been even simpler. But as it is, this is just normal Swing code. I set the count on the ws bean, then asked it for the random numbers. I then put the resulting List into the JList component. Ok, so why bother with the bean? Seems like extra overhead here. Yes, this is a trivial example and it doesn't show off the point to a Bean very well. However, if I were using JSR 295: Bean Binding then having a Bean to bind to would have been really useful. Further, more complicated web services may benefit more from the beans approach. There is another subtle benefit to using the JavaBean in this case. It insulates the UI developer from the web service implementation. Both Clint and Wally won't have to change anything is Sally decides to switch to XML-RPC instead of SOAP and redistributes a new bean. From the UI perspective, they are dealing with the Web Service on the semantic level, rather than the level of the implementation. Once I learned how to use NB to execute web services from the client, it was a very easy process to get these calls into the UI. Those paying close attention will notice that the call blocks, though, so I have some more work to go before this is a genuinely rich rich client application. Gotta get rid of those blocking calls! Baby BoyPosted by rbair on February 09, 2006 at 10:15 AM | Permalink | Comments (13)I've never posted an "off-topic" blog posting before, but permit me a short indulgence: Luke Allen Bair, my first child, was born February 3rd at 6:31pm. Wife and child are doing well. Here's a couple quick pictures (as any proud papa would have to post, of course :-)).
JIC -- Java Icon File FormatPosted by rbair on October 03, 2005 at 04:21 PM | Permalink | Comments (7)Tired of "dealing with a dozen png representations of a single (logical) icon as separated files"? Tired of writing/debugging the code to treat multiple files as a single logical unit? Well, Daniel Leuck, SwingLabs, and Ikayzo bring you JIC : the simple multi-resolution cross-platform icon format for Java! Ok, ok, a little dramatic I know. But hey, it's cool technology and cool technology is what SwingLabs is all about. Daniel Leuck from Ikayzo recently contributed some code to the SwingLabs/JDNC Incubator Project for Java(tm) Icons. Read through the source (it's a quick read), as well as this SwingLabs forums posting. Essentially, JIC is a zip file that contains a series of png or jpg images. All images are named in a standard manner. From the JavaDoc for JIconFile: Bam, that's it. As you can imagine, a lot of cool things can be done with this basic structure. Since JIconFile represents the logical icon rather than the physical icon, we can imagine cool utilities for getting grayscaled images (for disabled icons, of course), accessible (large) images, images with badges, etc. Oh, and by the way, I can't help but plug the awesome icons over at IconExperience. I'm sure these icons (with all their wonderful variations) motivated JIconFile in the first place. Cool stuff, keep it comin' Richard DeploymentPosted by rbair on October 03, 2005 at 11:13 AM | Permalink | Comments (8)A new sub project has been added to SwingLabs today, http://deployment.dev.java.net. A few weeks ago Erik Vickroy approached me about starting a project related to deployment issues for rich client Swing applications. After a little brainstorming, it became clear that such a project would be a great addition to the SwingLabs suite of projects. Indeed, easing the deployment of rich client apps is an extremely important aspect of improving Swing developers' productivity. We're looking forward to continued collaboration between the Deployment and Swing teams here at Sun and the Java developer community! SwingLabs and SwingPosted by rbair on August 12, 2005 at 01:25 PM | Permalink | Comments (4)In my last blog's comments Andy Roberts asked the following question: I always keep my eye on SwingLabs because it is adding great value to the existing Swing toolkit. One thing that confuses me is just *how* it interacts with Swing, within the development process, that is. SwingX is an incubator for neat features, for example, sortable tables. Yet the approach adopted by Swing devs in Mustang is different than that in SwingLabs. And license issues seem to be contradictory, with SwingLabs being LGPL, it can't ever be absorbed into the main Java code. I've personally communicated to Richard discussing this, but it would be worthwhile clarifying fully the interaction between Swing and SwingLabs for all. The Short AnswerSwingLabs is simply an incubator for ideas that can be incorporated into Swing. Swing engineers work on both Swing and on SwingLabs (incidently, SwingX contributors include Scott Violet who is the Swing architect, and Josh Outwater who is a Swing engineer for Apple, as well as several other Swing engineers). The Long AnswerThere is a real need in the desktop java community for components and frameworks to aid in writing rich client Swing applications. This need is deeper than simply updating the Swing toolkit. Things such as a data binding framework, application framework, tool support, progress management, and so on are really not part of the Swing toolkit per se. Rather, they are built beside or on top of Swing to help make the Swing application programming experience better. There are also many things which are directly related to Swing, such as our JXTreeTable component. Another example is the filtering, sorting, and highlighting support for trees, tables and lists. The JXDatePicker is another good example. Work on these components is directly related to the Swing toolkit. This is a minor distinction that substantially alters the way that SwingLabs interacts with the JDK. Frameworks built around the Swing toolkit that are included in the JDK will go through a formal JSR process, while additions to the Swing toolkit itself will be done via one of the release JSRs (such as the JSR for Dolphin). This is more a matter of procedure, but is a good thing to keep in mind. As I mentioned in the "Short Answer", SwingLabs was initially created as an incubator for Swing. It was a place that Swing engineers could test out proposed enhancements with the community. It's LGPL license ensured that any changes to the code would have to be publicly available, while also allowing developers to bundle the code with their proprietary applications. But it didn't take long to notice that developers wanted to build Swing apps now and couldn't wait 18 months or longer for these changes to be made available in the JDK. I was one of those developers. Helping rich client Swing applications take root is a very important goal for the SwingLabs project. If the project is LGPL, then how can it be incorporated in the JDK? This is a legal question more than a techinical question, but I'll do my best to answer it with the general caveat that I am not a lawyer. However, as I understand it, when you write a piece of code there are two different kinds of rights that you get. The first is copyright. Copyright means that you own what you wrote the instant that you wrote it, and you have the right to do with it as you please. One of those rights is to assign a license to your work. The License dictates what rights others have with your work. However, as the copyright owner you have the right to be able to change the license at any time. So, if a Sun engineer writes some code for the SwingLabs project, then Sun (who is paying the Engineer) owns the copyright for the code. It is licensed under the LGPL, but whenever Sun decides to change license we are free to do so, since we own the copyright on the code. What was originally released as LGPL is still LGPL, meaning that it is impossible for Sun to revoke your rights to the code that was released under the LGPL, but they can dual license the code. What does this mean for the JDK? Well, it means that in order to migrate code from SwingLabs into the JDK we need to fork the code, change license, and put the new code into the JDK. Because Sun owns the copyright, Sun can do that However, what happens if code is contributed from folks outside of Sun? In that case, there are a couple of concerns. First, as demonstrated above, in order for SwingLabs to fulfill it's mission as an incubator for Swing Sun must own the copyright, or the code could never be included in the JDK. However, since nobody would want to hand over copyright to their own work, we use a Joint Copyright Agreement for the SwingLabs project. The JCA grants joint copyright between you the contributor and Sun. You still maintain every right you once had, but you also grant Sun copyright ownership. In this way, Sun is able to migrate code from the SwingLabs projects into the JDK. If SwingLabs is an incubator, then why does the implementation differ between Mustang and SwingLabs? In an ideal world, it wouldn't. Ideally new features would be implemented in SwingLabs first, and then simply included in the JDK rather than being rewritten. Unfortunately, due to time constraints this was not fully realized for Mustang. Can SwingLabs be used with my proprietary application? Yes! Well, that's it for today. If you have any more questions, I'd be happy to answer them as best I can! | ||
|
|