if ( event.getKeyCode() == KeyEvent.VK_F1 ) {
// function key F1 pressed
XInterface oInterface;
XDesktop oDesktop;
XComponentLoader oCLoader;
XComponent aDoc = null;
String stringParentNode = "";
String stringURLDocument = "";
// Path to the selected node
TreePath treePath = tree.getSelectionPath();
// get the parent node
if ( treePath.getParentPath() != null ) {
stringParentNode = treePath.getParentPath().getLastPathComponent().toString();
}
// get the stored object
Object object = hashtableObjects.get( treePath.toString() );
// set the context dependend part of the URL path for the documentation
if ( treePath.getPathCount() % 2 <= 0 ) {
// Category is selected
stringParentNode = treePath.getParentPath().getLastPathComponent().toString();
int intBegin = stringParentNode.indexOf( " = (" ) + 4;
int intEnd = stringParentNode.indexOf( ")" );
stringURLDocument = stringParentNode.substring( intBegin, intEnd ).replace( '.', '/' ) + ".html";
}
else if ( object != null ) {
// Complex property selected
String stringNode = treePath.getLastPathComponent().toString();
int intBegin = stringNode.indexOf( " = (" ) + 4;
int intEnd = stringNode.indexOf( ")" );
stringURLDocument = stringNode.substring( intBegin, intEnd ).replace( '.', '/' ) + ".html";
}
else if ( stringParentNode.equals( "Methods" ) ) {
// Method selected
String stringNode = treePath.getLastPathComponent().toString();
int intBegin = stringNode.indexOf( " " ) + 1;
int intEnd = stringNode.indexOf( " (" );
String stringMethod = stringNode.substring( intBegin, intEnd );
Object objectGrandParent = hashtableObjects.get( treePath.getParentPath().getParentPath().toString() );
XIntrospectionAccess xIntrospectionAccess = xIntrospection.inspect( objectGrandParent );
XIdlMethod xIdlMethod = xIntrospectionAccess.getMethod( stringMethod, com.sun.star.beans.MethodConcept.ALL );
String stringDeclaringClass = xIdlMethod.getDeclaringClass().getName().replace( '.', '/' );
stringURLDocument = stringDeclaringClass + ".html#" + stringMethod;
}
else if ( ( stringParentNode.equals( "Services" )
|| ( stringParentNode.equals( "Interfaces" ) ) ) ) {
// Service or interface selected
stringURLDocument = treePath.getLastPathComponent().toString().replace( '.', '/' ) + ".html";
}
else if ( ( (DefaultMutableTreeNode) treePath.getLastPathComponent() ).getChildCount() == 0 ) {
// Simple property selected
String stringGrandParentNode = treePath.getParentPath().getParentPath().getLastPathComponent().toString();
int intBegin = stringGrandParentNode.indexOf( " = (" ) + 4;
int intEnd = stringGrandParentNode.indexOf( ")" );
stringURLDocument = stringGrandParentNode.substring( intBegin, intEnd ).replace( '.', '/' ) + ".html";
}
// get the component loader
oInterface = (XInterface) xmulticomponentfactory.createInstanceWithContext( "com.sun.star.frame.Desktop", xcomponentcontext );
oDesktop = ( XDesktop ) UnoRuntime.queryInterface( XDesktop.class,
oInterface );
oCLoader = ( XComponentLoader ) UnoRuntime.queryInterface( XComponentLoader.class, oDesktop );
PropertyValue [] szEmptyArgs = new PropertyValue [0];
// open a HTML document from OpenOffice.org
aDoc = oCLoader.loadComponentFromURL("http://api.openoffice.org/common/ref/" + stringURLDocument,
"_blank", 0, szEmptyArgs );
}
}
catch ( Exception exception ) {
System.err.println( exception );