/** * 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); } } }); }
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(); } } }
/** * Create a new Piccolo2D SWT benchmarking test suite with the specified parent and style. * * @param parent parent * @param style style */ private SWTBenchTest(final Composite parent, final int style) { super(parent, style); testImageOpaque = loadImage(getDisplay(), "opaque.jpg"); testImageBitmask = loadImage(getDisplay(), "bitmask.gif"); testImageTranslucent = loadImage(getDisplay(), "translucent.png"); testImageARGB = new Image(getDisplay(), 128, 128); final GC tmpGC = new GC(testImageARGB); tmpGC.drawImage(testImageTranslucent, 0, 0); tmpGC.dispose(); addPaintListener(new PaintListener() { public void paintControl(final PaintEvent pe) { runAll(new SWTGraphics2D(pe.gc, getDisplay())); } }); }
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); } }); }
public void init() { if(TuxGuitar.getInstance().getConfig().getBooleanValue(TGConfigKeys.SHOW_SPLASH)){ final Image image = TuxGuitar.getInstance().getIconManager().getAppSplash(); this.shell = new Shell(TuxGuitar.getInstance().getDisplay(), SWT.NO_TRIM | SWT.NO_BACKGROUND); this.shell.setLayout(new FillLayout()); this.shell.setBounds(getBounds(image)); this.shell.setImage(TuxGuitar.getInstance().getIconManager().getAppIcon()); this.shell.setText(TuxGuitar.APPLICATION_NAME); this.shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { TGPainter painter = new TGPainterImpl(e.gc); painter.drawImage(new TGImageImpl(image), 0, 0); } }); this.shell.open(); this.shell.redraw(); this.shell.update(); } }
public void init() { this.setLayout(new GridLayout(1,true)); this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); ((GridData)this.getLayoutData()).widthHint = 600; this.composite = new Composite(this,SWT.BORDER | SWT.DOUBLE_BUFFERED); this.composite.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE)); this.composite.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { TGPainterImpl painter = new TGPainterImpl(e.gc); TGTunerRoughWidget.this.paintWidget(painter); } }); GridData data = new GridData(SWT.FILL,SWT.FILL,true,true); data.minimumHeight = MIN_HEIGHT; data.grabExcessHorizontalSpace = true; this.composite.setLayoutData(data); }
/** * Create contents of the shell. */ protected void createContents() { setText("SWT Application"); setSize(673, 173); windowLocation.showWindowOnScreenCenter(this); addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { // TODO Auto-generated method stub e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); e.gc.drawString(infotext, 20, getSize().y-20,true); } }); }
public RotatedLabel(Composite parent, int style) { super(parent, style); this.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { paint(e); } }); this.addListener(SWT.MouseDown, new Listener() { @Override public void handleEvent(Event event) { if (switchListener != null && !isDefinitionSectionExpanded) switchListener.handleSelection(); } }); }
public void createPartControl(Composite parent) { setTitleImage(Images.TYPE_ACTSPEED); canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { try { area = canvas.getClientArea(); drawCanvasImage(e.gc); } catch (Throwable t) { t.printStackTrace(); } } }); window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); }
private Composite createUI_20_PageShellImage(final Composite parent) { final Canvas resizeCanvas = new Canvas(// parent, // SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE// SWT.NONE // ); resizeCanvas.setLayout(new FillLayout()); // resizeCanvas.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN)); resizeCanvas.addPaintListener(new PaintListener() { @Override public void paintControl(final PaintEvent e) { onPaintShellImage(e); } }); return resizeCanvas; }
public CanvasImpl( final IGenericWidgetFactory factory, final Object parentUiReference, final ICanvasSetupSpi setup, final SwtImageRegistry imageRegistry) { super(factory, new Canvas((Composite) parentUiReference, getStyle(setup)), imageRegistry); getUiReference().setBackgroundMode(SWT.INHERIT_DEFAULT); this.paintObservable = new PaintObservable(); getUiReference().addPaintListener(new PaintListener() { @Override public void paintControl(final PaintEvent e) { final Dimension size = getSize(); final Rectangle bounds = new Rectangle(0, 0, size.getWidth(), size.getHeight()); final Rectangle clipBounds = new Rectangle(e.x, e.y, e.width, e.height); final GraphicContextSpiImpl graphicContext = new GraphicContextSpiImpl(e.gc, bounds, imageRegistry); paintObservable.firePaint(new PaintEventSpiImpl(graphicContext, clipBounds)); } }); }
/** * Constructor * * @param parent Parent * @param style Style flags */ public SpinnerProgress(Composite parent, int style) { super(parent, style); // Add paint listener addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { onPaint(e); } }); // Set font setFont(parent.getFont()); // Create spoke colors createColors(getDisplay()); // Compute spoke angles computeSpokeAngles(); }
/** * Constructor * * @param parent Parent * @param image Image to display */ public AnimateControl(Composite parent, int style, Image[] images) { super(parent, style); // Image attributes this.images = images; imageWidth = images[0].getImageData().width; imageHeight = images[0].getImageData().height; // Add paint listener addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { onPaint(e); } }); }
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(); }
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() { 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(); } } }
@Override public void init(Shell splash) { super.init(splash); ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, BETA_PNG); if (descriptor != null) image = descriptor.createImage(); if (image !=null) { final int xposition = splash.getSize().x - image.getImageData().width - 60; final int yposition = BORDER; getContent().addPaintListener (new PaintListener () { public void paintControl (PaintEvent e) { e.gc.drawImage (image, xposition, yposition); } }); } }
Hover(Shell parent) { final Display display = parent.getDisplay(); hoverShell = new Shell(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); hoverShell.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); hoverShell.setForeground(display .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); hoverShell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent pe) { pe.gc.drawText(text, hm, hm); if (!MAC) { pe.gc.drawPolygon(getPolygon(true)); } } }); hoverShell.addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent e) { hideHover(); } }); }
Hover(Shell parent) { final Display display = parent.getDisplay(); hoverShell = new Shell(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); hoverShell.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); hoverShell.setForeground(display .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); hoverShell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent pe) { pe.gc.drawString(text, hm, hm); if (!MAC) { pe.gc.drawPolygon(getPolygon(true)); } } }); hoverShell.addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent e) { hideHover(); } }); }
/** * Create a new plot canvas. * * @param parent parent composite * @param style parent composite style * @param drawAxis * set this to true, if axes are to be drawn. */ public PlotCanvas(Composite parent, int style, boolean drawAxis) { super(parent, style); rootSequence = null; this.drawAxes = drawAxis; if (drawAxes) { yTopMargin = 10; yAxisMargin = 34; xAxisMargin = 40; } setLayoutData(new GridData(SWT.FILL, SWT.CENTER)); addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { paintOnDisplay(e.display, PlotCanvas.this, (PlotCanvas.this).getSize().x, (PlotCanvas.this).getSize().y); } }); }
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(); parent.update(); }
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); } }); }
public HighlightDecorationProvider(TreeViewer tw) { this.treeViewer = tw; this.selectionListener = new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { update(event.getSelection()); } }; this.treeViewer.addSelectionChangedListener(this.selectionListener); this.paintListener = new PaintListener() { @Override public void paintControl(PaintEvent e) { update(treeViewer.getSelection()); } }; this.treeViewer.getTree().addPaintListener(this.paintListener); DecorationManager.addProvider(this); }
@Test @ConditionalIgnore( condition = GtkPlatform.class ) public void runOnVerticalScrollBarSelectionChange() { Table scrollable = createTable( shell, 100, SWT.VIRTUAL ); scrollable.addListener( SWT.MeasureItem, evt -> {} ); StructureScrollableRedrawInsurance redrawInsurance = newRedrawInsurance( scrollable ); PaintListener listener = mock( PaintListener.class ); shell.open(); flushPendingEvents(); trigger( SWT.Selection ).on( scrollable.getVerticalBar() ); flushPendingEvents(); scrollable.addPaintListener( listener ); redrawInsurance.run(); flushPendingEvents(); verify( listener, never() ).paintControl( any( PaintEvent.class ) ); }
@Test @ConditionalIgnore( condition = NonWindowsPlatform.class ) public void runOnVerticalScrollBarPostSelectionChange() { Table scrollable = createTable( shell, 100, SWT.VIRTUAL ); scrollable.addListener( SWT.MeasureItem, evt -> {} ); StructureScrollableRedrawInsurance redrawInsurance = newRedrawInsurance( scrollable ); PaintListener listener = mock( PaintListener.class ); shell.open(); flushPendingEvents(); trigger( SWT.Selection ).on( scrollable.getVerticalBar() ); flushPendingEvents(); scrollable.addPaintListener( listener ); redrawInsurance.run(); flushPendingEvents(); redrawInsurance.run(); flushPendingEvents(); verify( listener ).paintControl( any( PaintEvent.class ) ); }
@Test @ConditionalIgnore( condition = GtkPlatform.class ) public void runOnVerticalScrollBarWithoutSelectionChange() { Table scrollable = createTable( shell, 100, SWT.VIRTUAL ); scrollable.addListener( SWT.MeasureItem, evt -> {} ); StructureScrollableRedrawInsurance redrawInsurance = newRedrawInsurance( scrollable ); PaintListener listener = mock( PaintListener.class ); shell.open(); flushPendingEvents(); scrollable.addPaintListener( listener ); redrawInsurance.run(); flushPendingEvents(); verify( listener, never() ).paintControl( any( PaintEvent.class ) ); }
@Override protected void addMapPaintListener() { getContainer().addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { UiProject currentProject = UiModel.getDefault().getCurrentUiProject(); if (currentProject != null) { getMapDrawer().draw(glContext, currentProject); } else { getMapDrawer().draw(glContext); } getContainer().swapBuffers(); } }); }
public SwtDeviceComponent(Composite parent) { super(parent, SWT.NO_BACKGROUND); instance = this; mousePressed = false; dc = new SwtDisplayComponent(this); this.initialPressedSoftButton = null; addKeyListener(keyListener); addMouseListener(mouseListener); addMouseMoveListener(mouseMoveListener); addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { SwtDeviceComponent.this.paintControl(e); } }); }
public void init() { if(TuxGuitar.instance().getConfig().getBooleanConfigValue(TGConfigKeys.SHOW_SPLASH)){ final Image image = TuxGuitar.instance().getIconManager().getAppSplash(); this.shell = new Shell(TuxGuitar.instance().getDisplay(), SWT.NO_TRIM | SWT.NO_BACKGROUND); this.shell.setLayout(new FillLayout()); this.shell.setBounds(getBounds(image)); this.shell.setImage(TuxGuitar.instance().getIconManager().getAppIcon()); this.shell.setText(TuxGuitar.APPLICATION_NAME); this.shell.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { TGPainter painter = new TGPainter(e.gc); painter.drawImage(image, 0, 0); } }); this.shell.open(); this.shell.redraw(); this.shell.update(); } }
public void init() { this.setLayout(new GridLayout(1,true)); this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); ((GridData)this.getLayoutData()).widthHint = 600; this.composite = new Composite(this,SWT.BORDER | SWT.DOUBLE_BUFFERED); this.composite.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_WHITE)); this.composite.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { TGPainter painter = new TGPainter(e.gc); TGTunerRoughWidget.this.paintWidget(painter); } }); GridData data = new GridData(SWT.FILL,SWT.FILL,true,true); data.minimumHeight = MIN_HEIGHT; data.grabExcessHorizontalSpace = true; this.composite.setLayoutData(data); }
private void deleteCell( final Cell cell ) { final CellColumn cellColumn = ( CellColumn ) cell.getParent(); cellColumn.remove( cell ); // Update indexes final List< ? > children = cellColumn.getChildren(); for ( int ndx = cell.index; ndx < children.size(); ndx++ ) { final Cell afterCell = ( Cell ) children.get( ndx ); afterCell.index--; afterCell.indexField.setText( String.valueOf( Integer.parseInt( afterCell.indexField.getText() ) - 1 ) ); } // Focus on next cell, or previous cell if last cell was deleted cellColumn.getLayoutManager().layout( cellColumn ); if ( children.size() > 1 ) { final Cell newCell = ( Cell ) children.get( Math.min( cell.index + 1, children.size() - 1 ) ); addPaintListener( new PaintListener() { @Override public void paintControl( final PaintEvent e ) { changeFocusCell( cellColumn.column, newCell ); removePaintListener( this ); } } ); changeFocusCell( cellColumn.column, newCell ); } updateCellPreferredWidth( cellColumn.column ); }
public PreviewCanvas(Composite parent, int style) { super(parent, style); this.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent evt) { if(imageFile == null) evt.gc.drawString(LabelHolder.get("dialog.pojo.image.nopreview"), 5, 10); else { Image swtImage = null; try { final ImageTool imageTool = InitializationManager.getBean(ImageTool.class); //$NON-NLS-1$ File prevFile = imageTool.getDialogPreview(imageFile, new Dimension(getSize().x, getSize().y)); swtImage = new Image(Display.getCurrent(), prevFile.getAbsolutePath()); evt.gc.drawImage(swtImage, 0, 0); swtImage.dispose(); } catch (Exception e) { logger.warn(String.format("Problems while previewing [%s]: %s", imageFile.getPath(), e.getMessage()), e); } finally { if (swtImage != null) swtImage.dispose(); } } } }); }