package com.drawbridge.vl; import java.awt.Component; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JLabel; public class PopupInfoMessage extends Popup { /** * */ private static final long serialVersionUID = -517260964117893610L; private JLabel mJLabel; private FadeInAnimation fadeInThread = null; public PopupInfoMessage() { super(false, 1f); initUI(); } public void initUI() { BoxLayout bl = new BoxLayout(this, BoxLayout.X_AXIS); this.setLayout(bl); add(Box.createHorizontalGlue()); mJLabel = new JLabel("Test"); mJLabel.setAlignmentX(Component.CENTER_ALIGNMENT); mJLabel.setAlignmentY(Component.CENTER_ALIGNMENT); add(mJLabel); add(Box.createHorizontalGlue()); } public void show(String message, long time){ mJLabel.setText(message); setTransparency(0f); setVisible(true); if(fadeInThread == null || !fadeInThread.isAlive()){ fadeInThread = new FadeInAnimation(time); fadeInThread.start(); } } class FadeInAnimation extends Thread{ public boolean allowToRun = true; int fadeTime = 500; long waitTime; int updates = 100; public FadeInAnimation(long time){ waitTime = time; } @Override public void run() { for(int i = 1; i < updates && allowToRun; i++){ PopupInfoMessage.this.setTransparency(((float) i) / updates); PopupInfoMessage.this.repaint(); try { Thread.sleep(fadeTime / updates); } catch (InterruptedException e) { e.printStackTrace(); } } if(allowToRun){ try { Thread.sleep(waitTime); } catch (InterruptedException e) { e.printStackTrace(); } } for(int i = 1; i < updates && allowToRun; i++){ PopupInfoMessage.this.setTransparency(1f - (((float) i) / updates)); PopupInfoMessage.this.repaint(); try { Thread.sleep(fadeTime / updates); } catch (InterruptedException e) { e.printStackTrace(); } } } } }