Pivot 2.0 has been posted
Category: programming
Simple Effect
Pivot nicely provides a few nice effects for items. This is useful for images, etc but if you want to make a simple text-based header it needs the tiniest bit of tweaking.
What we need is to translate the reflection so it overlaps the text a little.
We can just modify the Reflection effect and two properties for x & y reflection translation and tweak where the reflection is drawn. Here’s the modified ConfigurableReflection class
public class ConfigurableReflection extends ReflectionDecorator { private Component component = null; private Graphics2D graphics = null; private BufferedImage componentImage = null; private Graphics2D componentImageGraphics = null; private int yTranslate = 0; private int xTranslate = 0; public void setXTranslate(int xTranslate) { this.xTranslate = xTranslate; } public void setYTranslate(int yTranslate) { this.yTranslate = yTranslate; } public int getXTranslate() { return xTranslate; } public int getYTranslate() { return yTranslate; } @Override public Graphics2D prepare(Component component, Graphics2D graphics) { this.component = component; this.graphics = graphics; int width = component.getWidth(); int height = component.getHeight(); componentImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); componentImageGraphics = componentImage.createGraphics(); // Clear the image background componentImageGraphics.setComposite(AlphaComposite.Clear); componentImageGraphics.fillRect(0, 0, componentImage.getWidth(), componentImage.getHeight()); componentImageGraphics.setComposite(AlphaComposite.SrcOver); return componentImageGraphics; } @Override public void update() { // Draw the component graphics.drawImage(componentImage, 0, 0, null); // Draw the reflection int width = componentImage.getWidth(); int height = componentImage.getHeight(); GradientPaint mask = new GradientPaint(0, height / 4f, new Color(1.0f, 1.0f, 1.0f, 0.0f), 0, height, new Color(1.0f, 1.0f, 1.0f, 0.5f)); componentImageGraphics.setPaint(mask); componentImageGraphics.setComposite(AlphaComposite.DstIn); componentImageGraphics.fillRect(0, 0, width, height); componentImageGraphics.dispose(); componentImageGraphics = null; componentImage.flush(); graphics.transform(getTransform(component)); graphics.drawImage(componentImage, 0, 0, null); componentImage = null; component = null; graphics = null; } @Override public Bounds getBounds(Component component) { // MODIFICATION for new translation return new Bounds(0, 0, component.getWidth() + xTranslate, component.getHeight() * 2 + yTranslate); } @Override public AffineTransform getTransform(Component component) { AffineTransform transform = AffineTransform.getScaleInstance(1.0, -1.0); // MODIFICATION for new translation transform.translate(xTranslate, -((component.getHeight() * 2) + yTranslate)); return transform; } }
Simple netbeans Pivot module
I got a little tired re-running my entire app just to see what the current pivot layout would look like, so here’s a quick and dirty plugin for Netbeans 6.8 which does the following:
- Pivot 1.5.1 library
- XML-editing and formatting for .wtkx files
- right-click, ‘Preview WTKX’ function
To use this module on a pivot project, Right-click on project, select properties and add the new Pivot 1.5.1 library to your project. When viewing a file, you first need to build your project then right click on the .wtkx files to preview.
Extracting selected pivot tree items
The pivot TreeView only returns selected paths. A path is a list of list indexes which refer to the underlying data model of a tree. Unfortunately, the treeview doesn’t have a convenience method for extracting the items referenced by those paths. Here’s that missing method:
public static List extractSelectedObjects(TreeView tv) { List retList = new ArrayList(); for (Path p : tv.getSelectedPaths()) { Object currBranch = tv.getTreeData(); for (int i : p) { currBranch = ((List) currBranch).get(i); } retList.add(currBranch); } return retList; }
Preventing grizzly timeouts
In grizzly, the default timeout for an http process is 5 minutes. This applies to the total activity time. In most cases, this is fine, however for long uploads you may need to extend this. Oh say for uploading 50g files. There is a switch for disabling timeouts, however this is global. What we need is a timeout for connections that are still active. Inactive connections should close 5m after last activity.
Grizzly logs the following:
Aug 12, 2010 3:17:25 PM com.sun.grizzly.http.KeepAliveThreadAttachment timedOut WARNING: GRIZZLY0023: Interrupting idle Thread: Grizzly-8080(2). Aug 12, 2010 3:17:27 PM com.sun.grizzly.http.KeepAliveThreadAttachment timedOut WARNING: GRIZZLY0023: Interrupting idle Thread: Grizzly-8080(3).
The somewhat messy solution is the pick apart the thread that your request is running in and toggle timeouts as needed.
while ((read = in.read(byteArray)) != -1) { if ((System.currentTimeMillis() - lastXmit) > 5000) { HttpWorkerThread thread = (HttpWorkerThread)Thread.currentThread(); ((SelectionKeyAttachment) thread.getProcessorTask().getSelectionKey().attachment()).setTimeout(lastXmit); lastXmit = System.currentTimeMillis(); } buffer.clear(); buffer.limit(read); openFile.write(buffer); }