1 4 package swingwtx.swing; 5 6 import org.eclipse.swt.SWT; 7 import org.eclipse.swt.graphics.GC; 8 import org.eclipse.swt.graphics.ImageData; 9 import org.eclipse.swt.graphics.Rectangle; 10 import org.eclipse.swt.widgets.Label; 11 import org.eclipse.swt.widgets.Shell; 12 13 import swingwt.awt.Image; 14 15 38 public class JSplashScreen { 39 public static final int TEXT_LOWER_RIGHT = 0; 40 public static final int TEXT_LOWER_LEFT = 1; 41 public static final int TEXT_UPPER_RIGHT = 2; 42 public static final int TEXT_UPPER_LEFT = 3; 43 public static final int NO_TEXT = 4; 44 45 private String text = ""; 46 private int style = 4; 47 private Shell shell; 48 private Label label; 49 private ImageData data; 50 private org.eclipse.swt.graphics.Image image; 51 52 public JSplashScreen(Image img, int style) { 53 this.style = style; 54 image = img.image; 55 data = image.getImageData(); 56 57 shell = new Shell(SwingWTUtils.getDisplay(), SWT.NO_TRIM); 58 shell.setSize(data.width, data.height); 59 60 Rectangle rect = SwingWTUtils.getDisplay().getBounds(); 61 int shellX = (rect.width - data.width) / 2; 62 int shellY = (rect.height - data.height) / 2; 63 shell.setLocation(shellX, shellY); 64 65 shell.open(); 66 new GC(shell).drawImage(image, 0, 0); 67 68 if (style == TEXT_LOWER_RIGHT) { 69 label = new Label(shell, SWT.RIGHT); 70 label.setText(text); 71 label.setLocation(data.width - label.getBounds().width, data.height - label.getBounds().height); 72 } else if (style == TEXT_LOWER_LEFT) { 73 label = new Label(shell, SWT.LEFT); 74 label.setText(text); 75 label.setLocation(0, data.height - label.getBounds().height); 76 } else if (style == TEXT_UPPER_RIGHT) { 77 label = new Label(shell, SWT.RIGHT); 78 label.setText(text); 79 label.setLocation(data.width - label.getBounds().width, 0); 80 } else if (style == TEXT_UPPER_LEFT) { 81 label = new Label(shell, SWT.LEFT); 82 label.setText(text); 83 label.setLocation(0, 0); 84 } 85 } 86 87 public JSplashScreen(Image img) { 88 this(img, NO_TEXT); 89 } 90 91 public void setText(String text) { 92 this.text = text; 93 94 if (style == TEXT_LOWER_RIGHT) { 95 label.setText(text); 96 label.setLocation(data.width - label.getBounds().width, data.height - label.getBounds().height); 97 } else if (style == TEXT_LOWER_LEFT) { 98 label.setText(text); 99 label.setLocation(0, data.height - label.getBounds().height); 100 } else if (style == TEXT_UPPER_RIGHT) { 101 label.setText(text); 102 label.setLocation(data.width - label.getBounds().width, 0); 103 } else if (style == TEXT_UPPER_LEFT) { 104 label.setText(text); 105 label.setLocation(0, 0); 106 } 107 } 108 109 public void takeDown() { 110 image.dispose(); 111 shell.dispose(); 112 } 113 } 114 115 132 | Popular Tags |