<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Greg Brown&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/gkbrown/" />
<modified>2008-08-27T18:09:14Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/gkbrown/392</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, gkbrown</copyright>
<entry>
<title>Creating Fixed-Column Tables in Pivot</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/gkbrown/archive/2008/08/creating_fixedc_1.html" />
<modified>2008-08-27T18:09:14Z</modified>
<issued>2008-08-27T15:10:12Z</issued>
<id>tag:weblogs.java.net,2008:/blog/gkbrown/392.10346</id>
<created>2008-08-27T15:10:12Z</created>
<summary type="text/plain">Demonstrates how to create tables with fixed columns in a Pivot application.</summary>
<author>
<name>gkbrown</name>

<email>gkbrown@mac.com</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/gkbrown/">
<![CDATA[<p>I came across this <a href="http://blog.flexexamples.com/2007/08/15/locking-columns-in-a-horizontally-scrolling-datagrid-control/">Flex demo</a> the other day that demonstrates the use of fixed columns in a Flex data grid:</p>

<iframe src="http://blog.flexexamples.com/wp-content/uploads/DataGrid_lockedColumnCount_test/bin/main.html" width="360" height="240" style="border:solid 1px black"></iframe>

<p>I wanted to see how this might work in Pivot. Here's what I came up with:</p>

<iframe src="https://pivot.dev.java.net/nonav/demos/fixed_column_table.html" width="360" height="240" style="border:solid 1px black"></iframe>

<p>This is the WTKX source I used to create the table. One TableView and TableViewHeader set is placed in the scroll pane's row header and corner to create the fixed column, and another set is placed in the view and column header to create the scrollable columns. The same data is used to drive both tables:</p>

<pre>
&lt;Border styles="{padding:0, borderColor:'#cccac2'}"
    xmlns:wtkx="http://pivot.dev.java.net/wtkx/2008" xmlns="pivot.wtk"&gt;
    &lt;ScrollPane horizontalScrollBarPolicy="fillToCapacity"&gt;
        &lt;view&gt;
            &lt;TableView wtkx:id="primaryTableView" selectMode="single"
                styles="{selectionColor:'#ffffff', inactiveSelectionColor:'#ffffff',
                    selectionBackgroundColor:'#14538B', inactiveSelectionBackgroundColor:'#14538B',
                    showHighlight:false}"&gt;
                &lt;columns&gt;
                    &lt;TableView.Column name="colA" headerData="Column A"/&gt;
                    &lt;TableView.Column name="colB" headerData="Column B"/&gt;
                    &lt;TableView.Column name="colC" headerData="Column C"/&gt;
                &lt;/columns&gt;
                &lt;tableData wtkx:id="tableData"&gt;
                    &lt;row name="User 1" colA="1.A" colB="1.B" colC="1.C" /&gt;
                    &lt;row name="User 2" colA="2.A" colB="2.B" colC="2.C" /&gt;
                    &lt;row name="User 3" colA="3.A" colB="3.B" colC="3.C" /&gt;
                    &lt;row name="User 4" colA="4.A" colB="4.B" colC="4.C" /&gt;
                    &lt;row name="User 5" colA="5.A" colB="5.B" colC="5.C" /&gt;
                    &lt;row name="User 6" colA="6.A" colB="6.B" colC="6.C" /&gt;
                    &lt;row name="User 7" colA="7.A" colB="7.B" colC="7.C" /&gt;
                    &lt;row name="User 8" colA="8.A" colB="8.B" colC="8.C" /&gt;
                &lt;/tableData&gt;
            &lt;/TableView&gt;
        &lt;/view&gt;
        &lt;columnHeader&gt;
            &lt;TableViewHeader wtkx:id="primaryTableViewHeader" tableView="$primaryTableView"/&gt;
        &lt;/columnHeader&gt;
        &lt;rowHeader&gt;
            &lt;TableView wtkx:id="fixedTableView" tableData="$tableData" selectMode="single"
                styles="{selectionColor:'#ffffff', inactiveSelectionColor:'#ffffff',
                    selectionBackgroundColor:'#14538B', inactiveSelectionBackgroundColor:'#14538B',
                    showHighlight:false, includeTrailingVerticalGridLine:true}"&gt;
                &lt;columns&gt;
                    &lt;TableView.Column name="name" headerData="Name"/&gt;
                &lt;/columns&gt;
            &lt;/TableView&gt;
        &lt;/rowHeader&gt;
        &lt;corner&gt;
            &lt;TableViewHeader wtkx:id="fixedTableViewHeader" tableView="$fixedTableView"
                styles="{includeTrailingVerticalGridLine:true}"/&gt;
        &lt;/corner&gt;
    &lt;/ScrollPane&gt;
&lt;/Border&gt;
</pre>

<p>The Pivot version does require a little more code than the Flex version, primarily to keep the selection state of the two tables in sync - the Java source for the demo is <a href="https://pivot.dev.java.net/source/browse/pivot/trunk/demos/src/pivot/demos/tables/FixedColumnTable.java?view=markup">here</a>. The gradients used to create the look and feel of the Flex version also look a little nicer. However, scrolling and column resizing in the Pivot table is much smoother. Additionally, the Pivot version addresses some issues raised by readers of the original article:</p>

<p><cite>"Is there a way to not have the scrollbar under the first column so the scrollbar component does not span the whole datagrid but just the columns that can scroll? This would be better for the user."</cite></p>

<p><cite>"Is there a way to remove that black vertical grid line. Tried a number of ways, sounds impossible."</cite></p>

<p>So, it wasn't especially tough to implement, and it compares pretty favorably overall to the Flex version.</p>]]>

</content>
</entry>
<entry>
<title>Using Decorators in Pivot</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/gkbrown/archive/2008/08/using_decorator.html" />
<modified>2008-08-22T21:44:47Z</modified>
<issued>2008-08-22T21:44:32Z</issued>
<id>tag:weblogs.java.net,2008:/blog/gkbrown/392.10332</id>
<created>2008-08-22T21:44:32Z</created>
<summary type="text/plain">How to use Pivot&apos;s decorator feature to achieve interesting visual effects in Java2D.</summary>
<author>
<name>gkbrown</name>

<email>gkbrown@mac.com</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/gkbrown/">
<![CDATA[<html>
<body>
<p>I've recently been reading through the excellent <a href="http://www.sun.com/books/catalog/filthy_rich_clients.xml">Filthy Rich Clients</a> book by Chet Haase and Romain Guy. I picked it up a couple of weeks ago to see how I might apply some cool Java2D effects to a Pivot application. Since both Pivot and Swing are based on Java2D, I was hoping it wouldn't be too tough. Turns out that it was actually pretty easy.</p>

<p>For example, the book contains a section on creating reflections. In Swing, this requires a custom repaint manager. In Pivot, it can be done with a decorator. Decorators allow a caller to attach additional rendering behavior to a component. The decorator interface is defined as follows:</p>

<pre>
public interface Decorator {
    public Graphics2D prepare(Component component, Graphics2D graphics);
    public void update();

    public Rectangle getBounds(Component component);
    public void repaint(Component component, int x, int y, int width, int height);
}
</pre>

<p>The <tt>prepare()</tt> method is called immediately before the component's <tt>paint()</tt> method and allows the caller to modify or replace the graphics object on which the component will be painted. For example, Pivot's <tt>DropShadowDecorator</tt> class paints a semi-transparent black rectangle underneath a component to simulate a drop shadow. The <tt>FadeDecorator</tt> sets an <tt>AlphaComposite</tt> on the graphics before the component is called, making the entire component appear translucent.</p>

<p>The <tt>update()</tt> method is called just after painting the component. This allows a caller to paint on top of a component after the component itself is done painting. For example, the <tt>ShadeDecorator</tt> class paints a semi-transparent colored rectangle over an entire component, and the <tt>WatermarkDecorator</tt> class paints a string of text over a component, simulating a paper watermark.</p>

<p>The <tt>prepare()</tt> and <tt>update()</tt> methods can also be used together to achieve interesting visual effects. <tt>BlurDecorator</tt> and <tt>GrayscaleDecorator</tt> take a "snapshot" of the component by returning a BufferedImage graphics object from <tt>prepare()</tt>, then paint the buffered image to the original graphics object in <tt>update()</tt>. <tt><a href="https://pivot.dev.java.net/source/browse/pivot/trunk/wtk/src/pivot/wtk/effects/ReflectionDecorator.java?view=markup">ReflectionDecorator</a></tt> also works this way, and uses a technique similar to that described in the book to paint the reflection of an undecorated window containing a JPEG image.</p>

<p>Multiple decorators can be attached to a component, and decorators are "chained". The decorators' <tt>prepare()</tt> methods are called in descending order, passing the graphics output of each to the prior decorator. The <tt>update()</tt> methods are called in ascending order after the component is painted. This allows a caller to create a window whose contents are rendered in black and white and also paints a drop shadow, for example. 

<p>In addition to trying out some of the examples in Filthy Rich Clients, I was also inspired to see how I might implement the translucent window effect described in Josh Marinacci's <a href="http://weblogs.java.net/blog/joshy/archive/2008/06/java_doodle_fad.html">web log</a> a few weeks back. An instance of <tt>FadeDecorator</tt> attached to a <tt>Frame</tt> window did the trick. The result of both experiements is shown in the applet below:</p>

<iframe src="https://pivot.dev.java.net/nonav/demos/decorator.html" width="480" height="640" style="border: solid 1px black"></iframe>

<p>As in Josh's demo, mousing over the frame changes the opacity to 0.9, and mousing out changes it back to 0.5. Fortunately, it is a bit easier to implement the mouse handler logic in Pivot: simply attach a <tt>ComponentMouseListener</tt> to the frame:</p>

<pre>
fadeFrame.getComponentMouseListeners().add(new ComponentMouseListener() {
    public void mouseMove(Component component, int x, int y) {
        // No-op
    }

    public void mouseOver(Component component) {
        fadeDecorator.setOpacity(0.9f);
        component.repaint();
    }

    public void mouseOut(Component component) {
        fadeDecorator.setOpacity(0.5f);
        component.repaint();
    }
});
</pre>

<p>The Pivot version also doesn't require any OS-specific hacks - the same code works on OSX, Linux, and Windows.</p>

<p>The full source for the demo can be found <a href="https://pivot.dev.java.net/source/browse/pivot/trunk/demos/src/pivot/demos/decorator/">here</a>.

</body>
</html>]]>

</content>
</entry>
<entry>
<title>Introducing Pivot</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/gkbrown/archive/2008/06/introducing_piv.html" />
<modified>2008-06-11T16:58:15Z</modified>
<issued>2008-06-11T16:56:15Z</issued>
<id>tag:weblogs.java.net,2008:/blog/gkbrown/392.9955</id>
<created>2008-06-11T16:56:15Z</created>
<summary type="text/plain">Pivot is an open-source framework for building high-quality, cross-platform applications that are easily deployable both via the web and to the desktop. It began as an R&amp;D effort at VMware and is now being made available to the community as an option for developers who want to build rich client applications in Java.</summary>
<author>
<name>gkbrown</name>

<email>gkbrown@mac.com</email>
</author>
<dc:subject>Community: JavaDesktop</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/gkbrown/">
<![CDATA[<p>A little over a year ago, I wrote a blog entry describing how I thought applets could regain viability as an application development platform ("<a href="http://weblogs.java.net/blog/gkbrown/archive/2007/03/reinventing_the.html">Re-Inventing the Applet</a>", 3/6/2007). At the time, I made a few suggestions about what needed to improve in order for this to happen:</p>

<ul>
<li>
<cite>"A new, streamlined "Java Player" that can be easily downloaded and installed by end users...which, when first installed, would include only a minimal set of classes required by all applications"</cite>
<p>I later discovered that Sun had been actively working on this. At the time, they were calling it the "Consumer JRE", but it is now known as <a href="http://java.sun.com/developer/technicalArticles/javase/java6u10/index.html">"Java 6 Update 10"</a> and is scheduled for release later this year.</p>
</li>

<li>
<cite>
"A new GUI toolkit optimized for delivering the best possible user experience on modern operating systems and graphics hardware"
</cite>
<p>I learned that Sun had also taken some steps in this direction, optimizing the Java2D API to take better advantage of current graphics hardware (on Windows, at least).</p>
</li>
</ul>

<p>That left one item: the new GUI toolkit. As I suggested in the earlier article, Swing and AWT have grown a bit long in the tooth. The question then became - <i>what should a new Java-based GUI toolkit look like?</i> Sun seemed to think that a new scripting layer added on top of Swing was the answer, but that wasn't consistent with my objectives. I wanted something that would enable Java developers to easily build highly functional and visually engaging applications <i>in Java</i>, not another scripting language, providing capabilities similar to other modern GUI toolkits such as Flex and Silverlight.</p> 

<p>After nearly a year of development, I believe I now have an answer to that question.</p>

<h2>Introducing Pivot</h2>
<p>I would like to introduce the Java development community to the <a href="https://pivot.dev.java.net/">Pivot</a> platform. Pivot is an open-source framework for building high-quality, cross-platform applications that are easily deployable both via the web and to the desktop. It began as an R&D effort at VMware and is now being made available to the community as an option for developers who want to build rich client applications in Java.</p>

<p>Pivot applications are written using a combination of Java and XML and can be run either as an applet or as a standalone (optionally offline) desktop application. While Pivot was designed to be familar to web developers who have experience building AJAX applications using HTML, CSS, and JavaScript, it provides a much richer set of standard widgets than HTML, and allows developers to create sophisticated user experiences much more quickly and easily. Pivot will also seem familiar to Swing developers, as both Swing and Pivot are based on Java2D and employ a model-view-controller (MVC) architecture to separate component data from presentation. However, Pivot includes additional features that make building modern GUI applications much easier, including declarative UI, data binding, and web services integration.</p>

<p>Pivot isn't just another open source web toolkit - it is a full-featured, professional-grade development platform that is sufficiently functional to create a broad range of production-ready applications. We've done our best to include what we think are the most essential features for a 1.0 release, and we have tested as extensively as possible. However, we are looking to the Java development community to help us continue to expand upon what we have accomplished thus far. We need support from developers who are willing to start working with Pivot now, to help us identify issues, complete features, and create reference applications. We are excited about this platform, and we want other Java developers to be excited about it as well.</p>

<p>Pivot is currently being hosted at <a href="https://pivot.dev.java.net/">pivot.dev.java.net</a>. We hope to see you there!</p>

<p>-The Pivot Development Team</p>]]>

</content>
</entry>
<entry>
<title>Re-Inventing the Applet</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/gkbrown/archive/2007/03/reinventing_the.html" />
<modified>2008-06-24T19:17:03Z</modified>
<issued>2007-03-06T17:03:14Z</issued>
<id>tag:weblogs.java.net,2007:/blog/gkbrown/392.6747</id>
<created>2007-03-06T17:03:14Z</created>
<summary type="text/plain">Rich web clients are all the rage these days. It&apos;s time for the applet to make a comeback.</summary>
<author>
<name>gkbrown</name>

<email>gkbrown@mac.com</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/gkbrown/">
<![CDATA[<p>For all of the (arguably justifiable) buzz AJAX is getting these days, it can still be a pretty painful technology to use for developing web applications. JavaScript, the programming language used to build AJAX applications, is interpreted and only minimally object-oriented. HTML, the UI framework behind AJAX, remains, at its core, a page layout language, not a GUI toolkit. AJAX is certainly a step towards building better web apps, but it is by no means the final step.</p>

<p>It's time for the applet to make a comeback.</p>

<p>Applets were the original "rich client"-enabling technology. However, due to some early performance and compatibility issues, as well as the "lowest common denominator" approach taken by the AWT, they never really took off. Now, after over a decade of increasingly complex server-generated UI, new applet-like technologies are beginning to emerge:</p>

<ul>
<li>Microsoft's XAML Browser Applications, or XBAPs, are mini-applications that can be embedded in web pages. They are based on the Windows Presentation Foundation (WPF), a new, Windows-only, UI technology that is a key component of .NET 3.0 and Windows Vista. A lighter-weight version called WPF/E (for "WPF/Everywhere") is cross-platform and is tentatively scheduled for release later this year.</li>

<li>Adobe's Flex uses a combination of MXML, a UI markup language created by Macromedia, and ActionScript, an ECMAScript variant similar to JavaScript, to deliver rich client functionality via the cross-platform Flash player.</li>
</ul>

<p>So, while applets may have failed to gain widespread acceptance 10 years ago, there is clearly a continued, or at least renewed, interest in developing applications that can go beyond the capabilities of HTML. However, even these newer technologies have some limitations: XBAPs only run on Windows XP, Server 2003, and Vista, and require the .NET 3.0 runtime, which must be downloaded and currently weighs in at 50MB (though it may be pre-installed with Windows Vista). WPF/E is still in very early development, and, even when complete, will offer only a restricted subset of the the functionality provided by the full version of WPF; it includes only the most basic user input controls, making it unsuitable for developing all but the most trivial applications. Flex is more capable, but applications developed with Flex tend to seem slow, and the Flex platform itself seems (from my experience, anyways) fairly complex and a little buggy.</p>

<p>I think that it is time to re-introduce, and re-think, the applet.</p>

<p>Java is a solid, proven technology that is actively supported across all major operating systems and browser versions. What is needed is a streamlined "Java Player" that can be easily downloaded and installed by end users and is capable of running the "next generation" of Java-based web clients (I'll call them "Java Browser Applications", or JBAs, for now).</p>

<p>JBAs would run in a "lighter-weight" version of the Java Plugin, which, when first installed, would include only a minimal set of classes required by all applications. For example, the initial download might contain only java.lang, java.net, and possibly a GUI library (see below). Packages that aren't useful to most browser-based applications, such as RMI, JDBC, and CORBA, would not be included. However, the player would allow developers to specify additional required libraries to be downloaded (and cached) at runtime on a per-application basis, similar to Java Web Start. This would keep the initial plugin download size small but would allow developers to add additional functionality incrementally as needed.</p>

<p>Ideally, the player would include a new GUI toolkit optimized for delivering the best possible user experience on modern operating systems and graphics hardware (yes, it is time to deprecate the beleaguered Swing and AWT). Similar to WPF and Flex, this toolkit would support a declarative, XML-based UI markup language, allowing developers to quickly build and deploy highly functional and visually engaging applications. However, since such a toolkit does not yet exist, it might be useful to allow developers to specify a GUI package as a runtime download; this would allow the player to run existing applications built using AWT, Swing, or SWT without requiring built-in support for each toolkit, which would increase download size. The new, updated GUI library could be added in a later release of the player.</p>

<p>Though this represents something of a departure from the way Java is used on the client today, I believe it is consistent with the original vision of the applet and would create a strong platform for future web-based application development. Microsoft has created a very compelling technology in WPF; if they chose to make XBAPs cross-platform or WPF/E more powerful, the web development landscape would change almost overnight. But they won't, because a powerful, cross-platform application development technology will not help drive users to the Windows platform. Adobe does not seem to have enough mind share in the developer community to inspire developers to invest in the Flex platform, and, while AJAX is hot right now, the lack of a strongly-typed and truly object-oriented development language combined with the limitations of HTML will ultimately result in developers looking elsewhere.</p>

<p>Java on the client needs some new buzz, and developers need a new technology that can really move web development forward. Sun, what do you think? Are you ready to re-invent the applet?</p>]]>

</content>
</entry>

</feed>