1
14 package gate.gui;
15
16 import java.awt.*;
17
18 import javax.swing.*;
19 import javax.swing.border.EtchedBorder;
20
21
28 public class Splash extends JWindow {
29
30
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 }
42
45 public Splash(String imageResourcePath) {
46 this(null, imageResourcePath);
47 }
49
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 }
61
64 public Splash(Window owner, String imageResourcePath) {
65 this(owner,
66 new JLabel(new ImageIcon(Splash.class.getResource(imageResourcePath))));
67 }
69
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 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 }
100 }