packagedev.equo;importdev.equo.swt.Config;importorg.eclipse.swt.SWT;importorg.eclipse.swt.graphics.Color;importorg.eclipse.swt.graphics.Image;importorg.eclipse.swt.graphics.ImageData;importorg.eclipse.swt.graphics.PaletteData;importorg.eclipse.swt.layout.FormAttachment;importorg.eclipse.swt.layout.FormData;importorg.eclipse.swt.layout.FormLayout;importorg.eclipse.swt.widgets.Canvas;importorg.eclipse.swt.widgets.Display;importorg.eclipse.swt.widgets.Shell;/** * A login-screen shape: a Shell with a backgroundImage forced onto its children * (INHERIT_FORCE) and a Canvas that never sets a background of its own but draws a status line * from a PaintListener. * * SWT erases the Canvas to the inherited image before the listener runs, so the text must land * on the image with nothing else visible -- a solid slab where the Canvas sits means the GC erase * resolved to a color instead of staying transparent for the image painted underneath. * * Swap Config.forceEquo() for Config.forceEclipse() (runEmbedExample) for the native baseline. */publicclassCanvasPaintListenerInheritedImageSnippet{publicstaticvoidmain(String[]args){Config.forceEquo();Displaydisplay=newDisplay();Shellshell=newShell(display);shell.setText("CanvasPaintListenerInheritedImageSnippet");shell.setSize(800,600);shell.setBackground(newColor(display,240,240,240));shell.setBackgroundImage(stripes(display));shell.setBackgroundMode(SWT.INHERIT_FORCE);shell.setLayout(newFormLayout());CanvasinfoArea=newCanvas(shell,SWT.NONE);FormDatadata=newFormData();data.height=200;data.left=newFormAttachment(5,0);data.right=newFormAttachment(95,0);data.bottom=newFormAttachment(95,0);infoArea.setLayoutData(data);infoArea.addPaintListener(e->{StringinfoText="Waiting for connection ....";inttextHeight=e.gc.stringExtent(infoText).y;e.gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));e.gc.drawText(infoText,0,infoArea.getSize().y-textHeight,true);});shell.open();while(!shell.isDisposed()){if(!display.readAndDispatch())display.sleep();}display.dispose();}/** * Diagonal stripes as pixel data, the way an image loaded from a file arrives: an opaque slab * over them is unmistakable, a transparent Canvas invisible. (Painting them through a GC on an * Image would take the remote-render path, which a backgroundImage does not display.) */privatestaticImagestripes(Displaydisplay){intwidth=800,height=600;ImageDatadata=newImageData(width,height,24,newPaletteData(0xFF0000,0x00FF00,0x0000FF));intbase=(205<<16)|(215<<8)|235;intstripe=(120<<16)|(140<<8)|190;for(inty=0;y<height;y++){for(intx=0;x<width;x++){data.setPixel(x,y,((x+y)/20)%2==0?base:stripe);}}returnnewImage(display,data);}}