KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > splash > SplashScreen


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.optional.splash;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.Toolkit JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import javax.swing.BorderFactory JavaDoc;
29 import javax.swing.ImageIcon JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JProgressBar JavaDoc;
33 import javax.swing.JWindow JavaDoc;
34 import org.apache.tools.ant.BuildEvent;
35 import org.apache.tools.ant.BuildListener;
36
37 class SplashScreen extends JWindow JavaDoc implements ActionListener JavaDoc, BuildListener {
38
39     private JLabel JavaDoc text;
40     private JProgressBar JavaDoc pb;
41     private int total;
42     private static final int MIN = 0;
43     private static final int MAX = 200;
44
45     public SplashScreen(String JavaDoc msg) {
46         init(null);
47         setText(msg);
48     }
49
50     public SplashScreen(ImageIcon JavaDoc img) {
51         init(img);
52     }
53
54     protected void init(ImageIcon JavaDoc img) {
55
56         JPanel JavaDoc pan = (JPanel JavaDoc) getContentPane();
57         JLabel JavaDoc piccy;
58         if (img == null) {
59             piccy = new JLabel JavaDoc();
60         } else {
61             piccy = new JLabel JavaDoc(img);
62         }
63
64         piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1));
65         text = new JLabel JavaDoc("Building....", JLabel.CENTER);
66         text.setFont(new Font JavaDoc("Sans-Serif", Font.BOLD, 12));
67         text.setBorder(BorderFactory.createEtchedBorder());
68
69         pb = new JProgressBar JavaDoc(MIN, MAX);
70         pb.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
71         JPanel JavaDoc pan2 = new JPanel JavaDoc();
72         pan2.setLayout(new BorderLayout JavaDoc());
73
74         pan2.add(text, BorderLayout.NORTH);
75         pan2.add(pb, BorderLayout.SOUTH);
76
77         pan.setLayout(new BorderLayout JavaDoc());
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 JavaDoc size = getSize();
86         Dimension JavaDoc 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 JavaDoc txt) {
93         text.setText(txt);
94     }
95
96     public void actionPerformed(ActionEvent JavaDoc 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