|
WaitDialog |
|
1 /* 2 * WaitDialog.java 3 * 4 * Copyright (c) 1998-2001, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Valentin Tablan, 12/07/2000 12 * 13 * $Id: WaitDialog.java,v 1.3 2001/05/16 14:26:28 valyt Exp $ 14 */ 15 16 package gate.swing; 17 18 import java.awt.*; 19 import javax.swing.*; 20 import javax.swing.border.*; 21 22 /** 23 * A small window used to show messages to the user during processing. 24 * This component is intended as a nicer alternative 25 * to a status bar/progress bar. 26 * The window has its own thread for updating the animated pictures displayed. 27 * 28 */ 29 public class WaitDialog extends JWindow implements Runnable { 30 31 /** Debug flag 32 */ 33 private static final boolean DEBUG = false; 34 35 /** * 36 */ 37 Box centerBox; 38 39 /** */ 40 public WaitDialog(Frame frame, String title) { 41 super(frame); 42 this.icon = new ImageIcon(ClassLoader.getSystemResource( 43 "gate/resources/img/working.gif")); 44 this.frame = frame; 45 try { 46 jbInit(); 47 pack(); 48 } 49 catch(Exception ex) { 50 ex.printStackTrace(); 51 } 52 } 53 54 /** 55 * Shows the window containing labels for the texts provided as attributes. 56 * 57 * @param texts 58 */ 59 public synchronized void showDialog(String[] texts) { 60 centerBox.removeAll(); 61 62 for(int i =0; i < texts.length; i++){ 63 centerBox.add(new JLabel(texts[i])); 64 } 65 66 centerBox.validate(); 67 pack(); 68 /* 69 Point loc = frame.getLocation(); 70 loc.move(frame.getSize().width - getSize().width / 2 , 71 frame.getSize().height - getSize().height /2 ); 72 setLocation(loc); 73 */ 74 stop = false; 75 Thread thread = new Thread(Thread.currentThread().getThreadGroup(), 76 this, 77 "WaitDialog1"); 78 thread.setPriority(Thread.MAX_PRIORITY); 79 thread.start(); 80 show(); 81 } 82 83 /** 84 * Shows the window containing the components provided as attributes. 85 * 86 * @param components 87 */ 88 public synchronized void showDialog(Component[] components) { 89 centerBox.removeAll(); 90 for(int i =0; i < components.length; i++){ 91 centerBox.add(components[i]); 92 } 93 centerBox.validate(); 94 pack(); 95 /* 96 Point loc = frame.getLocation(); 97 setLocation(loc.x + (frame.getSize().width - getSize().width) / 2 , 98 loc.y + (frame.getSize().height - getSize().height) /2); 99 */ 100 stop = false; 101 Thread thread = new Thread(Thread.currentThread().getThreadGroup(), 102 this, 103 "WaitDialog2"); 104 thread.setPriority(Thread.MAX_PRIORITY); 105 thread.start(); 106 show(); 107 } 108 109 /** */ 110 void jbInit() throws Exception { 111 JPanel centerPanel = new JPanel(); 112 Container content = getContentPane(); 113 centerBox = Box.createVerticalBox(); 114 centerPanel.setLayout(borderLayout1); 115 //centerPanel.setBorder(new LineBorder(Color.darkGray, 2)); 116 // centerPanel.setBackground(Color.white); 117 // centerBox.setBackground(Color.white); 118 picture = new JLabel(icon); 119 picture.setOpaque(false); 120 centerPanel.add(centerBox, BorderLayout.CENTER); 121 centerPanel.add(picture, BorderLayout.WEST); 122 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.NORTH); 123 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.SOUTH); 124 centerPanel.add(Box.createHorizontalStrut(8), BorderLayout.EAST); 125 getContentPane().add(centerPanel, BorderLayout.CENTER); 126 centerPanel.setOpaque(false); 127 } 128 129 /** 130 * Hides the window. 131 * 132 */ 133 public void goAway() { 134 stop = true; 135 } 136 137 /** * 138 */ 139 public void run() { 140 while(!stop){ 141 try{ 142 Thread.sleep(300); 143 centerBox.validate(); 144 pack(); 145 /* 146 Point loc = frame.getLocation(); 147 setLocation(loc.x + (frame.getSize().width - getSize().width) / 2 , 148 loc.y + (frame.getSize().height - getSize().height) /2); 149 */ 150 picture.paintImmediately(picture.getVisibleRect()); 151 }catch(InterruptedException ie){} 152 } 153 this.setVisible(false); 154 } 155 156 157 boolean stop = false; 158 159 BorderLayout borderLayout1 = new BorderLayout(); 160 161 Frame frame; 162 163 JLabel picture; 164 165 Icon icon; 166 167 } // class WaitDialog 168
|
WaitDialog |
|