Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public static void main(String[] args) {
shell.setText("Advanced Graphics");
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 60, SWT.BOLD | SWT.ITALIC);
final Image image = new Image(display, 640, 480);
final ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(0, 0, imageWidth, imageHeight);
};
final Image image = new Image(display,imageGcDrawer, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();
shell.addListener(SWT.Paint, event -> {
GC gc1 = event.gc;
Transform tr = new Transform(display);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class Snippet104 {
public static void main(String[] args) {
final Display display = new Display();
final int [] count = new int [] {4};
final Image image = new Image(display, 300, 300);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRectangle(image.getBounds());
gc.drawText("Splash Screen", 10, 10);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRectangle(0, 0, imageWidth, imageHeight);
gc.drawText("Splash Screen", 10, 10);
};
final Image image = new Image(display, imageGcDrawer, 300, 300);
final Shell splash = new Shell(SWT.ON_TOP);
final ProgressBar bar = new ProgressBar(splash, SWT.NONE);
bar.setMaximum(count[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public class Snippet112 {

public static void main (String [] args) {
Display display = new Display ();
final Image image = new Image (display, 20, 20);
Color color = display.getSystemColor (SWT.COLOR_RED);
GC gc = new GC (image);
gc.setBackground (color);
gc.fillRectangle (image.getBounds ());
gc.dispose ();
final ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
Color color = display.getSystemColor (SWT.COLOR_RED);
gc.setBackground(color);
gc.fillRectangle(0, 0, imageWidth, imageHeight);
};
final Image image = new Image (display, imageGcDrawer, 20, 20);

Shell shell = new Shell (display);
shell.setText("Snippet 112");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class Snippet138 {
public static void main(String[] args) {
Display display = new Display();

Image small = new Image(display, 16, 16);
GC gc = new GC(small);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, 16, 16, 45, 270);
gc.dispose();
final ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, imageWidth, imageHeight, 45, 270);
};
Image small = new Image(display, imageGcDrawer, 16, 16);

Image large = new Image(display, 32, 32);
gc = new GC(large);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, 32, 32, 45, 270);
gc.dispose();
final ImageGcDrawer imageGcDrawer1 = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, imageWidth, imageHeight, 45, 270);
};
Image large = new Image(display, imageGcDrawer1, 32, 32);

/* Provide different resolutions for icons to get
* high quality rendering wherever the OS needs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void main(String[] args) {
shellBackground = shell.getBackground();

FileDialog dialog = new FileDialog(shell);
dialog.setFilterExtensions(new String[] {"*.gif"});
dialog.setFilterExtensions("*.gif");
String fileName = dialog.open();
final AtomicBoolean stopAnimation = new AtomicBoolean(false);
if (fileName != null) {
Expand All @@ -59,11 +59,14 @@ public static void main(String[] args) {
@SuppressWarnings("unused")
public void run() {
/* Create an off-screen image to draw on, and fill it with the shell background. */
Image offScreenImage = new Image(display, loader.logicalScreenWidth, loader.logicalScreenHeight);
int width = loader.logicalScreenWidth;
int height = loader.logicalScreenHeight;
ImageGcDrawer offscreenDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(shellBackground);
gc.fillRectangle(0, 0, imageWidth, imageHeight);
};
Image offScreenImage = new Image(display, offscreenDrawer, width, height);
GC offScreenImageGC = new GC(offScreenImage);
offScreenImageGC.setBackground(shellBackground);
offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight);

try {
/* Create the first image and draw it on the off-screen image. */
int imageDataIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public static void main(String[] args) {
Shell shell = new Shell (display);
shell.setText("Snippet 143");
Image image = new Image (display, 16, 16);
Image image2 = new Image (display, 16, 16);
GC gc = new GC(image2);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(image2.getBounds());
gc.dispose();
ImageGcDrawer imgc = (gc, iwidth, iheight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(0, 0, iwidth, iheight);
};
Image image2 = new Image(display, imgc, 16, 16);
final Tray tray = display.getSystemTray ();
if (tray == null) {
System.out.println ("The system tray is not available");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,16 @@ static ImageData convertToSWT(BufferedImage bufferedImage) {
}

static ImageData createSampleImage(Display display) {
Image image = new Image(display, 100, 100);
Rectangle bounds = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(bounds);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.fillOval(0, 0, bounds.width, bounds.height);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawLine(0, 0, bounds.width, bounds.height);
gc.drawLine(bounds.width, 0, 0, bounds.height);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, imageWidth, imageHeight);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.fillOval(0, 0, imageWidth, imageHeight);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawLine(0, 0, imageWidth, imageHeight);
gc.drawLine(imageWidth, 0, 0, imageHeight);
};
Image image = new Image(display, imageGcDrawer, 100, 100);
ImageData data = image.getImageData();
image.dispose();
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ public void getState (AccessibleControlEvent e) {
}

static Image getStateImage (Display display, boolean checked) {
Image image = new Image (display, 16, 16);
GC gc = new GC (image);
gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
gc.fillOval (0, 0, 16, 16);
if (checked) {
gc.setForeground (display.getSystemColor (SWT.COLOR_DARK_GREEN));
gc.drawLine (0, 0, 16, 16);
gc.drawLine (16, 0, 0, 16);
}
gc.dispose ();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
gc.fillOval(0, 0, imageWidth, imageHeight);
if (checked) {
gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_GREEN));
gc.drawLine(0, 0, imageWidth, imageHeight);
gc.drawLine(imageWidth, 0, 0, imageHeight);
}
};
Image image = new Image(display, imageGcDrawer, 16, 16);
return image;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class Snippet165 {

public static void main (String [] args) {
Display display = new Display ();
Image image = new Image(display, 16, 16);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, 16, 16);
gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
gc.fillRectangle(3, 3, 10, 10);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, 16, 16);
gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
gc.fillRectangle(3, 3, 10, 10);
};
Image image = new Image(display, imageGcDrawer, 16, 16);
final Shell shell = new Shell (display);
shell.setText("Snippet 165");
shell.setLayout(new GridLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public class Snippet200 {
public static void main(String[] args) {
Display display = new Display();
//define a pattern on an image
final Image image = new Image(display, 1000, 1000);
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
GC gc = new GC(image);
gc.setBackground(white);
gc.setForeground(yellow);
gc.fillGradientRectangle(0, 0, 1000, 1000, true);
for (int i=-500; i<1000; i+=10) {
gc.setForeground(blue);
gc.drawLine(i, 0, 500 + i, 1000);
gc.drawLine(500 + i, 0, i, 1000);
}
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
gc.setBackground(white);
gc.setForeground(yellow);
gc.fillGradientRectangle(0, 0, 1000, 1000, true);
for (int i=-500; i<1000; i+=10) {
gc.setForeground(blue);
gc.drawLine(i, 0, 500 + i, 1000);
gc.drawLine(500 + i, 0, i, 1000);
}
};
final Image image = new Image(display, imageGcDrawer, 1000, 1000);
final Pattern pattern;
try {
pattern = new Pattern(display, image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setText("Embedding objects in text");
final Image[] images = {new Image(display, 32, 32), new Image(display, 20, 40), new Image(display, 40, 20)};
final Image[] images = new Image[3];
final Rectangle[] rects = { new Rectangle(0, 0, 32, 32), new Rectangle(0, 0, 20, 40), new Rectangle(0, 0, 40, 20) };
int[] colors = {SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN};
for (int i = 0; i < images.length; i++) {
GC gc = new GC(images[i]);
gc.setBackground(display.getSystemColor(colors[i]));
gc.fillRectangle(images[i].getBounds());
gc.dispose();
final int index = i;
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(colors[index]));
gc.fillRectangle(rects[index]);
};
images[i] = new Image(display, imageGcDrawer, rects[i].width, rects[i].height);
}

final Button button = new Button(shell, SWT.PUSH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public class Snippet207 {
public static void main(String[] args) {
final Display display = new Display();

final Image image = new Image(display, 110, 60);
GC gc = new GC(image);
Font font = new Font(display, "Times", 30, SWT.BOLD);
gc.setFont(font);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, 110, 60);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawText("SWT", 10, 10, true);
font.dispose();
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
Font font = new Font(display, "Times", 30, SWT.BOLD);
gc.setFont(font);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, 110, 60);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawText("SWT", 10, 10, true);
font.dispose();
};
final Image image = new Image(display, imageGcDrawer, 110, 60);

final Rectangle rect = image.getBounds();
Shell shell = new Shell(display);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public static void main(String [] args) {
button.setText ("Button " + i);
}
shell.addListener (SWT.Resize, event -> {
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
gc.fillGradientRectangle (0, 0, imageWidth, imageHeight, false);
};
Rectangle rect = shell.getClientArea ();
Image newImage = new Image (display, Math.max (1, rect.width), 1);
Image newImage = new Image (display, imageGcDrawer, Math.max (1, rect.width), 1);
GC gc = new GC (newImage);
gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public static void main(String [] args) {
styledText.setForeground(display.getSystemColor (SWT.COLOR_BLUE));
styledText.addListener (SWT.Resize, event -> {
Rectangle rect = styledText.getClientArea ();
Image newImage = new Image (display, 1, Math.max (1, rect.height));
GC gc = new GC (newImage);
gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
gc.fillGradientRectangle (rect.x, rect.y, 1, rect.height, true);
gc.dispose ();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW));
gc.fillGradientRectangle (rect.x, rect.y, 1, rect.height, true);
};
Image newImage = new Image (display, imageGcDrawer, 1, Math.max (1, rect.height));
styledText.setBackgroundImage (newImage);
if (oldImage != null) oldImage.dispose ();
oldImage = newImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public static void main(String [] args) {
Shell shell = new Shell(display);
shell.setText("Snippet 220");
shell.setBounds(10, 10, 350, 200);
Image xImage = new Image (display, 16, 16);
GC gc = new GC(xImage);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawLine(1, 1, 14, 14);
gc.drawLine(1, 14, 14, 1);
gc.drawOval(2, 2, 11, 11);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawLine(1, 1, 14, 14);
gc.drawLine(1, 14, 14, 1);
gc.drawOval(2, 2, 11, 11);
};
Image xImage = new Image (display, imageGcDrawer, 16, 16);
final int IMAGE_MARGIN = 2;
final Tree tree = new Tree(shell, SWT.CHECK);
tree.setBounds(10, 10, 300, 150);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ public static void main(String[] args) {

private static void createImage() {
Font font = new Font(display, "Comic Sans MS", 48, SWT.BOLD);
Image image = new Image(display, 174, 96);
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(image.getBounds());
gc.setFont(font);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawString("S", 3, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));
gc.drawString("W", 50, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.drawString("T", 124, 10);
gc.dispose();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
gc.fillRectangle(new Rectangle(0, 0, 174, 96));
gc.setFont(font);
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.drawString("S", 3, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));
gc.drawString("W", 50, 10);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.drawString("T", 124, 10);
};
Image image = new Image(display, imageGcDrawer, 174, 96);

ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class Snippet275 {
public static void main (String[] args) {
final int INTERVAL = 888;
final Display display = new Display ();
final Image image = new Image (display, 750, 750);
GC gc = new GC (image);
gc.setBackground (display.getSystemColor (SWT.COLOR_RED));
gc.fillRectangle (image.getBounds ());
gc.dispose ();
ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, imageWidth, imageHeight);
};
final Image image = new Image(display, imageGcDrawer, 750, 750);

Shell shell = new Shell (display);
shell.setText("Snippet 275");
Expand Down
Loading
Loading