001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.splash;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Color;
023: import java.awt.Dimension;
024: import java.awt.Font;
025: import java.awt.Toolkit;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028: import javax.swing.BorderFactory;
029: import javax.swing.ImageIcon;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.JProgressBar;
033: import javax.swing.JWindow;
034: import org.apache.tools.ant.BuildEvent;
035: import org.apache.tools.ant.BuildListener;
036:
037: class SplashScreen extends JWindow implements ActionListener,
038: BuildListener {
039:
040: private JLabel text;
041: private JProgressBar pb;
042: private int total;
043: private static final int MIN = 0;
044: private static final int MAX = 200;
045:
046: public SplashScreen(String msg) {
047: init(null);
048: setText(msg);
049: }
050:
051: public SplashScreen(ImageIcon img) {
052: init(img);
053: }
054:
055: protected void init(ImageIcon img) {
056:
057: JPanel pan = (JPanel) getContentPane();
058: JLabel piccy;
059: if (img == null) {
060: piccy = new JLabel();
061: } else {
062: piccy = new JLabel(img);
063: }
064:
065: piccy.setBorder(BorderFactory.createLineBorder(Color.black, 1));
066: text = new JLabel("Building....", JLabel.CENTER);
067: text.setFont(new Font("Sans-Serif", Font.BOLD, 12));
068: text.setBorder(BorderFactory.createEtchedBorder());
069:
070: pb = new JProgressBar(MIN, MAX);
071: pb
072: .setBorder(BorderFactory
073: .createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
074: JPanel pan2 = new JPanel();
075: pan2.setLayout(new BorderLayout());
076:
077: pan2.add(text, BorderLayout.NORTH);
078: pan2.add(pb, BorderLayout.SOUTH);
079:
080: pan.setLayout(new BorderLayout());
081: pan.add(piccy, BorderLayout.CENTER);
082: pan.add(pan2, BorderLayout.SOUTH);
083:
084: pan
085: .setBorder(BorderFactory
086: .createBevelBorder(javax.swing.border.BevelBorder.RAISED));
087:
088: pack();
089:
090: Dimension size = getSize();
091: Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
092: int x = (scr.width - size.width) / 2;
093: int y = (scr.height - size.height) / 2;
094: setBounds(x, y, size.width, size.height);
095: }
096:
097: public void setText(String txt) {
098: text.setText(txt);
099: }
100:
101: public void actionPerformed(ActionEvent a) {
102: if (total < MAX) {
103: total++;
104: } else {
105: total = MIN;
106: }
107: pb.setValue(total);
108: }
109:
110: public void buildStarted(BuildEvent event) {
111: actionPerformed(null);
112: }
113:
114: public void buildFinished(BuildEvent event) {
115: pb.setValue(MAX);
116: setVisible(false);
117: dispose();
118: }
119:
120: public void targetStarted(BuildEvent event) {
121: actionPerformed(null);
122: }
123:
124: public void targetFinished(BuildEvent event) {
125: actionPerformed(null);
126: }
127:
128: public void taskStarted(BuildEvent event) {
129: actionPerformed(null);
130: }
131:
132: public void taskFinished(BuildEvent event) {
133: actionPerformed(null);
134: }
135:
136: public void messageLogged(BuildEvent event) {
137: actionPerformed(null);
138: }
139: }
|