001 /*
002 * WaitDialog.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Valentin Tablan, 12/07/2000
013 *
014 * $Id: WaitDialog.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.swing;
018
019 import java.awt.*;
020
021 import javax.swing.*;
022
023 /**
024 * A small window used to show messages to the user during processing.
025 * This component is intended as a nicer alternative
026 * to a status bar/progress bar.
027 * The window has its own thread for updating the animated pictures displayed.
028 *
029 */
030 public class WaitDialog extends JWindow implements Runnable {
031
032 /** Debug flag
033 */
034 private static final boolean DEBUG = false;
035
036 /** *
037 */
038 Box centerBox;
039
040 /** */
041 public WaitDialog(Frame frame, String title) {
042 super(frame);
043 //this.icon = new ImageIcon(ClassLoader.getSystemResource(
044 // "gate/resources/img/working"));
045 // use the cached version from MainFrame
046 this.icon = gate.gui.MainFrame.getIcon("working");
047 this.frame = frame;
048 try {
049 jbInit();
050 pack();
051 }
052 catch(Exception ex) {
053 ex.printStackTrace();
054 }
055 }
056
057 /**
058 * Shows the window containing labels for the texts provided as attributes.
059 *
060 * @param texts
061 */
062 public synchronized void showDialog(String[] texts) {
063 centerBox.removeAll();
064
065 for(int i =0; i < texts.length; i++){
066 centerBox.add(new JLabel(texts[i]));
067 }
068
069 centerBox.validate();
070 pack();
071 /*
072 Point loc = frame.getLocation();
073 loc.move(frame.getSize().width - getSize().width / 2 ,
074 frame.getSize().height - getSize().height /2 );
075 setLocation(loc);
076 */
077 stop = false;
078 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
079 this,
080 "WaitDialog1");
081 thread.setPriority(Thread.MAX_PRIORITY);
082 thread.start();
083 setVisible(true);
084 }
085
086 /**
087 * Shows the window containing the components provided as attributes.
088 *
089 * @param components
090 */
091 public synchronized void showDialog(Component[] components) {
092 centerBox.removeAll();
093 for(int i =0; i < components.length; i++){
094 centerBox.add(components[i]);
095 }
096 centerBox.validate();
097 pack();
098 /*
099 Point loc = frame.getLocation();
100 setLocation(loc.x + (frame.getSize().width - getSize().width) / 2 ,
101 loc.y + (frame.getSize().height - getSize().height) /2);
102 */
103 stop = false;
104 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
105 this,
106 "WaitDialog2");
107 thread.setPriority(Thread.MAX_PRIORITY);
108 thread.start();
109 setVisible(true);
110 }
111
112 /** */
113 void jbInit() throws Exception {
114 JPanel centerPanel = new JPanel();
115 Container content = getContentPane();
116 centerBox = Box.createVerticalBox();
117 centerPanel.setLayout(borderLayout1);
118 //centerPanel.setBorder(new LineBorder(Color.darkGray, 2));
119 // centerPanel.setBackground(Color.white);
120 // centerBox.setBackground(Color.white);
121 picture = new JLabel(icon);
122 picture.setOpaque(false);
123 centerPanel.add(centerBox, BorderLayout.CENTER);
124 centerPanel.add(picture, BorderLayout.WEST);
125 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.NORTH);
126 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.SOUTH);
127 centerPanel.add(Box.createHorizontalStrut(8), BorderLayout.EAST);
128 getContentPane().add(centerPanel, BorderLayout.CENTER);
129 centerPanel.setOpaque(false);
130 }
131
132 /**
133 * Hides the window.
134 *
135 */
136 public void goAway() {
137 stop = true;
138 }
139
140 /** *
141 */
142 public void run() {
143 while(!stop){
144 try{
145 Thread.sleep(300);
146 centerBox.validate();
147 pack();
148 /*
149 Point loc = frame.getLocation();
150 setLocation(loc.x + (frame.getSize().width - getSize().width) / 2 ,
151 loc.y + (frame.getSize().height - getSize().height) /2);
152 */
153 picture.paintImmediately(picture.getVisibleRect());
154 }catch(InterruptedException ie){}
155 }
156 this.setVisible(false);
157 }
158
159
160 boolean stop = false;
161
162 BorderLayout borderLayout1 = new BorderLayout();
163
164 Frame frame;
165
166 JLabel picture;
167
168 Icon icon;
169
170 } // class WaitDialog
|