1   /*
2    *  Copyright (c) 1998-2005, The University of Sheffield.
3    *
4    *  This file is part of GATE (see http://gate.ac.uk/), and is free
5    *  software, licenced under the GNU Library General Public License,
6    *  Version 2, June 1991 (in the distribution as file licence.html,
7    *  and also available at http://gate.ac.uk/gate/licence.html).
8    *
9    *  Valentin Tablan 28/01/2001
10   *
11   *  $Id: Splash.java,v 1.11 2005/01/11 13:51:34 ian Exp $
12   *
13   */
14  package gate.gui;
15  
16  import java.awt.*;
17  
18  import javax.swing.*;
19  import javax.swing.border.EtchedBorder;
20  
21  /**
22   * A splash screen.
23   * A splash screen is an image that appears on the screen while an application
24   * initialises. The implementation uses a {@link java.awt.Window} (a Frame with
25   * no decorations such as bar or buttons) and can either display a JComponent
26   * as content or an image.
27   */
28  public class Splash extends JWindow {
29  
30    /**
31     * Constructor from owner and content.
32     */
33    public Splash(Window owner, JComponent content) {
34      super(owner);
35      getContentPane().setLayout(new BorderLayout());
36      content.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
37      getContentPane().add(content, BorderLayout.CENTER);
38      validate();
39      pack();
40    }// public Splash(Window owner, JComponent content)
41  
42    /**
43     * Contructor from image.
44     */
45    public Splash(String imageResourcePath) {
46      this(null, imageResourcePath);
47    }// public Splash(String imageResourcePath)
48  
49    /**
50     * Constructor from content.
51     */
52    public Splash(JComponent content) {
53      super();
54      getContentPane().setLayout(new BorderLayout());
55      content.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
56      getContentPane().add(content, BorderLayout.CENTER);
57      validate();
58      pack();
59    }// public Splash(JComponent content)
60  
61    /**
62     * Constructor from owner and image.
63     */
64    public Splash(Window owner, String imageResourcePath) {
65      this(owner,
66          new JLabel(new ImageIcon(Splash.class.getResource(imageResourcePath))));
67    }// public Splash(Window owner, String imageResourcePath)
68  
69    /**
70     * Displays the splash screen centered in the owner's space or centered on
71     * the screen if no owner or owner not shown.
72     */
73    public void showSplash(){
74      Dimension ownerSize;
75      Point ownerLocation;
76      if(getOwner() == null){
77        ownerSize = Toolkit.getDefaultToolkit().getScreenSize();
78        ownerLocation = new Point(0, 0);
79      }else{
80        ownerSize = getOwner().getSize();
81        ownerLocation = getOwner().getLocation();
82        if(ownerSize.height == 0 ||
83           ownerSize.width == 0 ||
84           !getOwner().isVisible()){
85          ownerSize = Toolkit.getDefaultToolkit().getScreenSize();
86          ownerLocation = new Point(0, 0);
87        }
88      }
89      //Center the window
90      Dimension frameSize = getSize();
91      if (frameSize.height > ownerSize.height)
92        frameSize.height = ownerSize.height;
93      if (frameSize.width > ownerSize.width)
94        frameSize.width = ownerSize.width;
95      setLocation(ownerLocation.x + (ownerSize.width - frameSize.width) / 2,
96                  ownerLocation.y + (ownerSize.height - frameSize.height) / 2);
97      super.setVisible(true);
98    }// public void show()
99  
100 }// class Splash