The Source for Java Technology Collaboration
User: Password:



Joerg Plewe's Blog

Community: JavaDesktop Archives


WYLIWYT - where you look is where you type in NetBeans

Posted by herkules on October 04, 2007 at 01:25 PM | Permalink | Comments (3)

In my latest blog I wrote about the TrackIR device and my Java binding JTrackIR. The device allows to track the users head position and attitude in front of the screen using infrared reflecting strips on a basecap the user has to wear.

Now what to do with it? What about controlling the IDE with the head? Activating different areas (editor, properties, output ...) by just looking at them. So that the keyboard focus is always in the window I am looking at.

A good opportunity for an excercise of NetBeans module development that I did not do for quite a time now (NB5 or so...).

Creating the infrastructure for the module was surprisingly easy. Just calling some wizards for a library module wrapping my jtrackir.jar, a module that does the actual work and a module suite sueing everything together. Finally I created a TopComponent that can control the TrackIR device. I configured the suite to be a standalone application and added some IDE modules to have some more windows for testing. Very easy.
The TopComponent is meant to visualize where the user is looking at. For that, a scheme of the current Mode layout - that's how NetBeans calls the different areas of a GUI application - is rendered as it can be seen at the bottom left of the screenshot. The red dot is the place I'm currently looking at.

NB_JTrackIR_screenshot.jpg


To code the functionality I needed some help from the web, but as soon as somebody guide me to WindowManager the rest was quite easy.

Using the module requires a bit of practise and fine tuning the 'sensitivity' value. After that, it is possible to have the focus really in the window I am looking at. I admit the module is of low practical value, but at least it was fun to create the module and get acquainted with some NetBeans APIs e.g. like NbPreferences used to save the sensitivity value.
It was my first time creating, starting and debugging an appplication with the NetBeans RCP and I have to say: very easy, very cool, it just worked! I was suprised how fast the edit-compile-debug cycle was (that has to launch a full copy of the NetBeans framework) even on my poor notebook. I can encourage everybody to try it out.

Head banging...

Posted by herkules on September 30, 2007 at 10:58 AM | Permalink | Comments (2)

TrackIR is a headtracking device that currently is quite popular amongst gamers, especially in the simulation community.
It consists of a small device to be placed on top of the monitor and a prepared base cap with three IR reflecting strips.
JTrackIR is my Java binding. Not a big thing, but maybe useful to somebody.


TrackIR4-laptop-TrackClip-hat.jpg

2inch-TRACKIR4-iso-ns.jpg

TrackIR shows an impressive resolution and supports all 6 axes (x,y,z,yaw,pitch,roll). So it not only detects the heads attitude but also the translational position and even the heads distance from the screen.

6DOFmovement.jpg

The device is not cheap but also not extraordinary expensive and definitely worth the money if you have a good use-case.

As with all parts of the Distributed RealTime Simulation project on SourceForge, the source is available from cvs.
The Java source code is free while I'm not allowed to opensource the C/C++ code accessing the TrackIR DLL because it is covered under an NDA. So you have to refer to the compiled binary located in the bin directory.

The API is stupid simple. For there can only be a single device, the API layout is completely static. Here are parts of it:


public static void setDeveloperID( int id );
public static void update();
public static boolean isOperational();
public static float getRoll();
public static float getPitch();
public static float getYaw();
public static float getX();
public static float getY();
public static float getZ();
...


The jar file in the bin folder there also contains a simple test UI that paints the values as it is delivered by the device.

.


jtrackir_screenshot.jpg


Currently, JTrackIR is not yet embodied to FlyingGuns. My own architecture placed the camera far away from the input system, so they are hard to connect :). But there is still some hope.

If you think controlling something with your head and you like to use your head not only for its mental power, JTrackIR allows you to do that easily and your application might proudly show a new logo:
trackir_logo50.jpg




My first CVS checkin 2007

Posted by herkules on December 31, 2006 at 04:47 PM | Permalink | Comments (0)


This is my first CVS checkin 2007!



Happy coding to everybody in the new year.




C with NetBeans on Linux ... check it out!

Posted by herkules on December 21, 2006 at 09:27 AM | Permalink | Comments (10)

My current project is something with C on Linux. This is no fun, believe me. Especially when you are used to the rich development environment in the Java world.

What do we have on Linux? vi, emacs, make, kdevelop, gdb. Ouch.

Fortunately, Java tools reach out to that foreign, hostile world. First I tried Eclipse/CDT which works pretty well and I use it for my daily development. By far the best thing I could get hold of. The C/C++ module for NetBeans, which was at beta3 those days, was not in a productive state.

Today, I gave it a second try with all the brand new stuff. JDK6, NetBeans 5.5 and the new C/C++ development pack - surprise, surprise! It looks pretty polished and works like a charm.

NB/C wraps very nicely around existing Makefiles. This allowed me to browse a real complex project (>1mio LOC) within the IDE very soon. It also recognized the SVN structure immediately and guided me smoothly to checkin the NB projects just created. Another big plus is that it was very easy to create the NB projects completely separated from the source directories. I missed that in Eclipse (maybe it's my fault). And no more switching between 'perspectives' which I always found annoying. A matter of taste. Also, NetBeans 5.5 runs very smooth even on an X terminal.

So I had 2 lucky hours today exploring my new toy. Everything was so easy. Maybe tomorrow I will run into the issues. But thats OK for a first release. I'll just post the issues to the NB bug tracker. Typically they do respond quickly.

What I love about NetBeans is the speed of improvement. Subversion, UML, C/C++ and much more ... all that has been added just recently. So I'm really excited to see what comes next....

'Close' icons on a JTabbedPane w/o UI interference

Posted by herkules on October 29, 2005 at 04:18 AM | Permalink | Comments (7)

Many apps require a 'close' icon on a tab of a JTabbedPane. The solutions I've seen so far all require manipulation of the L&F classes which can be considered bad in many respects.

There is another option that works without interference with the UI classes. It relies on a special implementation of Icon that is sensitive to the mouse itself. Such an icon can be set for each tab (setIconAt()). This solution is far from perfect. E.g. the close icon always appears on the left side of the tabs text. But it is simple, easy to use and works with all L&Fs. The schema might be useful in other areas of icon usage as well.

How does it work?

The implementation of CloseTabIcon uses are common Icon and delegates all method calls to it. Just, during paintIcon(), it remembers the last position the icon has been painted and additionally adds a MouseListener to the resp. Component. This mouselistener can test wether the mouse button has been pressed above the icon and perform the appropriate action then.

In order not to loose the possibility to set an icon to the tab that does not close it, I provide another utility class CombinedIcon. It implements Icon and delegates to two Icons given to its constructor. Using CombinedIcon and CloseTabIcon can create JTabbedPanes like this:




/*
 * TabCloseIcon.java
 */

package de.hardcode.util.swing;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTabbedPane;

/**
 *
 * @author Herkules
 */
public class TabCloseIcon implements Icon
{
	private final Icon mIcon;
	private JTabbedPane mTabbedPane = null;
	private transient Rectangle mPosition = null;
	
	/**
	 * Creates a new instance of TabCloseIcon.
	 */
	public TabCloseIcon( Icon icon )
	{
		mIcon = icon;
	}
	
	
	/**
	 * Creates a new instance of TabCloseIcon.
	 */
	public TabCloseIcon()
	{
		this( new ImageIcon( TabCloseIcon.class.getResource("icons/closeTab.gif")) );
	}
	
	
	/**
	 * when painting, remember last position painted.
	 */
	public void paintIcon(Component c, Graphics g, int x, int y)
	{
		if( null==mTabbedPane )
		{
			mTabbedPane = (JTabbedPane)c;
			mTabbedPane.addMouseListener( new MouseAdapter()
			{
				@Override public void mouseReleased( MouseEvent e )
				{
					// asking for isConsumed is *very* important, otherwise more than one tab might get closed!
					if ( !e.isConsumed()  &&   mPosition.contains( e.getX(), e.getY() ) )
					{
						final int index = mTabbedPane.getSelectedIndex();
						mTabbedPane.remove( index );
						e.consume();
					}
				}
			});
		}
		
		mPosition = new Rectangle( x,y, getIconWidth(), getIconHeight() );
		mIcon.paintIcon(c, g, x, y );
	}
	
	
	/**
	 * just delegate
	 */
	public int getIconWidth()
	{
		return mIcon.getIconWidth();
	}
	
	/**
	 * just delegate
	 */
	public int getIconHeight()
	{
		return mIcon.getIconHeight();
	}
	
}
Find the sourcecode here and a usage sample here.

Quick tabbedpane switching w/o sacrifying mnemonics

Posted by herkules on September 08, 2005 at 03:51 AM | Permalink | Comments (6)

Having JTabbedPanes with many tabs can be awkward concerning keyboard usage. Per-tab mnemonics are not really an option because they really limit the number of available mnemonics for the tabs own valuable content!

Facing this problem, I created the TabSwitcher utility applicable to any JTabbedPane:
new TabSwitcher(tabbedpane, KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.ALT_DOWN_MASK));
TabSwitcher will automatically pop up when the given KeyStroke occurs on the JTabbedPane. It reflects the current number of tabs with their resp. titles and icons, computes a reasonable set of mnemonics and offers them as a JPopupMenu right at the position of the currently selected tab.

For the usage is mnemonic-like, I suggest to use an ALT-combination for the KeyStroke (Alt-T in my sample above).

screenshot


Find the sourcecode here and a usage sample here.



Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds