1 18 19 package org.apache.tools.ant.taskdefs.optional.splash; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Font ; 25 import java.awt.Toolkit ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 import javax.swing.BorderFactory ; 29 import javax.swing.ImageIcon ; 30 import javax.swing.JLabel ; 31 import javax.swing.JPanel ; 32 import javax.swing.JProgressBar ; 33 import javax.swing.JWindow ; 34 import org.apache.tools.ant.BuildEvent; 35 import org.apache.tools.ant.BuildListener; 36 37 class SplashScreen extends JWindow implements ActionListener , BuildListener { 38 39 private JLabel text; 40 private JProgressBar pb; 41 private int total; 42 private static final int MIN = 0; 43 private static final int MAX = 200; 44 45 public SplashScreen(String msg) { 46 init(null); 47 setText(msg); 48 } 49 50 public SplashScreen(ImageIcon img) { 51 init(img); 52 } 53 54 protected void init(ImageIcon img) { 55 56 JPanel pan = (JPanel ) getContentPane(); 57 JLabel piccy; 58 if (img == null) { 59 piccy = new JLabel (); 60 } else { 61 piccy = new JLabel (img); 62 } 63 64 piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1)); 65 text = new JLabel ("Building....", JLabel.CENTER); 66 text.setFont(new Font ("Sans-Serif", Font.BOLD, 12)); 67 text.setBorder(BorderFactory.createEtchedBorder()); 68 69 pb = new JProgressBar (MIN, MAX); 70 pb.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); 71 JPanel pan2 = new JPanel (); 72 pan2.setLayout(new BorderLayout ()); 73 74 pan2.add(text, BorderLayout.NORTH); 75 pan2.add(pb, BorderLayout.SOUTH); 76 77 pan.setLayout(new BorderLayout ()); 78 pan.add(piccy, BorderLayout.CENTER); 79 pan.add(pan2, BorderLayout.SOUTH); 80 81 pan.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); 82 83 pack(); 84 85 Dimension size = getSize(); 86 Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 87 int x = (scr.width - size.width) / 2; 88 int y = (scr.height - size.height) / 2; 89 setBounds(x, y, size.width, size.height); 90 } 91 92 public void setText(String txt) { 93 text.setText(txt); 94 } 95 96 public void actionPerformed(ActionEvent a) { 97 if (total < MAX) { 98 total++; 99 } else { 100 total = MIN; 101 } 102 pb.setValue(total); 103 } 104 105 public void buildStarted(BuildEvent event) { 106 actionPerformed(null); 107 } 108 109 public void buildFinished(BuildEvent event) { 110 pb.setValue(MAX); 111 setVisible(false); 112 dispose(); 113 } 114 public void targetStarted(BuildEvent event) { 115 actionPerformed(null); 116 } 117 118 public void targetFinished(BuildEvent event) { 119 actionPerformed(null); 120 } 121 122 public void taskStarted(BuildEvent event) { 123 actionPerformed(null); 124 } 125 126 public void taskFinished(BuildEvent event) { 127 actionPerformed(null); 128 } 129 130 public void messageLogged(BuildEvent event) { 131 actionPerformed(null); 132 } 133 } 134 135 | Popular Tags |