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 @@ -1475,7 +1475,7 @@ void setFont(Font font, int tabs) {
if (boldItalicFont != null) boldItalicFont.dispose();
boldFont = italicFont = boldItalicFont = null;
regularFont = font;
layout.setText(" ");
layout.setText(" ");
layout.setFont(font);
layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0);
layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ 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 All @@ -61,6 +62,7 @@ public static void main(String[] args) {
if (!display.readAndDispatch())
display.sleep();
}

image.dispose();
font.dispose();
display.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,63 @@

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();
final Shell splash = new Shell(SWT.ON_TOP);
final ProgressBar bar = new ProgressBar(splash, SWT.NONE);
bar.setMaximum(count[0]);
Label label = new Label(splash, SWT.NONE);
label.setImage(image);
FormLayout layout = new FormLayout();
splash.setLayout(layout);
FormData labelData = new FormData ();
labelData.right = new FormAttachment (100, 0);
labelData.bottom = new FormAttachment (100, 0);
label.setLayoutData(labelData);
FormData progressData = new FormData ();
progressData.left = new FormAttachment (0, 5);
progressData.right = new FormAttachment (100, -5);
progressData.bottom = new FormAttachment (100, -5);
bar.setLayoutData(progressData);
splash.pack();
Rectangle splashRect = splash.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
splash.setLocation(x, y);
splash.open();
display.asyncExec(() -> {
Shell [] shells = new Shell[count[0]];
for (int i1=0; i1<count[0]; i1++) {
shells [i1] = new Shell(display);
shells [i1].setSize (300, 300);
shells [i1].addListener(SWT.Close, e -> --count[0]);
bar.setSelection(i1+1);
try {Thread.sleep(1000);} catch (Throwable e) {}
}
splash.close();
image.dispose();
for (int i2=0; i2<count[0]; i2++) {
shells [i2].setText("SWT Snippet 104 - " + (i2+1));
shells [i2].open();
public static void main(String[] args) {
final Display display = new Display();
final int[] count = new int[] { 4 };

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]);
Label label = new Label(splash, SWT.NONE);
label.setImage(image);
FormLayout layout = new FormLayout();
splash.setLayout(layout);
FormData labelData = new FormData();
labelData.right = new FormAttachment(100, 0);
labelData.bottom = new FormAttachment(100, 0);
label.setLayoutData(labelData);
FormData progressData = new FormData();
progressData.left = new FormAttachment(0, 5);
progressData.right = new FormAttachment(100, -5);
progressData.bottom = new FormAttachment(100, -5);
bar.setLayoutData(progressData);
splash.pack();
Rectangle splashRect = splash.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
splash.setLocation(x, y);
splash.open();
display.asyncExec(() -> {
Shell[] shells = new Shell[count[0]];
for (int i1 = 0; i1 < count[0]; i1++) {
shells[i1] = new Shell(display);
shells[i1].setSize(300, 300);
shells[i1].addListener(SWT.Close, e -> --count[0]);
bar.setSelection(i1 + 1);
try {
Thread.sleep(1000);
} catch (Throwable e) {
}
}
splash.close();
image.dispose();
for (int i2 = 0; i2 < count[0]; i2++) {
shells[i2].setText("SWT Snippet 104 - " + (i2 + 1));
shells[i2].open();
}
});
while (count[0] != 0) {
if (!display.readAndDispatch())
display.sleep();
}
});
while (count [0] != 0) {
if (!display.readAndDispatch ()) display.sleep ();
display.dispose();
}
display.dispose();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ 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) -> {
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 @@ -28,7 +28,7 @@
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));
Expand All @@ -40,6 +40,21 @@ public static void main(String[] args) {
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, 32, 32, 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);

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 @@ -91,7 +91,6 @@ static ImageData flip(ImageData srcData, boolean vertical) {
public static void main(String[] args) {
Display display = new Display();

// create an image with the word "hello" on it
final Image image0 = new Image(display, 50, 30);
GC gc = new GC(image0);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
Expand All @@ -100,8 +99,9 @@ public static void main(String[] args) {
gc.dispose();

ImageData data = image0.getImageData();

// rotate and flip this image
final Image image1 = new Image(display, rotate(data, SWT.LEFT));
final Image image1 = new Image(display, rotate(data, SWT.LEFT));
final Image image2 = new Image(display, rotate(data, SWT.RIGHT));
final Image image3 = new Image(display, rotate(data, SWT.DOWN));
final Image image4 = new Image(display, flip(data, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,102 +49,79 @@ public static void main(String[] args) {
dialog.setFilterExtensions(new String[] {"*.gif"});
String fileName = dialog.open();
final AtomicBoolean stopAnimation = new AtomicBoolean(false);

if (fileName != null) {
loader = new ImageLoader();
try {
imageDataArray = loader.load(fileName);
if (imageDataArray.length > 1) {
animateThread = new Thread("Animation") {
@Override
@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);
GC offScreenImageGC = new GC(offScreenImage);
offScreenImageGC.setBackground(shellBackground);
offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight);

Image offScreenImage = null;
try {
/* Create the first image and draw it on the off-screen image. */
int width = loader.logicalScreenWidth;
int height = loader.logicalScreenHeight;

ImageGcDrawer offscreenDrawer = (gc, imageWidth, imageHeight) -> {
gc.setBackground(shellBackground);
gc.fillRectangle(0, 0, imageWidth, imageHeight);
};
offScreenImage = new Image(display, offscreenDrawer, width, height);
GC offScreenImageGC = new GC(offScreenImage);

int imageDataIndex = 0;
ImageData imageData = imageDataArray[imageDataIndex];

if (image != null && !image.isDisposed()) image.dispose();
image = new Image(display, imageData);
offScreenImageGC.drawImage(
image,
0,
0,
imageData.width,
imageData.height,
imageData.x,
imageData.y,
imageData.width,
imageData.height);

/* Now loop through the images, creating and drawing each one
* on the off-screen image before drawing it on the shell. */
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,
imageData.x, imageData.y, imageData.width, imageData.height);

int repeatCount = loader.repeatCount;
while ((loader.repeatCount == 0 || repeatCount > 0) && !stopAnimation.get()) {
switch (imageData.disposalMethod) {
case SWT.DM_FILL_BACKGROUND:
/* Fill with the background color before drawing. */
Color bgColor = null;
if (useGIFBackground && loader.backgroundPixel != -1) {
bgColor = new Color(imageData.palette.getRGB(loader.backgroundPixel));
}
offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground);
offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, imageData.height);
if (bgColor != null) bgColor.dispose();
break;
case SWT.DM_FILL_PREVIOUS:
/* Restore the previous image before drawing. */
offScreenImageGC.drawImage(
image,
0,
0,
imageData.width,
imageData.height,
imageData.x,
imageData.y,
imageData.width,
imageData.height);
offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,
imageData.x, imageData.y, imageData.width, imageData.height);
break;
}

imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;
imageData = imageDataArray[imageDataIndex];
image.dispose();
image = new Image(display, imageData);
offScreenImageGC.drawImage(
image,
0,
0,
imageData.width,
imageData.height,
imageData.x,
imageData.y,
imageData.width,
imageData.height);

/* Draw the off-screen image to the shell. */

offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,
imageData.x, imageData.y, imageData.width, imageData.height);

shellGC.drawImage(offScreenImage, 0, 0);

/* Sleep for the specified delay time (adding commonly-used slow-down fudge factors). */
try {
int ms = imageData.delayTime * 10;
if (ms < 20) ms += 30;
if (ms < 30) ms += 10;
Thread.sleep(ms);
} catch (InterruptedException e) {
// ignore
}

/* If we have just drawn the last image, decrement the repeat count and start again. */
if (imageDataIndex == imageDataArray.length - 1) repeatCount--;
}
offScreenImageGC.dispose();
} catch (SWTException ex) {
System.out.println("There was an error animating the GIF");
} finally {
if (offScreenImage != null && !offScreenImage.isDisposed()) offScreenImage.dispose();
if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) offScreenImageGC.dispose();
if (image != null && !image.isDisposed()) image.dispose();
}
}
Expand All @@ -163,4 +140,4 @@ public void run() {
stopAnimation.set(true);
display.dispose();
}
}
}
Loading
Loading