|
|
||
Amy Fowler's BlogCommunity: JavaDesktop Archivesresponding to questions on Swing, RIA, and JavaFXPosted by aim on May 19, 2008 at 09:32 AM | Permalink | Comments (8)To me, one of the most enjoyable parts of JavaOne is hanging out in the audience in Hall E-135 (traditional home of the Desktop track) and chatting face-to-face with developers between presentations. Kirill Grouchnikov (of Substance look-and-feel fame) always asks us insightful and often difficult questions. This year he asked if he could interview me post-JavaOne to address many of the concerns which the conference raised for desktop developers. Read the interview if you're curious, and please post any follow-up questions. Embedding Swing components in a JEditorPanePosted by aim on July 19, 2007 at 07:15 AM | Permalink | Comments (16)In the early days of Swing we spent many lunches arguing over the best way to do GUI layout. Tim Prinzing, the original architect of Swing's text package, believed that one sensical approach would be to leverage the power and popularity of HTML for GUI screen layout, and so from the very beginning he made sure it was possible to use the <object> tag to embed GUI components within HTML inside a JEditorPane. The page below embeds a JButton in the center of an HTML table: I've used a JButton here for simplicity, but this would also work with any java.awt.Component subclass. And here is the Swing code that loads page into a JEditorPane:
Now I'm not suggesting that we should abandon the use of tools and good layout managers in favor of HTML, but there may be an occasion where you'd find some utility in being able to embed components within HTML. In my case this is in writing some new demos for SwingSet3; I want to provide an HTML description (containing links, etc) of the demo and rather than placing that html adjacent to the running demo, it's a little more fun to just embed the demo within the descriptive html. Displaying the components in the page is the easy part. The tricky bit is in how to access the handle to the component instance in order to make the GUI do something useful in your application. You'd think you could simply dig around in the editorpane's view hierarchy until you find a component of the proper class, however setPage() is asynchronous and it turns out it's hard to know precisely when you can count on finding the instantiated component of interest. What you really want to do, if you're brave enough to tease open javax.swing.text, is to take control of the view factory to insert your own code at precisely the point when your component is instantiated. And just to rile up all those who think inheritence is the root of all evil, I'm going to neatly pack up all the code to do this in one simple JEditorPane subclass:
Note that we're using the "label" attribute in the <object> tag to set the label property on the button. By default, the text package's ObjectView factory (that we extended above) will use the JavaBean introspector to match up any html tag attributes with writable bean properties of type String. However, if a property name happens to also be defined as an attribute type in javax.swing.text.html.HTML.Attribute, then this mechanism will fail due to a bug in ObjectView. Unfortunately this happens to be the case for both the "text" and "name" properties (two I'd like to set for a JButton, drats). So if you are putting more than one component in the page and want to use an attribute value to identify them, you cannot rely on "name" being set for you. You'll have to specifically check for some other non-conflicting attribute. Now for the caveats. We've been appropriately skewered by developers for our less than stellar HTML support. We are steadily improving it, however JEditorPane may struggle with more complex layouts. Also, I don't even gloss over how CSS might play in all this, however if you can imagine skinning Swing components with CSS, I recommend checking out Josh Marinacci's 2003 article on Swing and CSS.
I do think Tim's idea of leveraging HTML for GUI layout still has merit, however the irony is that using HTML doesn't really make it any easier to get good ones. I've spent untold hours struggling in Dreamweaver to get my nested tables behaving just right; frankly I'd rather use GridBag and a good beer. But arguing over the holy grail keeps us all engaged.
the smartest person in the roomPosted by aim on May 12, 2007 at 02:15 PM | Permalink | Comments (8)A little more than 50 years ago, a team of brilliant engineers and mathematicians set out in the confines of an old battery factory in Philadelphia to build the world's first supercomputer, the UNIVAC LARC. My mother (Mary Cush, at the time) was on that team. So this year, as I sat in my seat at JavaOne, glancing at the sea of predominantly male geeks around me, I thought about how I came to be a software engineer and I realized that I pretty much owe that to her. After my mother graduated college with a Math degree in 1955, she considered her options; become a teacher or get married. With no desirable marriage prospects at that time (we'll get to that later), she did what any smart, resourceful individual would do. She sent out a bunch of letters to corporations and was ultimately hired by Remington-Rand (formerly Eckert-Mauchly) to be a Logical Designer. There she worked on a small team writing machine code to drive the LARC computer, which is pretty incredible if you realize that topping the list of important single career women characters of the 50's is Kitty of Gunsmoke. A few years later a team of Livermore Lawrence Laboratory engineers came out to Remington-Rand (then renamed Sperry Corp) to learn about maintaining the LARC and my Mom met James Moore (my Dad), they got married, moved to California, and started a family. She then did what every respectable woman of 1960 did; she left her career behind to dedicate her life to raising her four daughters. So I grew up with stories of rooms filled with transistors with gold-plated connections, counting by 1's and 0's, and a general love for math and logic. But most importantly I grew up in a household where the smartest person in the room was always my mother (my Dad is brilliant too, but that's a different story) and it never, ever occurred to me that there was anything boys could do that girls couldn't, except perhaps tackle football, which really only highlights an exceptional series of synapses in the woman's brain. Thanks to her, I emerged from the carnage of teenage-girlhood with an unshakable pride in being smart. Thanks to her, I've steered my way through a software career dominated by men without losing my sense of being a girl. Thanks to her, I've kept my pinky hooked into a job I love while raising my own children (yes, Sun has helped there too). So Mom, this year for Mother's Day I'm skipping cards and flowers and giving you this blog instead. You've made such a difference in my life. You're still the smartest person in the room. For fun I'm including an excerpt from the Univac LARC Programming Manual, which shows just how far (and not far) we've come in 50 years: "The Larc computer is an extremely high-speed computing device. Its high speed is obtained in part by using overlapping instructions, that is, the computer does not wait until and instruction has been executed before extracting the next from storage. Consequently, instructions follow each other rather closely through the stages of the control unit. In fact, as many as four instructions may be in the control unit at any one time. This overlapping of instructions of course increases the complexity of the computer and imposes certain sequencing restrictions on the programmer. In some cases by careless use of instructions a programmer may increase the running time of his program. In rare instances errors can be caused by failing to observe the restrictions. " The JDNC project debutsPosted by aim on June 23, 2004 at 12:37 PM | Permalink | Comments (4)At JavaOne '97, we kicked off project Swing and as we raised the toolkit scaffolding in the crazy months that followed, we released frequent snapshots of the bits to get our developer base (or at least a hardy core) in on the action. Feedback, both positive and 'constructive', was relentless, and the API improved steadily because of it. We still get email from folks who tell us they've been using Swing since those 0.2 days, and we always bow our heads in honor. So we're looking to get you in early on the action again. This time with a new technology called JDesktop Network Components (JDNC), which takes on the goal of simplifying development of data-centric Java desktop clients by providing shortcuts in the form of high level Swing components and an optional XML configuration language. Taking advantage of the open source boon, we're launching this as a javadesktop.org project, from which we can involve you not only in trying the stuff out, but in shaping and coding it directly. The JDNC project is a place where we can explore solutions and tune them long before they get baked into a standard. It is still in the rough early stage, so your impact could be significant. So read up about JDNC in my latest article, visit our project site, and join in on making it happen. After all, who knows better than you what would make your development life easier. And for those of you heading to San Francisco next week, we'll be at JavaOne talking more about the project. Come chat directly with us:
Itty Bitty ThingsPosted by aim on November 18, 2003 at 10:49 PM | Permalink | Comments (17)True confession: I love my Mozilla mail filter panel.(For non-mozilla users, this is the ever-present textfield that filters my message headers as I type, making it so very easy to find messages quickly). I'm also wildly fond of browser smart-fields that use auto-complete to recall my userid/password at the umpteen different websites where my memory always shorts. Auto-complete in general has changed my life. Itty bitty things make such a difference - nuggets of gold that seem so obvious in hindsight that we wonder how UIs ever existed without them. These are examples of usability features that help reduce what I call the "fuss-factor" in software, which is that intangible time spent around the edges of tasks, quietly accumulating, hard to measure, but adding up in the long run. System admin, virus warfare, and lengthy install wizards are a few examples of the fuss that remains in software. But also fitting this bill are the more subtle quirks that cause an unnecessary context switch or pause in the natural flow, like having to bring up a heavy search dialog to find something, or using HTML applications that refresh the page on every mouse click. (Please - give me real-time sort, search, and filter of my rottentomatoes movie lists!). You'd think software could make smarter use of the 2.3GHz sitting in our laps. Just imagine if corporations accounted for this fuss-factor in their "total cost of ownership" assessment of software. It just might change the purchasing habits of IT departments everywhere, now wouldn't it? Why is it that extreme degrees of usability are often relegated to the "consumer" market? No human being from my mother-in-law to James Gosling wants to waste time fussing at anything but the definitive task at hand, be it viewing grandchild photos or a little friendly mudslinging. Being technical or not has nothing to do with it. I recently googled "usability" and was delivered straight into the hands of Dr. Jakob Nielsen at useit.com. This turns out to be a rare source of information (some for free, some for fee) on how usability impacts return on investment. He focuses largely on the web, but his meta-message applies to user-experience in general and, unbeknownst to many, once upon a time he worked at Sun. So if common sense (wastedTime == lostMoney) isn't enough, the data is there for those willing to confront it. Our challenge in the Java platform group is to make it radically easier to build usable (less-fussy) client applications. And here is where I weave a tie-in to my current project... Java Desktop Network Components (JDNC) is all about simplifying the task of building and deploying rich Java desktop clients that deliver an exceptional end-user experience. We do this by providing high-level UI components with built-in networking smarts, great visuals, and usability features (like a filtering and other itty bitty things). On top of these Java components is an XML configuration layer for easy construction. We introduced JDNC at JavaOne 03 and have been working steadily since to produce a bag of useful bits worthy of evolution in the open source community. We hired ourselves a 3-year XML veteran to ensure we do the XML part justice (thankfully the schema has evolved since I wrote the original JDNC whitepaper). We've been quiet because we've been busy. I just remembered another usability diamond of mine: Alt-tab (for navigating active windows) - the single feature that transformed me into a laptop-only woman, having kissed the mouse goodbye. Would you run in flipflops?Posted by aim on July 11, 2003 at 10:33 PM | Permalink | Comments (1)Recently my 15-year-old cassette walkman that I use for running finally keeled, leaving me with no choice but to upgrade to an iPod. But this rant is really about iPod's companion, iTunes, and more specifically about Apple's dogged willingness to ensure that the user experience dictates the UI rather than the other way around. Now Apple could have built their music store as a classic web-based interface a la Amazon or cdnow, but they knew better. Prior to iTunes, my attempts to browse and buy music on the web were frought with the classically annoying "give me a new page on every click" molasses-like experience -- never quite edging to a net positive on my precious-time meter - so I rarely bothered. But iTunes is a real user interface dedicated to making the music hunt (and purchase) effortless. It's not even flashy - it uses basic controls (lists, tables, etc), no wizards (thank you!), and only an occasional spare confirmation popup. Browsing and searching provide instantaneous and *complete* results that can be sorted, filtered and scrolled without ever roundtripping to the server. Playlists can be edited and re-arranged using direct manipulation. It's so simple, it's glorious. The result is that I've spent more money on music in the last 4 days than I have in 4 years. I can only hope and predict that this is a preview of things to come. It may have taken Apple to start this sensible trend, but if Amazon and Ebay are as smart as I think they are, it won't stop at OSX. Java and Java Webstart make it possible to build iTunes-style web service clients that run everywhere, enabling the possibility of putting browsers back in the browse-document and form-submit business, where they belong. So it occurred to me, as I was running to the sounds of my freshly downloaded rendition of "I'll Take You There" by General Public, that if I was forced to wear flipflops (or Birkenstocks) while running, I wouldn't go very far. Bugs by moonlightPosted by aim on June 27, 2003 at 12:08 AM | Permalink | Comments (1)Powered by 802.11 and my viao with its duck-taped powercord to prevent hibernation loops, I'm basking in a balmy California midnight outside on my deck, coding away, fighting off an onslaught of bugs. Now you'd think that since I've worked on the JDK for many years that I'm referring to knats in the software. But I'm talking about real 6 legged creatures with wings and antennaes longer than their bodies. Entranced by the luminous glow of my LCD, they're landing on my screen and creeping around on my source code. What's freaky is that one little arthropod is hovering over a method which does some threading magic -- I mean he's really stuck there and won't leave! Suddenly I'm realizing that my critical section isn't properly encased in a synchronized block.... okay, right -- time to turn in for the night. What is it about late nights that warp the rational thought process? | ||
|
|