Tags:
create new tag
view all tags

PDF Version Portrait Landscape

Help Did you spot something wrong or missing on this page? If you have an account on this TWiki, you can fix it yourself by editing the page. If you don't have an account, you can leave a message at the bottom of the page to tell us about it. Thank you in advance!

Adding components to existing views

The contents of certain views can be extended by developers, such as the Outline View and the Editor Area. Both are examples of the system reacting on a data selection made by the user.

Here we explain how you can contribute to the outline view and the editor area.


Outline View

Whenever the user selects a session variable in the VariablesView, a SelectionEvent is sent around.
The OutlineView is listening to such event and it tries to find the appropriate component that can show the outline information of that variable.

The contract for outline components is:

The recommended way of implementing OutlineComponent is by extending ObjectOutline, which provides a table with basic information about the variable.
Methods getExtraTableInfo() and getExtraComponent() may be overriden as needed for providing extra information about your type.

For example, suppose you want to create an outline for FineTime variables to show their contents in the outline view whenever a session variable of that type is selected by the user.

Component Implementation

In this example, we simply add an entry to the ObjectOutline with the contents of the FineTime.

public class FineTimeOutline extends ObjectOutline {

    @Override
    protected Object[][] getExtraTableInfo() {
        Object time = getSelection().getValue();
        return new Object[][] { { "time", time.toString() } };
    }
}

Component Registry

The following snippet would go into your __init__.py:

# Register to the variable outline factory
REGISTRY.register(COMPONENT,Extension(
                 "My FineTime Outline",
                 "resides.in.java.package.FineTimeOutline",
                 "factory.outline.variable",
                 "herschel.share.fltdyn.time.FineTime"))

See also the Extension Registry documentation for more details.

Source Code of Basic implementations

Package herschel.ia.dataset.gui contains some basic implementations for OutlineComponent objects:

Tip, idea If you have a sub-class of e.g. a product, you can also create a dedicated OutlineComponent for that sub-class, which will be picked up instead of the default ProductOutline.

FITS Preview Outline

A special kind of outline is devoted to show previews of FITS files (for images, cubes, spectra...).

This is managed by FitsFileOutline, which reads the product contained in the FITS file in the background, and shows an image preview for it when done.

For this to work properly, any type that is meaningful to produce a preview should:

1. Extend herschel.ia.gui.kernel.PreviewMaker. For example, for images (herschel.ia.gui.image.Image):

import herschel.ia.gui.image.Image;

public class ImagePreviewMaker extends PreviewMaker<Image> {

    // PreviewFactory needs that every preview maker provides a default public constructor
    public ImagePreviewMaker() {
	super(Image.class);
    }

    // Either override this method
    @Override public java.awt.Image makeImage(Object o) {
	if (!(o instanceof Image)) return null;
	Image image = (Image)o;
        // create a Java image from the dataset image object
    }

    // or this one, by returning a visible component that will be used for drawing the image
    @Override protected java.awt.Component makeComponent(Image image) {
        // create a Java component from the dataset image
    }
}
2. Register the preview maker in the corresponding __init__.py:
from herschel.ia.gui.kernel import ExtensionRegistry, Extension, PreviewFactory

REGISTRY.register(PreviewFactory.ID, Extension(
                  "Image preview maker",
                  "herschel.ia.gui.image.ImagePreviewMaker",
                  None,   # unused
                  "herschel.ia.dataset.image.Image"))

Editor Area

The above showed an example of extending the outline view by adding an OutlineComponent. Similarly, you can contribute by developing a specific EditorComponent.

Editor components are editors (optionally read-only) of data contents of a specific variable that is selected within in the HIPE session.
They are triggered by double-clicking on a variable, or through the Open With menu. Editor components are opened in the editor area.

The contract for editor components is:

Simple Example Code

import herschel.ia.gui.kernel.parts.AbstractVariableEditorComponent;

/**
 * Editor component for SomeType.
 */
public class SomeEditorComponent extends AbstractVariableEditorComponent<SomeType> {

    public Icon getComponentIcon() {
	return ...;
    }

    @Override
    protected Class<SomeType> getVariableType() {
	return SomeType.class;
    }

    @Override
    protected boolean makeEditorContent() {
        String name = getKey();
        SomeType value = getValue();
        JComponent content = ...;    // build the content with the provided value
        add(content);
        return true;
    }
}

Source Code of Basic implementations

The herschel.ia.gui.apps package contains some basic implementations for EditorComponent objects:

Component Registry

Editor components need to be registered for telling the types they are interested in. This is to be done within your __init__.py:

# Register to the editor component factory
REGISTRY.register(COMPONENT,Extension(
                 "Some editor",
                 "herschel.your.module.views.SomeEditorComponent",
                 "factory.editor.variable",
                 "herschel.your.module.SomeType"))


blog comments powered by Disqus
Edit | Attach | Watch | Print version | History: r23 < r22 < r21 < r20 < r19 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r23 - 2014-02-18 - AlvarGarcia
 
This site is powered by the TWiki collaboration platform Powered by Perl