| 1 | 0 | package br.mia.test.view; |
| 2 | |
|
| 3 | |
import java.awt.BorderLayout; |
| 4 | |
import java.awt.Color; |
| 5 | |
import java.awt.FlowLayout; |
| 6 | |
|
| 7 | |
import javax.swing.ImageIcon; |
| 8 | |
import javax.swing.JLabel; |
| 9 | |
import javax.swing.JPanel; |
| 10 | |
import javax.swing.JProgressBar; |
| 11 | |
import javax.swing.JWindow; |
| 12 | |
import javax.swing.SwingUtilities; |
| 13 | |
|
| 14 | |
import br.mia.test.controler.ControladorErro; |
| 15 | |
|
| 16 | |
public class SplashScreen extends JWindow { |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
private static final long serialVersionUID = 1L; |
| 21 | |
|
| 22 | 0 | BorderLayout borderLayout1 = new BorderLayout(); |
| 23 | |
|
| 24 | 0 | JLabel imageLabel = new JLabel(); |
| 25 | |
|
| 26 | 0 | JPanel southPanel = new JPanel(); |
| 27 | |
|
| 28 | 0 | FlowLayout southPanelFlowLayout = new FlowLayout(); |
| 29 | |
|
| 30 | 0 | JProgressBar progressBar = new JProgressBar(); |
| 31 | |
|
| 32 | |
ImageIcon imageIcon; |
| 33 | |
|
| 34 | 0 | public SplashScreen(ImageIcon imageIcon) { |
| 35 | 0 | this.imageIcon = imageIcon; |
| 36 | |
try { |
| 37 | 0 | jbInit(); |
| 38 | 0 | } catch (Exception ex) { |
| 39 | 0 | ControladorErro.trata(ex, this); |
| 40 | |
} |
| 41 | 0 | } |
| 42 | |
|
| 43 | |
|
| 44 | |
void jbInit() throws Exception { |
| 45 | 0 | imageLabel.setIcon(imageIcon); |
| 46 | 0 | this.getContentPane().setLayout(borderLayout1); |
| 47 | 0 | southPanel.setLayout(southPanelFlowLayout); |
| 48 | 0 | southPanel.setBackground(Color.BLACK); |
| 49 | 0 | this.getContentPane().add(imageLabel, BorderLayout.CENTER); |
| 50 | 0 | this.getContentPane().add(southPanel, BorderLayout.SOUTH); |
| 51 | 0 | southPanel.add(progressBar, null); |
| 52 | 0 | this.pack(); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public void setProgressMax(int maxProgress) { |
| 56 | 0 | progressBar.setMaximum(maxProgress); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
public void setProgress(int progress) { |
| 60 | 0 | final int theProgress = progress; |
| 61 | 0 | SwingUtilities.invokeLater(new Runnable() { |
| 62 | |
public void run() { |
| 63 | 0 | progressBar.setValue(theProgress); |
| 64 | 0 | } |
| 65 | |
}); |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
public void setProgress(String message, int progress) { |
| 69 | 0 | final int theProgress = progress; |
| 70 | 0 | final String theMessage = message; |
| 71 | 0 | setProgress(progress); |
| 72 | 0 | SwingUtilities.invokeLater(new Runnable() { |
| 73 | |
public void run() { |
| 74 | 0 | progressBar.setValue(theProgress); |
| 75 | 0 | setMessage(theMessage); |
| 76 | 0 | } |
| 77 | |
}); |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
public void setScreenVisible(boolean b) { |
| 81 | 0 | final boolean boo = b; |
| 82 | 0 | SwingUtilities.invokeLater(new Runnable() { |
| 83 | |
public void run() { |
| 84 | 0 | setVisible(boo); |
| 85 | 0 | } |
| 86 | |
}); |
| 87 | 0 | } |
| 88 | |
|
| 89 | 0 | private void setMessage(String message) { |
| 90 | 0 | if (message == null) { |
| 91 | 0 | message = ""; |
| 92 | 0 | progressBar.setStringPainted(false); |
| 93 | |
} else { |
| 94 | 0 | progressBar.setStringPainted(true); |
| 95 | |
} |
| 96 | 0 | progressBar.setString(message); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
} |