The Incrementalist

12/28/2004

Starting a system drag on a mouseExited event

Filed under: — Joe @ 8:41 pm

Exit Drag

Swing’s drag-and-drop implementation is pretty straightforward for the common cases—if you’re working with standard components, you might not have to do any work at all to get basic drag-and-drop support. However, once you get to the point of wanting to do interesting nonstandard things, it’s easy to get tangled up in the web of interrelated UI classes, many of which can’t just be constructed.

Case in point: in certain parts of my application, I’d like item dragging to be rendered by my component up until the point at which the cursor crosses the component’s boundary. It’s simple to start a system drag when at the point at which the user clicks the cursor on an item—but I want the system drag to start only when the component gets a mouseExited() during an in-component drag. After a bit of experimentation, I found that I could accomplish this using a custom, somewhat corrupt DragGestureRecognizer (application-specific code indicated by $dollar signs$):

private class ExitDragGestureRecognizer 
    extends DragGestureRecognizer {
    public ExitDragGestureRecognizer(Component comp) {
        super(DragSource.getDefaultDragSource(), comp);
    }

    public synchronized int getSourceActions() {
        return DnDConstants.ACTION_COPY_OR_MOVE;
    }

    protected void registerListeners() {}

    protected void unregisterListeners() {}

    public void setEvent(InputEvent e) {
        resetRecognizer();
        appendEvent(e);
    }
}

private ExitDragGestureRecognizer dgr = 
    new ExitDragGestureRecognizer($myPanel$);

Then, in the component’s attached MouseListener, the following code transfers from a local to a system drag when the cursor hits the component boundary:

public void mouseExited(MouseEvent e) {
    if ($inLocalDrag()$) {
        Transferable trans = $getDragTransferable()$;
        DragSource source = DragSource.getDefaultDragSource();
        DragGestureEvent event = 
            new DragGestureEvent(dgr, DnDConstants.ACTION_COPY,
            $localDragStartPoint$, Collections.singletonList(e))
        dgr.setEvent(e);
        source.startDrag(event, DragSource.DefaultCopyDrop, 
            trans, null);

        $endLocalDrag()$;
    }
}

In my testing, this seemed to work under J2SE 1.4+ on Windows XP and Mac OS X 10.3.7. It’s really not all that difficult, but the only way I was able to figure it out was just by guessing at calls and seeing where they failed. If anyone knows of a good in-depth Swing reference that talks addresses this sort of thing, please let me know.

12/24/2004

Mac OS X Graphic Performance Tidbits

Filed under: — Joe @ 9:46 am

Quartz Debug

Lately I’ve been digging into the details of the Mac OS X graphics subsystem, both because a lot of my (Java) code exercises it, and partly because I might be building something similar at some point.

OS X owes its renowned visual stability to the fact that every single window is buffered; to be exact, drawing commands from programs are executed into offscreen buffers, which are flushed to the screen (with an eye to where the CRT beam is!) when WaitNextEvent or QDFlushPortBuffer are called. Keeping a bitmap for each window is what allows OS X to sling windows around without visual glitching, even when applications are frozen up compeletely. It is, of course, a very expensive proposition in terms of the system RAM that it consumes. It hadn’t sunk in for me before that every single open window, visible or not, eats up significant RAM—maybe that’ll convince me to close old windows a little more often, especially on my poor 640MB iBook.

The other thing that I had heard about before but hadn’t tried before is the Quartz Debug utility, which you’ll find in /Developer/Applications/Performance Tools/Quartz Debug if you have the Developer Tools installed on your machine. If you run that and check off Flash screen updates (yellow) and No delay after flash, you’ll get a nice view into the workings of the graphics system, because any area of the screen buffer that changes will flash yellow. One interesting thing that this makes apparent is an advantage that Safari has over Firefox: when scrolling, Safari updates only the newly-exposed area of the window, making for smoother scrolling than Firefox, which always redraws the whole content pane. Another thing that it made obvious to me is how horribly inefficient some parts of the Geobrowser are in terms of redrawing things which haven’t changed visually—I need to be more conscientious about calling repaint() with an affected area and minding the clip rectangle in paintComponent(). (It actually makes me happy to discover clear-cut avenues for optimization like that.)

I’m still looking for real nuts-and-bolts details on what happens during screen updates. Here’s the mental model that I’ve pieced together so far:

  1. An application performs some drawing operations, which modify an offscreen window buffer #1
  2. The application calls QDFlushPortBuffer with an affected region rectangle, which blocks while…
  3. The affected region of the application window is blitted from buffer #1 to buffer #2 (the Window Server’s buffer for that window)
  4. The affected region of the screen is re-composited by Quartz Compositor (Extreme or otherwise) and blitted to the frame buffer when the CRT beam or LCD refresh point is elsewhere

If you know better and I’m getting some details wrong, don’t hesitate to comment.

12/22/2004

Ambient Dashboard

Filed under: — Joe @ 6:36 pm

Ambient Dashboard

While I always liked the idea of Ambient Devices, their first product, the Orb, felt very wishy-washy to me. I like the concept of output devices (in that case a single “pixel”) that can convey general information to me at a subconscious level, but there are also times when I’d like to “zoom in” to get more quantitative detail.

That’s why I find their new Dashboard much more appealing. The basic pitch is this: a battery-powered set of three physical gauges that can display your choice of metrics. The information arrives over old pager networks, so there are absolutely no wires involved. To change which information a gauge is showing, you simply insert a piece of plastic with a different set of tick marks. (If you look closely at the photo, you can see that they use the old punched-card system to detect which of the—hmm—1024? possible data channels the card represents.) The device itself is squarely in Brookstone territory at $150. The data service is free for generic channels like the Dow index, regional forecast, and presidential approval rating, but you pay $6.95 a month to get the personalized ones like pending email count, minutes until next meeting, and traffic congestion. With a nod to their early-adopter market, they also include a couple cards corresponding to developer channels—I’ll have to take another look when they open up their developer program in earnest.

How Upcoming.org could get some of the Flickr mojo.

Filed under: — Joe @ 10:13 am

Flickr Friends Page
Jason Kottke, in a post rounding up his favorite weblogs of the year, puts his Flickr friends page at #1:

Flickr is the most fun on the web right now. Period. It’s the closest thing I’ve experienced online to hanging out with your friends at the coffeeshop.

The combination of prevalent cameraphones, RSS, and social networking ideas takes Flickr out of the realm of the ofotos and creates something new, something more like a cross between LiveJournal and webcams. Maybe it’s my disposition, but I find myself much more likely to take a photo that tells a story about my life than to write something on my blog. (Even if a cellcam photo isn’t worth quite a thousand words, it’s often more than I’m motivated to write on my own.) And there’s definitely something absurd and addictive about letting others see scenes from your life in near-real-time.

It’s worth comparing it to a site with similar ideals, Upcoming.org. Upcoming is a 100% user-contributed site that lists events in any area that cares to create a city listing—pretty clever. It’s got some of the same social software elements: I can identify friends and get RSS listings of the events they’re interested in. So why is my Upcoming friends feed so much more of a wasteland than my Flickr one? I think it comes down to posting frequency. Unfortunately, in many places there isn’t all that much going on—and even when there is, many of us can’t spare the time or expense to go to shows every week. (It’s no surprise that the two most active metro areas on Upcoming are geek-hipster meccas New York and San Fran.) Simply put, there isn’t enough fodder in Upcoming’s scope for my friends and I to communicate about, and I can forget that the site exists for months at a time. If Upcoming wants to become more useful and prominent, they should allow for friends-only listings of “events” like private parties and happy hour meetups, which would move their service more into the realm of Evite. It would give them more traffic while giving users an opt-in alternative to Evite’s obnoxious HTML spam-mails.

With private events, Upcoming would be a more interesting window into your friends’ futures, but what about their pasts? A more radical change for Upcoming would be to expand their commenting system to allow users to post stories and photos about the events afterwards (or even, thanks to cellcams, during the event). In this way, an event listing in Upcoming would turn into a historical record, and serve as the common reference point for all of the other media and metadata about that event. As a recent Salon story pointed out, people are already using Flickr’s tagging and grouping systems to do this for things like weddings, art shows, and conferences. Why not give them a way do this less ambiguously and with better metadata?

12/21/2004

Mappr Interactive Demo

Filed under: — Joe @ 4:03 pm

Mappr Alpha

Mappr, a new photo-mapping site that uses the Flickr image-sharing infrastructure to display photo thumbnails on a map, has just made an interactive demo available. At this stage, it appears to be limited to showing subsets of a fixed set of photo collections (refreshed daily) on a state-level map of the U.S. However, the end result is something that performs with compelling smoothness on my old iBook. (Though it naturally bogs down a bit more as you hit the “Thank you sir, may I have another” button.) They claim to be determining the location based on place name heuristics in the photos’ tags (and possibly descriptions?). Note also the red “2″ in the screenshot above, which appears to be an aggregation indicator. I’ll be watching this one closely as they develop its capabilities further.

(Update) Unsurprisingly, free-text geocoding is fraught with peril:

Paris, Texas?

12/20/2004

IndyJunior Flash-based Travel Mapper

Filed under: — Joe @ 1:34 pm

IndyJunior
Have you ever wanted to see a map of your journeys, like the ones used to express travel time in old movies? After admiring the map on Dan Washburn’s Shanghai Diaries, I tracked down Bryan Boyer’s IndyJunior. Indy Junior is a simple Flash application that you can use to put a clickable travel map on your site. You create an XML file listing the latitude, longitude, date, and optionally notes and URL, for each place you visited, and the app will plot the locations on the map, with lines between them. As far as I can tell, the level of detail is limited to country outlines, but as long as you’re traveling far enough, the results should still look interesting.

Spam-Karma: So Far, So Good

Filed under: — Joe @ 8:09 am

I installed the Spam-Karma plug-in for WordPress last weekend on my family blog, and it’s working great, judging from the batch report it emailed me this morning:

Spam Karma Digest Report:
10 comments digested since last report (mmm, yummy!):

=+ Comment #1 Reason(s): Used HTTP_VIA header. OSA: Code or time not in submission. KARMA: -12 Treatment: hell Comment posted on Post ID: 50 Added Author IP to auto-ip list (snip). Author : cialis Email : snip URL : snip IP : snip Comment: 1817 Well said += ...

12/19/2004

Animated Transitions in Java

Filed under: — Joe @ 8:57 pm

An inspired bit of hackery by Dmitry Markman led to a flurry of collaborative development on Apple’s java-dev mailing list, and the result is a handy AnimatingCardLayout class that provides a variety of animated transitions between two Swing panels. It’s not nearly as smooth as the OS X effects that inspired it, but it may be as good as it gets without more direct access to graphics hardware from Java. Visit Dmitry’s site to see demo applets and get the source.

[Update] The project now has a permanent home at java.net.

12/18/2004

WordPress Fine-Tuning

Filed under: — Joe @ 7:03 pm

Since I’m setting up a couple of WordPress installations today, here are the post-installation steps that I like to go through, for my future reference and your possible edification.

  • create non-admin users
  • delete sample post
  • remove the default sidebar links
  • create categories
  • set basic blog metadata in Options → General Options
  • change RSS feed to full content in Options → Reading → Syndication Feeds
  • change permalinks to the template /%year%/%monthnum%/%postname%/
  • create .htaccess file in the root directory of the blog and chmod it to 666
  • use the template editor to put the rewrite rules from the permalink page into the .htaccess
  • change wp-includes/template-functions-links.php as specified in this post to fix broken calendar links
  • install WordPress Plugin Manager
  • install Spam-Karma using Plugin Manager
  • install and enable the latest version of PHP Markdown
  • install the “del.icio.us cached” plugin using Plugin Manager, and add a delicious('username') call to index.php
  • general mucking with the templates

The Incrementalist

Filed under: — Joe @ 12:00 pm

I’ve decided to separate my work-related postings from the general discussion blog that I share with Nick Fox-Gieg, so that I can be free to geek out here and post extended shop talk that would bore some of my friends to tears.

Why The Incrementalist? Well, after reading Rands’s excellent essay on Incrementalists & Completionists, I realized that the role that I generally play at MAYA is generally that of the former. And my experiences working on buskarma and YouRepresentUs have convinced me that it’s often possible to build something which isn’t perfect, but which makes the world an ever-so-slightly better place. In addition, the Pebble Soup effect often kicks in once you’ve got something up and running—it’s much more rewarding to contribute a marginal improvement to something that’s already functional. And besides, the master plan is almost never completely right. We still need the dreamers to point us toward the horizon, but the best way to get there will always be one step at a time.