Browse Source

spashscreen task

Submitted by:	Les Hughes <leslie.hughes@rubus.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271943 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
03216f2caf
5 changed files with 356 additions and 1 deletions
  1. +1
    -1
      WHATSNEW
  2. +13
    -0
      build.xml
  3. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/defaults.properties
  4. +140
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java
  5. +201
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java

+ 1
- 1
WHATSNEW View File

@@ -147,7 +147,7 @@ Other changes:

* New tasks bzip2 and bunzip2 to pack and unpack files using the
BZip2 alogrithm, replaceregexp, checksum, translate, waitfor, input,
manifest, vsscp, vssadd, vsscreate
manifest, vsscp, vssadd, vsscreate, splash

* The attributes zipfile, jarfile, warfile and earfile (from the Zip,
Jar, War and Ear tasks) have been deprecated and superseded by a


+ 13
- 0
build.xml View File

@@ -159,6 +159,8 @@
<patternset id="needs.sun.b64">
<exclude name="${ant.package}/taskdefs/Get.java"
unless="base64.present" />
<exclude name="${optional.package}/splash/SplashTask.java"
unless="base64.present" />
</patternset>

<!-- depends on external libraries -->
@@ -285,6 +287,9 @@
<patternset id="onlinetests">
<exclude name="**/GetTest.java" if="offline" />
</patternset>
<patternset id="needs.swing">
<exclude name="${optional.package}/splash/*.java" unless="swing.present" />
</patternset>

<!--
===================================================================
@@ -435,6 +440,9 @@
</and>
</condition>
<available property="swing.present"
classname="javax.swing.ImageIcon"
classpathref="classpath"/>
</target>


@@ -503,6 +511,7 @@
<patternset refid="needs.sun.tools" />
<patternset refid="needs.sun.b64" />
<patternset refid="needs.jakarta.bcel" />
<patternset refid="needs.swing" />
</javac>

<copy todir="${build.classes}">
@@ -577,6 +586,10 @@
value="Apache Software Foundation" />
</section>
</manifest>

<fileset dir="${docs.dir}">
<include name="images/ant_logo_large.gif" />
</fileset>
</jar>

<jar destfile="${build.lib}/optional.jar"


+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/defaults.properties View File

@@ -150,6 +150,7 @@ soscheckin=org.apache.tools.ant.taskdefs.optional.sos.SOSCheckin
soscheckout=org.apache.tools.ant.taskdefs.optional.sos.SOSCheckout
soslabel=org.apache.tools.ant.taskdefs.optional.sos.SOSLabel
echoproperties=org.apache.tools.ant.taskdefs.optional.EchoProperties
splash=org.apache.tools.ant.taskdefs.optional.splash.SplashTask

# deprecated ant tasks (kept for back compatibility)
starteam=org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut


+ 140
- 0
src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashScreen.java View File

@@ -0,0 +1,140 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

package org.apache.tools.ant.taskdefs.optional.splash;

import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class SplashScreen extends JWindow implements ActionListener, BuildListener {

private JLabel text;
private JProgressBar pb;
private int total;
private final int min = 0;
private final int max = 200;

public SplashScreen(String msg) {
init(null);
setText(msg);
}
public SplashScreen(ImageIcon img) {
init(img);
}

protected void init(ImageIcon img) {
JPanel pan = (JPanel)getContentPane();
JLabel piccy;
if(img == null ) {
piccy = new JLabel();
} else {
piccy = new JLabel(img);
}
piccy.setBorder(BorderFactory.createLineBorder(Color.black,1));
text = new JLabel("Building....", JLabel.CENTER);
text.setFont(new Font("Sans-Serif", Font.BOLD, 12));
text.setBorder(BorderFactory.createEtchedBorder());

pb = new JProgressBar(min, max);
pb.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
JPanel pan2 = new JPanel();
pan2.setLayout(new BorderLayout());

pan2.add(text,BorderLayout.NORTH);
pan2.add(pb,BorderLayout.SOUTH);

pan.setLayout(new BorderLayout());
pan.add(piccy, BorderLayout.CENTER);
pan.add(pan2, BorderLayout.SOUTH);

pan.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

pack();

Dimension size = getSize();
Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
int x = (scr.width - size.width) /2;
int y = (scr.height - size.height) /2;
setBounds(x,y,size.width, size.height);
}

public void setText(String txt) {
text.setText(txt);
}

public void actionPerformed(ActionEvent a) {
if(total < max) {
total++;
} else {
total = min;
}
pb.setValue(total);
}

public void buildStarted(BuildEvent event){ actionPerformed(null);}
public void buildFinished(BuildEvent event){actionPerformed(null);}
public void targetStarted(BuildEvent event){actionPerformed(null);}
public void targetFinished(BuildEvent event){actionPerformed(null);}
public void taskStarted(BuildEvent event){actionPerformed(null);}
public void taskFinished(BuildEvent event){actionPerformed(null);}
public void messageLogged(BuildEvent event){actionPerformed(null);}
}


+ 201
- 0
src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java View File

@@ -0,0 +1,201 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

package org.apache.tools.ant.taskdefs.optional.splash;

import javax.swing.ImageIcon;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;

import java.io.*;
import java.net.*;

public class SplashTask extends Task {

private String imgurl = null;
private String proxy = null;
private String user = null;
private String password = null;
private String port = "80";
private int showDuration = 5000;
private boolean useProxy = false;

private static SplashScreen splash = null;

public void setImageURL(String imgurl) {
this.imgurl = imgurl;
}
public void setUseproxy(boolean useProxy) {
this.useProxy = useProxy;
}
public void setProxy(String proxy){
this.proxy = proxy;
}
public void setPort(String port){
this.port = port;
}
public void setUser(String user){
this.user = user;
}
public void setPassword(String password){
this.password = password;
}
public void setShowduration(int duration) {
this.showDuration = duration;
}

public void execute() throws BuildException {
if (splash != null ) {
splash.setVisible(false);
getProject().removeBuildListener(splash);
splash.dispose();
splash = null;
}
log("Creating new SplashScreen", Project.MSG_VERBOSE);
InputStream in = null;

if (imgurl != null) {
try{
URLConnection conn = null;
if(useProxy &&
(proxy != null && proxy.length() > 0) &&
(port != null && port.length() > 0)) {
log("Using proxied Connection", Project.MSG_DEBUG);
System.getProperties().put("http.proxySet", "true");
System.getProperties().put("http.proxyHost", proxy);
System.getProperties().put("http.proxyPort", port);
URL url = new URL(imgurl);
conn = url.openConnection();
if (user != null && user.length() > 0) {
String encodedcreds =
new sun.misc.BASE64Encoder().encode((new String(user+":"+password)).getBytes());
conn.setRequestProperty("Proxy-Authorization",
encodedcreds);
}
} else {
System.getProperties().put("http.proxySet", "false");
System.getProperties().put("http.proxyHost", "");
System.getProperties().put("http.proxyPort", "");
log("Using Direction HTTP Connection", Project.MSG_DEBUG);
URL url = new URL(imgurl);
conn = url.openConnection();
}
conn.setDoInput(true);
conn.setDoOutput(false);
in = conn.getInputStream();

// Catch everything - some of the above return nulls, throw exceptions or generally misbehave
// in the event of a problem etc
} catch(Throwable ioe) {
log("Unable to download image, trying default Ant Logo", Project.MSG_DEBUG);
log("(Exception was \""+ioe.getMessage()+"\"", Project.MSG_DEBUG);
}
}

if (in == null) {
in = SplashTask.class.getClassLoader().getResourceAsStream("images/ant_logo_large.gif");
}

if(in != null) {
DataInputStream din = new DataInputStream(in);
boolean success = false;
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int data;
while((data = din.read()) != -1) {
bout.write((byte)data);
}
log("Got ByteArray, creating splash", Project.MSG_DEBUG);
ImageIcon img = new ImageIcon(bout.toByteArray());
splash = new SplashScreen(img);
success = true;
} catch(Exception e) {
throw new BuildException(e);
} finally {
try {
din.close();
} catch (IOException ioe) {
// swallow if there was an error before so that
// original error will be passed up
if (success) {
throw new BuildException(ioe);
}
}
}
} else {
splash = new SplashScreen("Image Unavailable.");
}

splash.setVisible(true);
splash.toFront();
getProject().addBuildListener(splash);
try {
Thread.currentThread().sleep(showDuration);
} catch (InterruptedException e) {
}
}
}

Loading…
Cancel
Save