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

The following examples show how to use org.eclipse.swt.widgets.Canvas#setBackground() . 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: TimelineComposite.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public TimelineComposite(Composite parent, int style) {
	super(parent, style);

	fResourceManager = new LocalResourceManager(JFaceResources.getResources(), this);

	final FillLayout layout = new FillLayout();
	layout.marginHeight = 10;
	layout.marginWidth = 10;
	setLayout(layout);

	setBackground(ColorConstants.black);

	final Canvas canvas = new Canvas(this, SWT.DOUBLE_BUFFERED);
	canvas.setBackground(ColorConstants.black);
	final LightweightSystem lightWeightSystem = new LightweightSystem(canvas);

	fRootFigure = new RootFigure(fResourceManager);
	fRootFigure.setFont(parent.getFont());
	lightWeightSystem.setContents(fRootFigure);

	// draw2d does not directly support mouseWheelEvents, so register on canvas
	canvas.addMouseWheelListener(new TimelineScaler(this));
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
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
                    );
        }
    });
    
}