1 | /*
|
---|
2 | * Copyright 2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.splash;
|
---|
19 |
|
---|
20 | import java.awt.BorderLayout;
|
---|
21 | import java.awt.Color;
|
---|
22 | import java.awt.Dimension;
|
---|
23 | import java.awt.Font;
|
---|
24 | import java.awt.Toolkit;
|
---|
25 | import java.awt.event.ActionEvent;
|
---|
26 | import java.awt.event.ActionListener;
|
---|
27 | import javax.swing.BorderFactory;
|
---|
28 | import javax.swing.ImageIcon;
|
---|
29 | import javax.swing.JLabel;
|
---|
30 | import javax.swing.JPanel;
|
---|
31 | import javax.swing.JProgressBar;
|
---|
32 | import javax.swing.JWindow;
|
---|
33 | import org.apache.tools.ant.BuildEvent;
|
---|
34 | import org.apache.tools.ant.BuildListener;
|
---|
35 |
|
---|
36 | class SplashScreen extends JWindow implements ActionListener, BuildListener {
|
---|
37 |
|
---|
38 | private JLabel text;
|
---|
39 | private JProgressBar pb;
|
---|
40 | private int total;
|
---|
41 | private final int min = 0;
|
---|
42 | private final int max = 200;
|
---|
43 |
|
---|
44 | public SplashScreen(String msg) {
|
---|
45 | init(null);
|
---|
46 | setText(msg);
|
---|
47 | }
|
---|
48 |
|
---|
49 | public SplashScreen(ImageIcon img) {
|
---|
50 | init(img);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected void init(ImageIcon img) {
|
---|
54 |
|
---|
55 | JPanel pan = (JPanel) getContentPane();
|
---|
56 | JLabel piccy;
|
---|
57 | if (img == null) {
|
---|
58 | piccy = new JLabel();
|
---|
59 | } else {
|
---|
60 | piccy = new JLabel(img);
|
---|
61 | }
|
---|
62 |
|
---|
63 | piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1));
|
---|
64 | text = new JLabel("Building....", JLabel.CENTER);
|
---|
65 | text.setFont(new Font("Sans-Serif", Font.BOLD, 12));
|
---|
66 | text.setBorder(BorderFactory.createEtchedBorder());
|
---|
67 |
|
---|
68 | pb = new JProgressBar(min, max);
|
---|
69 | pb.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
|
---|
70 | JPanel pan2 = new JPanel();
|
---|
71 | pan2.setLayout(new BorderLayout());
|
---|
72 |
|
---|
73 | pan2.add(text, BorderLayout.NORTH);
|
---|
74 | pan2.add(pb, BorderLayout.SOUTH);
|
---|
75 |
|
---|
76 | pan.setLayout(new BorderLayout());
|
---|
77 | pan.add(piccy, BorderLayout.CENTER);
|
---|
78 | pan.add(pan2, BorderLayout.SOUTH);
|
---|
79 |
|
---|
80 | pan.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
---|
81 |
|
---|
82 | pack();
|
---|
83 |
|
---|
84 | Dimension size = getSize();
|
---|
85 | Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
86 | int x = (scr.width - size.width) / 2;
|
---|
87 | int y = (scr.height - size.height) / 2;
|
---|
88 | setBounds(x, y, size.width, size.height);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void setText(String txt) {
|
---|
92 | text.setText(txt);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public void actionPerformed(ActionEvent a) {
|
---|
96 | if (total < max) {
|
---|
97 | total++;
|
---|
98 | } else {
|
---|
99 | total = min;
|
---|
100 | }
|
---|
101 | pb.setValue(total);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void buildStarted(BuildEvent event) {
|
---|
105 | actionPerformed(null);
|
---|
106 | }
|
---|
107 |
|
---|
108 | public void buildFinished(BuildEvent event) {
|
---|
109 | pb.setValue(max);
|
---|
110 | setVisible(false);
|
---|
111 | dispose();
|
---|
112 | }
|
---|
113 | public void targetStarted(BuildEvent event) {
|
---|
114 | actionPerformed(null);
|
---|
115 | }
|
---|
116 |
|
---|
117 | public void targetFinished(BuildEvent event) {
|
---|
118 | actionPerformed(null);
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void taskStarted(BuildEvent event) {
|
---|
122 | actionPerformed(null);
|
---|
123 | }
|
---|
124 |
|
---|
125 | public void taskFinished(BuildEvent event) {
|
---|
126 | actionPerformed(null);
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void messageLogged(BuildEvent event) {
|
---|
130 | actionPerformed(null);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|