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

The following examples show how to use org.eclipse.swt.widgets.Canvas#addPaintListener() . 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: DarkPanel.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Show the dark panel
 */
public void show() {
	if (parent.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	panel = new Shell(parent, SWT.APPLICATION_MODAL | SWT.NO_TRIM);
	panel.setLayout(new FillLayout());
	panel.setAlpha(alpha);

	panel.addListener(SWT.KeyUp, event -> {
		event.doit = false;
	});

	canvas = new Canvas(panel, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
	canvas.addPaintListener(event -> {
		paintCanvas(event);
	});

	panel.setBounds(panel.getDisplay().map(parent, null, parent.getClientArea()));
	panel.open();
}
 
Example 2
Source File: BlurredPanel.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Show the blurred panel
 */
public void show() {
	if (parent.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	panel = new Shell(parent, SWT.APPLICATION_MODAL | SWT.NO_TRIM);
	panel.setLayout(new FillLayout());

	panel.addListener(SWT.KeyUp, event -> {
		event.doit = false;
	});

	canvas = new Canvas(panel, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
	canvas.addPaintListener(event -> {
		paintCanvas(event);
	});

	panel.setBounds(panel.getDisplay().map(parent, null, parent.getClientArea()));
	panel.open();

}
 
Example 3
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 4
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 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: GraphicalViewer.java    From eclipsegraphviz with Eclipse Public License 1.0 6 votes vote down vote up
public GraphicalViewer(Composite parent) {
    canvas = new Canvas(parent, SWT.NONE);
    parent.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            canvas.setBounds(canvas.getParent().getClientArea());
            requestImageRedraw();
        }
    });
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            redrawImageIfRequested();
            GC gc = e.gc;
            paintCanvas(gc);
        }

    });
}
 
Example 7
Source File: ChartView.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
private void setUpDrawing(Composite parent) {
	paintCanvas = new Canvas(parent, SWT.BACKGROUND);
	preview = new ChartPreview();
	paintCanvas.addPaintListener(preview);
	paintCanvas.addControlListener(preview);
	preview.setPreview(paintCanvas);
	preview.setDataPresent(false);
	preview.setTextToShow(noDataToDisplay);
}
 
Example 8
Source File: DecisionTableWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param parent
 * @param image
 * @return
 */
public Canvas createImageButton(final Composite parent, final Image image) {
    final Canvas deleteButton = new Canvas(parent, SWT.TRANSPARENT);
    deleteButton.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent e) {
            e.gc.drawImage(image, 0, 0, 16, 16, 0, 0, DELETE_SIZE, DELETE_SIZE);
        }
    });
    return deleteButton;
}
 
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: CheckBoxCellEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * As soon as the editor is activated, flip the current data value and commit it.<br/>
 * The repaint will pick up the new value and flip the image.
 */
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
	setCanonicalValue(originalCanonicalValue);

	checked = !checked;

	canvas = new Canvas(parent, SWT.NONE);

	canvas.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent paintEvent) {
			Rectangle bounds = canvas.getBounds();
			Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height);
			checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked);
		}

	});

	canvas.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseUp(MouseEvent e) {
			checked = !checked;
			canvas.redraw();
		}

	});

	commit(MoveDirectionEnum.NONE, false);

	return canvas;
}
 
Example 11
Source File: CheckBoxCellEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * As soon as the editor is activated, flip the current data value and commit it.<br/>
 * The repaint will pick up the new value and flip the image.
 */
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
	setCanonicalValue(originalCanonicalValue);

	checked = !checked;

	canvas = new Canvas(parent, SWT.NONE);

	canvas.addPaintListener(new PaintListener() {
		public void paintControl(PaintEvent paintEvent) {
			Rectangle bounds = canvas.getBounds();
			Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height);
			checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked);
		}

	});

	canvas.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseUp(MouseEvent e) {
			checked = !checked;
			canvas.redraw();
		}

	});

	commit(MoveDirectionEnum.NONE, false);

	return canvas;
}
 
Example 12
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion 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() {
		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: 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 14
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 15
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 16
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 17
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 18
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 19
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
                    );
        }
    });
    
}
 
Example 20
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 );
  }