Search in sources :

Example 1 with FunctionGraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.FunctionGraphLabelProvider in project hale by halestudio.

the class ImageContent method getImageContent.

/**
 * Get the function image for the function with the given identifier.
 *
 * @param func_id the function identifier
 * @param tempDir the temporary directory where the function image may be
 *            stored
 * @return the function image input stream or <code>null</code>
 * @throws Exception if an error occurs generating the image
 */
public static InputStream getImageContent(String func_id, File tempDir) throws Exception {
    final FunctionDefinition<?> function = FunctionUtil.getFunction(func_id, null);
    if (function == null) {
        log.warn("Unknown function " + func_id);
        return null;
    }
    final File _functionFile = new File(tempDir, func_id + ".png");
    if (!_functionFile.exists()) {
        Display display;
        if (Display.getCurrent() != null) {
            // use the current display if available
            display = Display.getCurrent();
        } else {
            try {
                // use workbench display if available
                display = PlatformUI.getWorkbench().getDisplay();
            } catch (Throwable e) {
                // use a dedicated display thread if no workbench is
                // available
                display = DisplayThread.getInstance().getDisplay();
            }
        }
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                // create an initial off-screen graph with fixed values;
                // resize the graph after computing the figures width and
                // height
                OffscreenGraph off_graph = new OffscreenGraph(300, 200) {

                    @Override
                    protected void configureViewer(GraphViewer viewer) {
                        LayoutAlgorithm algo = new FunctionTreeLayoutAlgorithm();
                        FunctionGraphContentProvider stcp = new FunctionGraphContentProvider();
                        // XXX no service provider given
                        FunctionGraphLabelProvider fglp = new FunctionGraphLabelProvider(null, false);
                        viewer.setContentProvider(stcp);
                        viewer.setLabelProvider(fglp);
                        viewer.setInput(function);
                        viewer.setLayoutAlgorithm(algo);
                    }
                };
                Graph graph = off_graph.getGraph();
                Dimension dim = computeSize(graph);
                int width;
                if (dim.width > 450) {
                    width = dim.width;
                } else {
                    // minimum width = 450
                    width = 450;
                }
                int height = dim.height;
                off_graph.resize(width, height);
                try {
                    off_graph.saveImage(new BufferedOutputStream(new FileOutputStream(_functionFile)), null);
                } catch (IOException e) {
                    log.warn("Conversion from Graph to Image failed!");
                } finally {
                    off_graph.dispose();
                }
            }
        });
    }
    if (_functionFile.exists()) {
        return new FileInputStream(_functionFile);
    }
    return null;
}
Also used : FunctionTreeLayoutAlgorithm(eu.esdihumboldt.hale.ui.common.graph.layout.FunctionTreeLayoutAlgorithm) Dimension(java.awt.Dimension) IOException(java.io.IOException) FunctionGraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.FunctionGraphLabelProvider) FileInputStream(java.io.FileInputStream) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) Graph(org.eclipse.zest.core.widgets.Graph) FunctionTreeLayoutAlgorithm(eu.esdihumboldt.hale.ui.common.graph.layout.FunctionTreeLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) FileOutputStream(java.io.FileOutputStream) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) FunctionGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.FunctionGraphContentProvider) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Display(org.eclipse.swt.widgets.Display)

Example 2 with FunctionGraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.FunctionGraphLabelProvider in project hale by halestudio.

the class FunctionGraphSection method createControls.

/**
 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite,
 *      org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
 */
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    Composite compparent = getWidgetFactory().createComposite(parent);
    compparent.setLayout(new FormLayout());
    Composite composite = getWidgetFactory().createComposite(compparent);
    composite.setLayout(new FillLayout());
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, -0);
    data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
    data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
    composite.setLayoutData(data);
    viewer = new GraphViewer(composite, SWT.NONE);
    viewer.setLayoutAlgorithm(treeAlgorithm, true);
    viewer.setContentProvider(new FunctionGraphContentProvider());
    viewer.setLabelProvider(new FunctionGraphLabelProvider(HaleUI.getServiceProvider(), true));
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) Composite(org.eclipse.swt.widgets.Composite) FunctionGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.FunctionGraphContentProvider) FillLayout(org.eclipse.swt.layout.FillLayout) FormAttachment(org.eclipse.swt.layout.FormAttachment) FunctionGraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.FunctionGraphLabelProvider)

Aggregations

FunctionGraphContentProvider (eu.esdihumboldt.hale.ui.common.graph.content.FunctionGraphContentProvider)2 FunctionGraphLabelProvider (eu.esdihumboldt.hale.ui.common.graph.labels.FunctionGraphLabelProvider)2 GraphViewer (org.eclipse.zest.core.viewers.GraphViewer)2 FunctionTreeLayoutAlgorithm (eu.esdihumboldt.hale.ui.common.graph.layout.FunctionTreeLayoutAlgorithm)1 OffscreenGraph (eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph)1 Dimension (java.awt.Dimension)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 Graph (org.eclipse.zest.core.widgets.Graph)1 LayoutAlgorithm (org.eclipse.zest.layouts.LayoutAlgorithm)1