| Splash |

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

| Splash |