Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 175530

Summary: Figures always visible
Product: [Tools] GEF Reporter: Manuel Selva <manuel.selva>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: eric, nyssen, stephan, vinuthamr
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Manuel Selva CLA 2007-02-26 10:16:41 EST
Hi all,

Dealing a lot with Draw2D, i would like to have capability for figures to be always visible, even if the underlying figure canvas is scrolled. For example, have a big chart with an always visible message at center to indicate: "DEMONSTRATION CHART". This message mustn't be redrawn or moved each time the user scroll.

I am investigating solutions to do this, but can't find anyone at this time.

Any help would we welcomed.

Manuel Selva
Comment 1 Alexander Nyßen CLA 2010-12-17 16:26:22 EST
You may add such a figure to one of the upper layers (e.g. feedback or guide layer) or you may introduce a separate layer with a DelegatingLayout and use a Locator to place the figure. 

As this is thus a use case already supported by the framework, resolving this one as wontfix.
Comment 2 Kenneth Vasilik CLA 2012-12-10 07:15:58 EST
Hello,

I want to do something very similar: I want headers at the top of the display to remain there even when the canvas is scrolled.  I implemented Alexander's suggestion, but I had to add a listener on the scrollbar to revalidate the root figure to correctly position the figure I always want visible.  In addition to this, the experience is quite bad in that the figure jitters when scrolled.  

Here is my test case:

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.DelegatingLayout;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.FreeformViewport;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.Locator;
import org.eclipse.draw2d.ScalableFreeformLayeredPane;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Test {
    
    private void run() {

        // Create Shell

        Shell shell = new Shell( new Display() );
        shell.setBounds( 100, 100, 400, 300 );
        shell.setText( "Test" );
        shell.setLayout( new FillLayout() );
        
        final FigureCanvas canvas = new FigureCanvas( shell, SWT.DOUBLE_BUFFERED );
        canvas.setBackground( ColorConstants.white );
        canvas.setViewport( new FreeformViewport() );
        
        final ScalableFreeformLayeredPane root = new ScalableFreeformLayeredPane();
        root.setFont( shell.getFont() );
        canvas.setContents( root );

        FreeformLayer primary = new FreeformLayer();
        primary.setLayoutManager( new FreeformLayout() );
        root.add( primary, "Container" );
        LayoutManager layoutManager = primary.getLayoutManager();
        
        FreeformLayer headers = new FreeformLayer();
        headers.setLayoutManager( new DelegatingLayout() );
        root.add( headers, "Headers" );
        
        final Label header = new Label( "header" );
        header.setBorder( new LineBorder() );
        headers.add( header );
        
        headers.getLayoutManager().setConstraint(
            header,
            new Locator() {
                @Override public void relocate( IFigure target ) {
                    int y = canvas.getVerticalBar().getSelection();
                    Dimension size = target.getPreferredSize();
                    target.setBounds( new Rectangle( 10, y, size.width, size.height ) );
                }
            }
        );
        
        Label data = new Label( "contents" );
        data.setBorder( new LineBorder() );
        primary.add( data );
        layoutManager.setConstraint( data, new Rectangle( 10, 40, 600, 500 ) );
        
        canvas.getVerticalBar().addSelectionListener(
            new SelectionAdapter() { public void widgetSelected( SelectionEvent e ) { header.revalidate(); } }
        );
                    
        
        Display display = shell.getDisplay();
        shell.open();
        while (!shell.isDisposed()) {
            while (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    public static void main(String[] args) {
        new Test().run();
    }
}