KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > Waiting


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import javax.swing.*;
17 import java.awt.*;
18 import java.awt.event.*;
19
20 import org.compiere.plaf.*;
21 import org.compiere.swing.*;
22
23 import org.compiere.util.*;
24
25 /**
26  * Waiting Dialog
27  *
28  * @author Jorg Janke
29  * @version $Id: Waiting.java,v 1.6 2003/02/14 06:44:13 jjanke Exp $
30  */

31 public class Waiting extends JDialog implements ActionListener
32 {
33     /**
34      * Constructor - non nodal as otherwise process is blocked
35      * @param owner
36      * @param text Message to be displayed
37      * @param canNotWait user can continue with other work
38      * @param timer timer ticks (seconds) - if 0 then 10
39      */

40     public Waiting (Frame owner, String JavaDoc text, boolean canNotWait, int timer)
41     {
42         super(owner, Msg.getMsg(Env.getCtx(), "Processing"));
43         init (text, canNotWait, timer);
44     } // Waiting
45

46     /**
47      * Constructor - non modal as otherwise process is blocked
48      * @param owner
49      * @param text Message to be displayed
50      * @param canNotWait user can continue with other work
51      * @param timer timer ticks (seconds) - if 0 then 10
52      */

53     public Waiting (Dialog owner, String JavaDoc text, boolean canNotWait, int timer)
54     {
55         super(owner, Msg.getMsg(Env.getCtx(), "Processing"));
56         init (text, canNotWait, timer);
57     } // Waiting
58

59     /**
60      * Common Initialize routine - does not create if timer == 1
61      * @param text Message to be displayed
62      * @param canNotWait user can continue with other work
63      * @param timer timer ticks (seconds) - if less than 5 then 10
64      */

65     private void init (String JavaDoc text, boolean canNotWait, int timer)
66     {
67         Log.trace(Log.l6_Database, "Waiting.init", text + " - Sec=" + timer);
68         // don't show if 1 sec average
69
if (timer == 1)
70             return;
71
72         try
73         {
74             jbInit();
75             setText (text);
76             if (!canNotWait)
77                 bDoNotWait.setVisible(false);
78         }
79         catch(Exception JavaDoc e)
80         {
81             Log.error ("Waiting", e);
82         }
83         // set progress Bar
84
progressBar.setMinimum(0);
85         progressBar.setMaximum(timer < 5 ? 10 : timer); // min 2 seconds
86

87         // Timer
88
m_timer = new Timer (1000, this); // every second
89
m_timer.start();
90         AEnv.showCenterWindow(getOwner(), this);
91     } // init
92

93     private int m_timervalue = 0;
94     private Timer m_timer;
95
96     private CPanel southPanel = new CPanel();
97     private CButton bDoNotWait = new CButton();
98     private CLabel infoLabel = new CLabel();
99     private FlowLayout southLayout = new FlowLayout();
100     private CPanel mainPanel = new CPanel();
101     private JProgressBar progressBar = new JProgressBar();
102
103     /**
104      * Static Layout
105      * @throws Exception
106      */

107     private void jbInit() throws Exception JavaDoc
108     {
109         CompiereColor.setBackground(this);
110         this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
111         this.setResizable(false);
112         this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
113
114         this.getContentPane().add(Box.createVerticalStrut(8), BorderLayout.NORTH);
115         this.getContentPane().add(Box.createHorizontalStrut(8), BorderLayout.WEST);
116         this.getContentPane().add(Box.createVerticalStrut(8), BorderLayout.SOUTH);
117         this.getContentPane().add(Box.createHorizontalStrut(8), BorderLayout.EAST);
118         mainPanel.setLayout(new BorderLayout(5,5));
119         this.getContentPane().add(mainPanel, BorderLayout.CENTER);
120         //
121
infoLabel.setFont(new java.awt.Font JavaDoc("Dialog", 3, 14));
122         infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
123         infoLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
124         infoLabel.setIcon(Env.getImageIcon("C10030.gif"));
125         infoLabel.setIconTextGap(10);
126         mainPanel.add(infoLabel, BorderLayout.NORTH);
127         mainPanel.add(progressBar, BorderLayout.CENTER);
128         //
129
// bDoNotWait.setText(Msg.getMsg(Env.getCtx(), "DoNotWait"));
130
// bDoNotWait.setToolTipText(Msg.getMsg(Env.getCtx(), "DoNotWaitInfo"));
131
// bDoNotWait.addActionListener(this);
132
// southPanel.setLayout(southLayout);
133
// southPanel.add(bDoNotWait, null);
134
// mainPanel.add(southPanel, BorderLayout.SOUTH);
135
} // jbInit
136

137     /**
138      * Set Info Text
139      * @param text
140      */

141     public void setText (String JavaDoc text)
142     {
143         infoLabel.setText(text);
144     } // setText
145

146     /**
147      * ActionListener
148      * @param e
149      */

150     public void actionPerformed (ActionEvent e)
151     {
152         if (e.getSource() == bDoNotWait)
153             doNotWait();
154         //
155
progressBar.setValue(m_timervalue++);
156         if (m_timervalue > progressBar.getMaximum())
157             m_timervalue = progressBar.getMinimum();
158     // progressBar.setString(progressBar.getPercentComplete());
159
} // actionPerformed
160

161     /**
162      * Set Timer Estimate
163      * @param max Seconds
164      */

165     public void setTimerEstimate (int max)
166     {
167         progressBar.setMaximum(max);
168     } // setMaximum
169

170     /**
171      * User does not want to wait for result and continue with other worg
172      * Callback & dispose
173      */

174     public void doNotWait()
175     {
176         /** @todo callback */
177         dispose();
178     } // doNotWait
179

180     /**
181      * Dispose
182      */

183     public void dispose()
184     {
185         if (m_timer != null)
186             m_timer.stop();
187         m_timer = null;
188         super.dispose();
189     } // dispose
190

191 } // Waiting
192
Popular Tags