Java Code Examples for org.eclipse.swt.widgets.Canvas#setLayoutData()

The following examples show how to use org.eclipse.swt.widgets.Canvas#setLayoutData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskSelectType.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void createTopPreviewArea( Composite parent )
{
	Composite cmpPreview = new Composite( parent, SWT.NONE );
	cmpPreview.setLayout( new GridLayout( ) );

	GridData gridData = new GridData( GridData.FILL_BOTH );
	gridData.horizontalSpan = 2;
	gridData.heightHint = 270;
	cmpPreview.setLayoutData( gridData );

	Label label = new Label( cmpPreview, SWT.NONE );
	{
		label.setText( getChartPreviewTitle( ) );
	}

	previewCanvas = new Canvas( cmpPreview, SWT.BORDER );
	previewCanvas.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	previewCanvas.setBackground( Display.getDefault( )
			.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );

	previewPainter = createPreviewPainter( );
}
 
Example 2
Source File: HoverInfoWithSpellingAnnotation.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void createAnnotationInformation(Composite parent, final Annotation annotation) {
    Composite composite= new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    GridLayout layout= new GridLayout(2, false);
    layout.marginHeight= 2;
    layout.marginWidth= 2;
    layout.horizontalSpacing= 0;
    composite.setLayout(layout);

    final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS);
    GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gridData.widthHint= 17;
    gridData.heightHint= 16;
    canvas.setLayoutData(gridData);
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setFont(null);
            fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
        }
    });

    StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(data);
    text.setText(annotation.getText());
}
 
Example 3
Source File: TaskSelectData.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void createPreviewArea( Composite parent )
{
	Composite cmpPreview = ChartUIUtil.createCompositeWrapper( parent );
	{
		GridData gridData = new GridData( GridData.FILL_BOTH );
		gridData.widthHint = CENTER_WIDTH_HINT;
		gridData.heightHint = 200;
		cmpPreview.setLayoutData( gridData );
	}

	Label label = new Label( cmpPreview, SWT.NONE );
	{
		label.setFont( JFaceResources.getBannerFont( ) );
		label.setText( Messages.getString( "TaskSelectData.Label.ChartPreview" ) ); //$NON-NLS-1$
	}

	previewCanvas = new Canvas( cmpPreview, SWT.BORDER );
	{
		GridData gd = new GridData( GridData.FILL_BOTH );
		previewCanvas.setLayoutData( gd );
		previewCanvas.setBackground( Display.getDefault( )
				.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
	}
}
 
Example 4
Source File: StyleChartViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * main() method for constructing the layout.
 * 
 * @param args
 */
public static void main( String[] args )
{
	Display display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setSize( 600, 400 );
	shell.setLayout( new GridLayout( ) );

	Canvas cCenter = new Canvas( shell, SWT.NONE );
	StyleChartViewer cv = new StyleChartViewer(  );
	cCenter.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	cCenter.addPaintListener( cv );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 5
Source File: AutoDataBindingViewer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * main() method for constructing the layout.
 * 
 * @param args
 */
public static void main( String[] args )
{
	Display display = Display.getDefault( );
	Shell shell = new Shell( display );
	shell.setSize( 600, 400 );
	shell.setLayout( new GridLayout( ) );

	Canvas cCenter = new Canvas( shell, SWT.NONE );
	AutoDataBindingViewer adbv = new AutoDataBindingViewer(  );
	cCenter.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	cCenter.addPaintListener( adbv );

	shell.open( );
	while ( !shell.isDisposed( ) )
	{
		if ( !display.readAndDispatch( ) )
			display.sleep( );
	}
	display.dispose( );
}
 
Example 6
Source File: AbstractWidgetTest.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAll() throws Exception {
	shell = new Shell();

	shell.open();
	shell.setLayout(new GridLayout(1, false));
	final Canvas canvas = new Canvas(shell, SWT.None);
	canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	text = new Text(shell, SWT.READ_ONLY);
	text.setFont(XYGraphMediaFactory.getInstance().getFont("default", 18,
			SWT.BOLD));
	text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
	final LightweightSystem lws = new LightweightSystem(canvas);
	lws.setContents(getTestBench());
	shell.setSize(800, 500);
	testGetBeanInfo();
	testWidget();
}
 
Example 7
Source File: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void adjustItemNumber() {
	if (fComposite == null)
		return;

	Control[] children= fComposite.getChildren();
	int oldSize= children.length;
	int newSize= fInput == null ? 0 : fInput.fAnnotations.length;

	Display display= fShell.getDisplay();

	// add missing items
	for (int i= oldSize; i < newSize; i++) {
		Canvas canvas= new Canvas(fComposite, SWT.NONE);
		Object gridData= fLayouter.getLayoutData();
		canvas.setLayoutData(gridData);
		canvas.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

		canvas.addPaintListener(fPaintListener);

		canvas.addMouseTrackListener(fMouseTrackListener);

		canvas.addMouseListener(fMouseListener);

		canvas.addListener(SWT.MenuDetect, fMenuDetectListener);

		canvas.addDisposeListener(fDisposeListener);
	}

	// dispose of exceeding resources
	for (int i= oldSize; i > newSize; i--) {
		Item item= (Item) children[i - 1].getData();
		item.deselect();
		children[i - 1].dispose();
	}

}
 
Example 8
Source File: SankeyMiniViewAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Control createContents(Composite parent) {
	Composite composite = createForm(parent);
	createScale(composite);
	Canvas canvas = new Canvas(composite, SWT.BORDER);
	canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	LightweightSystem lws = new LightweightSystem(canvas);
	ScrollableThumbnail thumbnail = createThumbnail();
	lws.setContents(thumbnail);
	viewer.getControl().addDisposeListener((e) -> {
		if (!closed)
			close();
	});
	return super.createContents(parent);
}
 
Example 9
Source File: AbstractAnnotationHover.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void createAnnotationInformation(Composite parent, final Annotation annotation) {
	Composite composite= new Composite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
	GridLayout layout= new GridLayout(2, false);
	layout.marginHeight= 2;
	layout.marginWidth= 2;
	layout.horizontalSpacing= 0;
	composite.setLayout(layout);

	final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS);
	GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
	gridData.widthHint= 17;
	gridData.heightHint= 16;
	canvas.setLayoutData(gridData);
	canvas.addPaintListener(new PaintListener() {
		@Override
		public void paintControl(PaintEvent e) {
			e.gc.setFont(null);
			fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
		}
	});

	StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
	GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
	text.setLayoutData(data);
	String annotationText= annotation.getText();
	if (annotationText != null)
		text.setText(annotationText);
}
 
Example 10
Source File: TaskFormatChart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected Composite createTitleArea( Composite parent )
{
	Composite cmpTitle = super.createTitleArea( parent );
	// ( (GridData) cmpTitle.getLayoutData( ) ).heightHint = 250;

	previewCanvas = new Canvas( cmpTitle, SWT.BORDER );
	{
		GridData gd = new GridData( GridData.FILL_BOTH );
		gd.horizontalSpan = 2;
		previewCanvas.setLayoutData( gd );
		previewCanvas.setBackground( Display.getDefault( )
				.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
	}
	return cmpTitle;
}
 
Example 11
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
protected void createPopupControl() {
	// overall panel
	final Shell top = getPopup();
	final GridLayout layout = new GridLayout(3, true);
	layout.horizontalSpacing = 0;
	layout.verticalSpacing = 0;
	layout.marginWidth = 5;
	layout.marginHeight = 5;
	top.setLayout(layout);
	top.setBackground(IGamaColors.BLACK.color());
	if (createExtraInfo) {
		// left overlay info
		left = label(top, SWT.LEFT);
		// center overlay info
		center = label(top, SWT.CENTER);
		// right overlay info
		right = label(top, SWT.RIGHT);
	}
	// coordinates overlay info
	coord = label(top, SWT.LEFT);
	// zoom overlay info
	zoom = label(top, SWT.CENTER);
	// scalebar overlay info
	scalebar = new Canvas(top, SWT.None);
	scalebar.setVisible(true);
	final GridData scaleData = new GridData(SWT.RIGHT, SWT.CENTER, true, false);
	scaleData.minimumWidth = 140;
	scaleData.widthHint = 140;
	scaleData.minimumHeight = 24;
	scaleData.heightHint = 24;
	scalebar.setLayoutData(scaleData);
	scalebar.setBackground(IGamaColors.BLACK.color());
	scalebar.addPaintListener(e -> paintScale(e.gc));
	top.addMouseListener(toggleListener);
	scalebar.addMouseListener(toggleListener);
	top.layout();
}
 
Example 12
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 5 votes vote down vote up
private void createAnnotationInformation(Composite parent, final Annotation annotation) {
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
	GridLayout layout = new GridLayout(2, false);
	layout.marginHeight = 2;
	layout.marginWidth = 2;
	layout.horizontalSpacing = 0;
	composite.setLayout(layout);

	final Canvas canvas = new Canvas(composite, SWT.NO_FOCUS);
	GridData gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
	gridData.widthHint = 17;
	gridData.heightHint = 16;
	canvas.setLayoutData(gridData);
	canvas.addPaintListener(new PaintListener() {

		@Override
		public void paintControl(PaintEvent e) {
			e.gc.setFont(null);
			fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
		}
	});

	StyledText text = new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
	GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
	text.setLayoutData(data);
	String annotationText = annotation.getText();
	if (annotationText != null)
		text.setText(annotationText);
}
 
Example 13
Source File: AnnotationWithQuickFixesHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void createAnnotationInformation(Composite parent, final Annotation annotation) {
	Composite composite= new Composite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
	GridLayout layout= new GridLayout(2, false);
	layout.marginHeight= 2;
	layout.marginWidth= 2;
	layout.horizontalSpacing= 0;
	composite.setLayout(layout);

	final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS);
	GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
	gridData.widthHint= 17;
	gridData.heightHint= 16;
	canvas.setLayoutData(gridData);
	canvas.addPaintListener(new PaintListener() {
		@Override
		public void paintControl(PaintEvent e) {
			e.gc.setFont(null);
			fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16));
		}
	});

	StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
	GridData data= new GridData(SWT.FILL, SWT.FILL, true, true);
	text.setLayoutData(data);
	String annotationText= annotation.getText();
	if (annotationText != null)
		text.setText(annotationText);
}
 
Example 14
Source File: HeapManager.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the bar that displays the memory
 */
private void createBar() {
	bar = new Canvas(this, SWT.NONE);
	final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, false);
	gd.minimumWidth = 100;
	gd.heightHint = 30;
	bar.setLayoutData(gd);
	heapMaxSize = (int) (Runtime.getRuntime().maxMemory() / (1024 * 1024));
	bar.addPaintListener(e -> {
		drawBar(e);
	});
}
 
Example 15
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Build the image on top of the login box. If no image has been set, create
 * a default image
 */
private void buildImage() {
	final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
	final GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false, 4, 1);
	gridData.widthHint = 400;
	gridData.heightHint = 60;
	canvas.setLayoutData(gridData);
	canvas.addPaintListener(e -> {
		e.gc.drawImage(image == null ? createDefaultImage(e.width, e.height) : image, 0, 0);
	});

}
 
Example 16
Source File: StarModelDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void addModelTab() {
  wModelTab = new CTabItem(wTabFolder, SWT.NONE);
  wModelTab.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelTab.Label"));

  Composite wModelComp = new Composite(wTabFolder, SWT.NONE);
  props.setLook(wModelComp);

  FormLayout transLayout = new FormLayout();
  transLayout.marginWidth = Const.MARGIN;
  transLayout.marginHeight = Const.MARGIN;
  wModelComp.setLayout(transLayout);

  // Model name:
  //
  Label wlModelName = new Label(wModelComp, SWT.RIGHT);
  wlModelName.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelName.Label"));
  props.setLook(wlModelName);
  FormData fdlJobname = new FormData();
  fdlJobname.left = new FormAttachment(0, 0);
  fdlJobname.right = new FormAttachment(middle, -margin);
  fdlJobname.top = new FormAttachment(0, margin);
  wlModelName.setLayoutData(fdlJobname);
  wModelName = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
  props.setLook(wModelName);
  FormData fdJobname = new FormData();
  fdJobname.left = new FormAttachment(middle, 0);
  fdJobname.top = new FormAttachment(0, margin);
  fdJobname.right = new FormAttachment(100, 0);
  wModelName.setLayoutData(fdJobname);
  Control lastControl = wModelName;

  // Model description
  //
  Label wlModelDescription = new Label(wModelComp, SWT.RIGHT);
  wlModelDescription.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelDescription.Label"));
  props.setLook(wlModelDescription);
  FormData fdlJobFilename = new FormData();
  fdlJobFilename.left = new FormAttachment(0, 0);
  fdlJobFilename.right = new FormAttachment(middle, -margin);
  fdlJobFilename.top = new FormAttachment(lastControl, margin);
  wlModelDescription.setLayoutData(fdlJobFilename);
  wModelDescription = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
  props.setLook(wModelDescription);
  FormData fdJobFilename = new FormData();
  fdJobFilename.left = new FormAttachment(middle, 0);
  fdJobFilename.top = new FormAttachment(lastControl, margin);
  fdJobFilename.right = new FormAttachment(100, 0);
  wModelDescription.setLayoutData(fdJobFilename);
  lastControl = wModelDescription;

  canvas = new Canvas(wModelComp, SWT.BORDER);
  FormData fdCanvas = new FormData();
  fdCanvas.left = new FormAttachment(0,0);
  fdCanvas.right = new FormAttachment(100, 0);
  fdCanvas.top = new FormAttachment(lastControl, 3*margin);
  fdCanvas.bottom = new FormAttachment(100, -margin);
  canvas.setLayoutData(fdCanvas);
  canvas.addPaintListener(new PaintListener() {
    @Override
    public void paintControl(PaintEvent paintEvent) {
      drawLogicalModel(logicalModel, canvas, paintEvent);
    }
  });


  FormData fdModelComp = new FormData();
  fdModelComp.left = new FormAttachment(0, 0);
  fdModelComp.top = new FormAttachment(0, 0);
  fdModelComp.right = new FormAttachment(100, 0);
  fdModelComp.bottom = new FormAttachment(100, 0);

  wModelComp.setLayoutData(fdModelComp);
  wModelTab.setControl(wModelComp);
}
 
Example 17
Source File: Histogram.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private Composite createWidget(final Composite parent) {

        fFont = adjustFont(parent);

        // --------------------------------------------------------------------
        // Define the histogram
        // --------------------------------------------------------------------

        final Composite composite = new Composite(parent, SWT.FILL);
        composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());

        // Use all the horizontal space
        composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

        // Y-axis max event
        fMaxNbEventsLabel = new Label(composite, SWT.RIGHT);
        fMaxNbEventsLabel.setFont(fFont);
        fMaxNbEventsLabel.setText("0"); //$NON-NLS-1$
        fMaxNbEventsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.TOP).create());

        // Histogram itself
        Composite canvasComposite = new Composite(composite, SWT.BORDER);
        canvasComposite.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create());
        canvasComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(1, 1).create());
        fCanvas = new Canvas(canvasComposite, SWT.DOUBLE_BUFFERED);
        fCanvas.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
        fCanvas.addDisposeListener(e -> {
            Object image = fCanvas.getData(IMAGE_KEY);
            if (image instanceof Image) {
                ((Image) image).dispose();
            }
        });

        fTimeLineScale = new TimeGraphScale(canvasComposite, fColorScheme, SWT.BOTTOM);
        fTimeLineScale.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
        fTimeLineScale.setHeight(TIME_SCALE_HEIGHT);
        fTimeLineScale.setTimeProvider(new HistogramTimeAdapter(fDataModel));

        updateTimeFormat();

        return composite;
    }
 
Example 18
Source File: GraphModelDialog.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 4 votes vote down vote up
private void addGraphTab() {

    CTabItem wGraphTab = new CTabItem( wTabs, SWT.NONE );
    wGraphTab.setText( "Graph" );

    ScrolledComposite wGraphSComp = new ScrolledComposite( wTabs, SWT.V_SCROLL | SWT.H_SCROLL );
    wGraphSComp.setLayout( new FillLayout() );

    Composite wGraphComp = new Composite( wGraphSComp, SWT.NONE );
    props.setLook( wGraphComp );

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 3;
    formLayout.marginHeight = 3;
    wGraphComp.setLayout( formLayout );

    Button wAuto = new Button( wGraphComp, SWT.PUSH );
    wAuto.setText( "Auto" );
    FormData fdAuto = new FormData();
    fdAuto.right = new FormAttachment( 100, 0 );
    fdAuto.bottom = new FormAttachment( 100, 0 );
    wAuto.setLayoutData( fdAuto );
    wAuto.addListener( SWT.Selection, this::autoModelLayout );

    // This is the canvas on which we draw the graph
    //
    wCanvas = new Canvas( wGraphComp, SWT.NONE );
    props.setLook( wCanvas );
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment( 0, 0 );
    fdCanvas.right = new FormAttachment( 100, 0 );
    fdCanvas.top = new FormAttachment( 0, 0 );
    fdCanvas.bottom = new FormAttachment( 100, 0 );
    wCanvas.setLayoutData( fdCanvas );
    wCanvas.addPaintListener( this::paintCanvas );
    wCanvas.addListener( SWT.MouseDown, this::graphMouseDown );
    wCanvas.addListener( SWT.MouseUp, this::graphMouseUp );
    wCanvas.addListener( SWT.MouseMove, this::moveGraphObject );
    wCanvas.addListener( SWT.MouseDoubleClick, this::editGraphObject );

    FormData fdGraphComp = new FormData();
    fdGraphComp.left = new FormAttachment( 0, 0 );
    fdGraphComp.top = new FormAttachment( 0, 0 );
    fdGraphComp.right = new FormAttachment( 100, 0 );
    fdGraphComp.bottom = new FormAttachment( wAuto, -margin );
    wGraphComp.setLayoutData( fdGraphComp );

    wGraphComp.pack();

    Rectangle bounds = wGraphComp.getBounds();

    wGraphSComp.setContent( wGraphComp );
    wGraphSComp.setExpandHorizontal( true );
    wGraphSComp.setExpandVertical( true );
    wGraphSComp.setMinWidth( bounds.width );
    wGraphSComp.setMinHeight( bounds.height );

    wGraphTab.setControl( wGraphSComp );
  }
 
Example 19
Source File: OpenMiniatureViewAction.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected Control createContents(final Composite parent) {
	FormToolkit toolkit = new FormToolkit(Display.getCurrent());
	ScrolledForm scrolledForm = toolkit.createScrolledForm(parent);
	Composite body = scrolledForm.getBody();
	body.setLayout(new FillLayout());
	toolkit.paintBordersFor(body);

	SashForm sashForm = new SashForm(body, SWT.VERTICAL);
	toolkit.adapt(sashForm, true, true);

	Section categorySection = toolkit
			.createSection(sashForm, ExpandableComposite.NO_TITLE
					| ExpandableComposite.EXPANDED);
	categorySection.setText("");
	Composite composite = toolkit.createComposite(categorySection,
			SWT.NONE);
	composite.setLayout(new GridLayout());
	categorySection.setClient(composite);
	toolkit.paintBordersFor(composite);
	final Scale scale = new Scale(composite, SWT.NONE);
	scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
	final double[] values = GraphConfig.ZOOM_LEVELS;
	final int increment = 100 / (values.length - 1);
	scale.setIncrement(increment);
	scale.setMinimum(0);
	scale.setMaximum(100);
	Controls.onSelect(scale, (e) -> {
		zoomManager.setZoom(values[scale.getSelection() / increment]);
	});
	scale.setSelection(increment * (values.length - 1) / 2);
	Canvas canvas = new Canvas(composite, SWT.BORDER);
	canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	lws = new LightweightSystem(canvas);
	thumbnail = new ScrollableThumbnail(port);
	thumbnail.setSource(figure);
	lws.setContents(thumbnail);
	disposeListener = new DisposeListener() {

		@Override
		public void widgetDisposed(final DisposeEvent e) {
			if (thumbnail != null) {
				thumbnail.deactivate();
				thumbnail = null;
			}
			if (control != null && !control.isDisposed())
				control.removeDisposeListener(disposeListener);
			close();
		}
	};
	control.addDisposeListener(disposeListener);
	return super.createContents(parent);
}
 
Example 20
Source File: TransitionTest2.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void init() {
    final TransitionTest2 me = this;
    
    _containerComposite.setLayout(new FormLayout());
    //_containerComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    
    imgs = new Image[6];
    for(int i = 0; i < imgs.length; i++)
        imgs[i] = new Image(_containerComposite.getDisplay(), getClass().getResourceAsStream(new Formatter().format("%02d.jpg", i+1).toString()));
    
    final Canvas cnvs = new Canvas(_containerComposite, SWT.DOUBLE_BUFFERED);
    cnvs.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 5);
    fd.right = new FormAttachment(100, -5);
    fd.top = new FormAttachment(0, 5);
    fd.bottom = new FormAttachment(100, -35);
    cnvs.setLayoutData(fd);
    
    final Button btn = new Button(_containerComposite, SWT.PUSH);
    btn.setText("Hit me!");
    fd = new FormData();
    fd.top = new FormAttachment(cnvs, 5);
    fd.bottom = new FormAttachment(100, -5);
    fd.left = new FormAttachment(0, 5);
    fd.right = new FormAttachment(100, -5);
    btn.setLayoutData(fd);
    
    _tm = new TransitionManager(new ImageTransitionable() {
        public void setSelection(int index) {
            me.curImg = index;
        }
    
        public int getSelection() {
            return me.curImg;
        }
    
        public Control getControl(int index) {
            return cnvs;
        }
    
        public Composite getComposite() {
            return _containerComposite;
        }
    
        public double getDirection(int toIndex, int fromIndex) {
            return getSelectedDirection(toIndex, fromIndex);
        }
    
        public void addSelectionListener(SelectionListener listener) {
            final SelectionListener transitionableListener = listener;
            btn.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    me.curImg = (me.curImg + 1) % me.imgs.length;
                    transitionableListener.widgetSelected(e);
                }
            });
        }
    });
    _tm.setControlImages(imgs);
    
    cnvs.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            Image img = me.imgs[me.curImg];
            e.gc.drawImage(
                    img
                    , 0
                    , 0
                    , img.getImageData().width
                    , img.getImageData().height
                    , 0
                    , 0
                    , cnvs.getSize().x
                    , cnvs.getSize().y
                    );
        }
    });
    
}