Java Code Examples for org.eclipse.swt.events.PaintListener

The following examples show how to use org.eclipse.swt.events.PaintListener. These examples are extracted from open source projects. 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 Project: openstock   Source File: SWTStrokeCanvas.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 2
Source Project: nebula   Source File: HeaderLayout.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void layout(final Composite child, boolean flushCache) {
    storeHeader(child);
    
    int childWidth = child.getSize().x;
    int shellWidth = child.getShell().getSize().x;
    
    if (childWidth == lastChildWidth && shellWidth > lastShellWidth) return;
    
    if (childWidth > lastChildWidth) {
        final Table headerTable = getHeader(child).headerTable;
        headerTable.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                headerTable.removePaintListener(this);
                layout(child);
            }
        });
    } else {
        layout(child);
    }
    lastChildWidth = childWidth;
    lastShellWidth = shellWidth;
}
 
Example 3
Source Project: nebula   Source File: GeoMap.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Removes listener from appropriate listener lists depending on the listener
 * interfaces that are implemented.
 * 
 * @param listener
 *            the listener
 */
public void removeMouseHandler(EventListener listener) {
	if (listener instanceof MouseListener) {
		removeMouseListener((MouseListener) listener);
	}
	if (listener instanceof MouseMoveListener) {
		removeMouseMoveListener((MouseMoveListener) listener);
	}
	if (listener instanceof MouseTrackListener) {
		removeMouseTrackListener((MouseTrackListener) listener);
	}
	if (listener instanceof MouseWheelListener) {
		removeMouseWheelListener((MouseWheelListener) listener);
	}
	if (listener instanceof PaintListener) {
		removePaintListener((PaintListener) listener);
	}
}
 
Example 4
Source Project: nebula   Source File: RichTextViewer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 
 * @param parent
 * @param style
 *            The style bits to use.
 * 
 * @see SWT#WRAP
 */
public RichTextViewer(Composite parent, int style) {
	super(parent, style | SWT.DOUBLE_BUFFERED);

	final boolean wordWrap = (getStyle() & SWT.WRAP) != 0;
	this.painter = new RichTextPainter(wordWrap);

	addPaintListener(new PaintListener() {

		@Override
		public void paintControl(PaintEvent e) {
			painter.paintHTML(htmlText != null ? htmlText : "", e.gc, getClientArea());
		}
	});

}
 
Example 5
Source Project: BiglyBT   Source File: SWTBGImagePainter2.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
	Display display = Display.getDefault();
	Shell shell = new Shell(display, SWT.DIALOG_TRIM);
	shell.setLayout(new FillLayout());

	Composite c = new Composite(shell, SWT.BORDER);
	c.setLayout(new FillLayout());
	c.addPaintListener(new PaintListener() {
		@Override
		public void paintControl(PaintEvent e) {
			e.gc.drawLine(0, 0, 100, 50);
		}
	});

	Label lbl = new Label(c, SWT.NONE);
	lbl.setText("text");

	shell.open();

	while (!shell.isDisposed()) {
		if (display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 6
Source Project: BiglyBT   Source File: PingGraphic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(Canvas canvas) {
	super.initialize(canvas);

	drawCanvas.addPaintListener(new PaintListener() {
	@Override
	public void paintControl(PaintEvent e) {
		if (bufferImage != null && !bufferImage.isDisposed()) {
			Rectangle bounds = bufferImage.getBounds();
			if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

				e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y,
						e.width, e.height);
			}
		}
	}
});

	drawCanvas.addListener(SWT.Resize, new Listener() {
	@Override
	public void handleEvent(Event event) {
		drawChart(true);
	}
});
}
 
Example 7
Source Project: BiglyBT   Source File: SpeedGraphic.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(Canvas canvas) {
	super.initialize(canvas);

	drawCanvas.addPaintListener(new PaintListener() {
	@Override
	public void paintControl(PaintEvent e) {
		if (bufferImage != null && !bufferImage.isDisposed()) {
			Rectangle bounds = bufferImage.getBounds();
			if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

				e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y,
						e.width, e.height);
			}
		}
	}
});

	drawCanvas.addListener(SWT.Resize, new Listener() {
	@Override
	public void handleEvent(Event event) {
		drawChart(true);
	}
});
}
 
Example 8
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 9
Source Project: http4e   Source File: CustomSeparator.java    License: Apache License 2.0 6 votes vote down vote up
public CustomSeparator( Composite parent, int style) {
   super(parent, style = checkStyle(style));

   this.style = style;

   if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0)
      lineSize = 2;
   else
      lineSize = 1;

   addPaintListener(new PaintListener() {
      public void paintControl( PaintEvent event){
         onPaint(event);
      }
   });
}
 
Example 10
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 11
Source Project: SIMVA-SoS   Source File: SWTStrokeCanvas.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 12
Source Project: tracecompass   Source File: BaseMouseProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Method to register the provider to chart viewer.
 */
protected void register() {
    IPlotArea plotArea = getChart().getPlotArea();
    Control control = plotArea.getControl();
    if (this instanceof MouseListener) {
        control.addMouseListener((MouseListener) this);
    }
    if (this instanceof MouseMoveListener) {
        control.addMouseMoveListener((MouseMoveListener) this);
    }
    if (this instanceof MouseWheelListener) {
        control.addMouseWheelListener((MouseWheelListener) this);
    }
    if (this instanceof MouseTrackListener) {
        control.addMouseTrackListener((MouseTrackListener) this);
    }
    if (this instanceof ICustomPaintListener) {
        plotArea.addCustomPaintListener((ICustomPaintListener) this);
    } else if (this instanceof PaintListener) {
        control.addPaintListener((PaintListener) this);
    }
    TmfAbstractToolTipHandler tooltipHandler = getTooltipHandler();
    if(tooltipHandler != null) {
        tooltipHandler.activateHoverHelp(control);
    }
}
 
Example 13
protected void highlight(final Composite parent, final Label labelControl, final Combo comboBox, final int color) {
	Object data= labelControl.getData();
	if (data == null) {
		if (color != HIGHLIGHT_NONE) {
			PaintListener painter= new HighlightPainter(parent, labelControl, comboBox, color);
			parent.addPaintListener(painter);
			labelControl.setData(painter);
		} else {
			return;
		}
	} else {
		if (color == HIGHLIGHT_NONE) {
			parent.removePaintListener((PaintListener) data);
			labelControl.setData(null);
		} else if (color != ((HighlightPainter) data).fColor){
			((HighlightPainter) data).fColor= color;
		} else {
			return;
		}
	}
	
	parent.redraw();
}
 
Example 14
Source Project: ECG-Viewer   Source File: SWTStrokeCanvas.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 15
Source Project: astor   Source File: SWTStrokeCanvas.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice());
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 16
Source Project: astor   Source File: SWTStrokeCanvas.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 17
Source Project: eclipsegraphviz   Source File: GraphicalViewer.java    License: 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 18
Source Project: buffer_bci   Source File: SWTStrokeCanvas.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 19
Source Project: arx   Source File: MainSplash.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param display
 * @param monitor
 */
public MainSplash(Display display, Monitor monitor) {
    
    this.version = ARXAnonymizer.VERSION;
    this.splash = Resources.getSplash(display);
    this.shell = new Shell(SWT.ON_TOP | (isMac() ? 0 : SWT.NO_TRIM));
    this.shell.setImages(Resources.getIconSet(display));
    this.shell.setSize(splash.getBounds().width, splash.getBounds().height);
    
    // Center
    SWTUtil.center(shell, monitor);
    
    // Paint
    shell.addPaintListener(new PaintListener(){
        public void paintControl(PaintEvent arg0) {
            paint(arg0.gc);
        }
    });
}
 
Example 20
Source Project: openstock   Source File: SWTPaintCanvas.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTPaintCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.gc.getDevice().getSystemColor(
                    SWT.COLOR_BLACK));
            e.gc.setBackground(SWTPaintCanvas.this.myColor);
            e.gc.fillRectangle(getClientArea());
            e.gc.drawRectangle(getClientArea().x, getClientArea().y, 
                    getClientArea().width - 1, getClientArea().height - 1);
        }
    });
}
 
Example 21
Source Project: arx   Source File: MainWindow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Executes the given runnable on show.
 *
 * @param runnable
 */
public void onShow(final Runnable runnable){
    
    // Using a paint listener is a hack to reliably determine when the shell is visible
    shell.addPaintListener(new PaintListener(){
        @Override
        public void paintControl(PaintEvent arg0) {
            shell.removePaintListener(this);
            display.timerExec(200, runnable);
        }
    });
}
 
Example 22
Source Project: BiglyBT   Source File: TransferStatsView.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected
zoneView(
 SpeedManagerPingMapper		_mapper,
 Canvas 						_canvas,
 String[]						_labels,
 ValueFormater[]				_formatters )
{
 mapper		= _mapper;
 canvas		= _canvas;
 labels		= _labels;
 formatters	= _formatters;

 canvas.addPaintListener(new PaintListener() {
	@Override
	public void paintControl(PaintEvent e) {
		if (buffer_image != null && !buffer_image.isDisposed()) {
			Rectangle bounds = buffer_image.getBounds();
			if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

				e.gc.drawImage(buffer_image, e.x, e.y, e.width, e.height, e.x, e.y,
						e.width, e.height);
			}
		}
	}
});

 canvas.addListener(SWT.Resize, new Listener() {
	@Override
	public void handleEvent(Event event) {
		refresh(true);
	}
});
 COConfigurationManager.addAndFireParameterListener( "Graphics Update", this );
}
 
Example 23
Source Project: BiglyBT   Source File: MultiPlotGraphic.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void
initialize(
	Canvas 	canvas,
	boolean	is_active )
{
  	super.initialize(canvas);

  	drawCanvas.addPaintListener(new PaintListener() {
			@Override
			public void paintControl(PaintEvent e) {
				if (bufferImage != null && !bufferImage.isDisposed()) {
					Rectangle bounds = bufferImage.getBounds();
					if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

						e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
					}
				}
			}
		});

  	drawCanvas.addListener(SWT.Resize, new Listener() {
			@Override
			public void handleEvent(Event event) {
				drawChart(true);
			}
		});

  	setActive( is_active );
}
 
Example 24
Source Project: ccu-historian   Source File: SWTPaintCanvas.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTPaintCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.gc.getDevice().getSystemColor(
                    SWT.COLOR_BLACK));
            e.gc.setBackground(SWTPaintCanvas.this.myColor);
            e.gc.fillRectangle(getClientArea());
            e.gc.drawRectangle(getClientArea().x, getClientArea().y, 
                    getClientArea().width - 1, getClientArea().height - 1);
        }
    });
}
 
Example 25
Source Project: http4e   Source File: AnimatedGIFRunner.java    License: Apache License 2.0 5 votes vote down vote up
AnimatedGIFRunner(
      Control control, 
      ImageLoader imageLoaderGIF, 
      final Image backgroundImage){
   
   this.control = control;
   controlGC = new GC(control);
   shellBackground = control.getBackground();
   this.imageLoader = imageLoaderGIF;
   this.imageDataArray = imageLoader.data;
   if(imageDataArray == null || imageDataArray.length < 2){
      throw new RuntimeException("Illegal ImageLoader.");
   }
   isStopped = false;
   this.backgroundImage = backgroundImage;
   Rectangle ctrR = control.getBounds();
   positionX = (ctrR.width - CoreConstants.IMAGES_HEIGHT)/2;
   positionY = (ctrR.height - CoreConstants.IMAGES_HEIGHT)/2;

   control.addPaintListener(new PaintListener() {
      public void paintControl( PaintEvent e){
         GC graphics = e.gc;
         if(!graphics.isDisposed()) {
            graphics.drawImage(backgroundImage, positionX, positionY);
            graphics.dispose();
         }
      }
   });
}
 
Example 26
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 27
Source Project: texlipse   Source File: TexInformationControl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a composites which contains an image of the command
 */
private void createImageComp() {
    this.imageComposite = new Composite(shell, SWT.NONE);
    imageComposite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    imageComposite.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            try {
                GC gc = e.gc;
                gc.drawRectangle(0, 0, e.width - 1, e.height - 1);
                if (hasImage) {
                    gc.drawImage(image, 2, 2);
                }
            } catch (Exception ex) {
                TexlipsePlugin.log("TexInformationControl: ", ex);
            }
        }
    });
    GridData data = new GridData();
    data.grabExcessHorizontalSpace = false;
    data.grabExcessVerticalSpace = false;
    data.verticalAlignment = SWT.TOP;
    if (image != null) {
        data.widthHint = image.getBounds().width + 4;
        data.heightHint = image.getBounds().height + 4;
    }
    imageComposite.setLayoutData(data);
    imageComposite.pack();
}
 
Example 28
Source Project: SIMVA-SoS   Source File: SWTPaintCanvas.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTPaintCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.gc.getDevice().getSystemColor(
                    SWT.COLOR_BLACK));
            e.gc.setBackground(SWTPaintCanvas.this.myColor);
            e.gc.fillRectangle(getClientArea());
            e.gc.drawRectangle(getClientArea().x, getClientArea().y, 
                    getClientArea().width - 1, getClientArea().height - 1);
        }
    });
}
 
Example 29
Source Project: typescript.java   Source File: AbstractAnnotationHover.java    License: 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 30
Source Project: tracecompass   Source File: ScrollView.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Remove the local Listener and add the new listener.
 *
 * @param nlistener the new listener
 */
public void replacePaintListener(PaintListener nlistener) {
    if (fLocalPaintListener != null) {
        removePaintListener(fLocalPaintListener);
        fLocalPaintListener = null;
    }
    fViewControl.addPaintListener(nlistener);
}