1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| package launch;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import javax.swing.JWindow;
import javax.swing.UIManager;
public class ShadowedWindow extends JWindow {
private static final long serialVersionUID = 1L;
private BufferedImage splash = null;
int extra = 14;
static final Font FONTNORMAL = UIManager.getFont("Label.font").deriveFont(Font.PLAIN,UIManager.getFont("Label.font").getSize());
static final Color INVALIDE_FG_RED = Color.RED;
public ShadowedWindow(BufferedImage image) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) ) ;
createShadowPicture(image);
}
public void dispose(){
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) ) ;
super.dispose();
}
public void paint(Graphics g) {
if (splash != null) {
g.drawImage(splash, 0, 0, null);
g.drawLine(0,0,1,this.getHeight()-extra-2);
g.drawLine(0,0,this.getWidth()-extra-2,1);
g.setFont(FONTNORMAL.deriveFont(Font.BOLD,15f));
g.setColor(INVALIDE_FG_RED);
g.drawString("Mise à jour en cours, Merci de patienter", 40, this.getHeight()-200);
}
}
private void createShadowPicture(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
setSize(new Dimension(width + extra, height + extra));
setLocationRelativeTo(null);
Rectangle windowRect = getBounds();
splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) splash.getGraphics();
try {
Robot robot = new Robot(getGraphicsConfiguration().getDevice());
BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width + extra, windowRect.height + extra));
g2.drawImage(capture, null, 0, 0);
} catch (AWTException e) { }
BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB);
Graphics g = shadow.getGraphics();
g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
g.fillRoundRect(6, 6, width, height, 12, 12);
g2.drawImage(shadow, getBlurOp(7), 0, 0);
g2.drawImage(image, 0, 0, this);
}
private ConvolveOp getBlurOp(int size) {
float[] data = new float[size * size];
float value = 1 / (float) (size * size);
for (int i = 0; i < data.length; i++) {
data[i] = value;
}
return new ConvolveOp(new Kernel(size, size, data));
}
// public static void main(String[] args) {
// try {
// BufferedImage image = ImageIO.read(ShadowedWindow.class.getResourceAsStream("aImages/binaire.png"));
// ShadowedWindow window = new ShadowedWindow(image);
// window.setVisible(true);
// Timer timer = new Timer(5000, new ActionListener() {
// public void actionPerformed(ActionEvent evt) {
// System.exit(0);
// }
// });
// timer.start();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
} |
Partager