KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.*;
18 import java.awt.*;
19 import java.awt.event.*;
20 import java.sql.*;
21
22 import org.compiere.util.*;
23 import org.compiere.plaf.*;
24 import org.compiere.swing.*;
25
26 /**
27  * Status Bar
28  *
29  * @author Jorg Janke
30  * @version $Id: StatusBar.java,v 1.10 2002/09/03 05:11:09 jjanke Exp $
31  */

32 public class StatusBar extends CPanel
33 {
34     /**
35      * Standard Status Bar
36      */

37     public StatusBar()
38     {
39         this(false);
40     } // StatusBar
41

42     /**
43      * Status Bar with additional info
44      * @param withInfo with info
45      */

46     public StatusBar (boolean withInfo)
47     {
48         super();
49         try
50         {
51             jbInit();
52         }
53         catch (Exception JavaDoc e)
54         {}
55         this.setName("statusBar");
56         if (!withInfo)
57             infoLine.setVisible(false);
58     } // StatusBar
59

60     private BorderLayout mainLayout = new BorderLayout();
61     private JLabel statusLine = new JLabel();
62     private JLabel statusDB = new JLabel();
63     private JLabel infoLine = new JLabel();
64     //
65
private boolean mt_error;
66     private String JavaDoc mt_text;
67     //
68
private String JavaDoc m_text;
69     private Timestamp m_created;
70     private Object JavaDoc m_createdBy;
71     private Timestamp m_updated;
72     private Object JavaDoc m_updatedBy;
73     private String JavaDoc m_info;
74
75     /**
76      * Static Init
77      * @throws Exception
78      */

79     private void jbInit() throws Exception JavaDoc
80     {
81         statusLine.setBorder(BorderFactory.createEtchedBorder());
82         statusLine.setText("statusLine");
83         statusLine.setOpaque(false);
84         statusDB.setForeground(Color.blue);
85         statusDB.setBorder(BorderFactory.createEtchedBorder());
86         statusDB.setText("#");
87         statusDB.setOpaque(false);
88         statusDB.addMouseListener(new StatusBar_mouseAdapter(this));
89         this.setLayout(mainLayout);
90         infoLine.setFont(CompierePLAF.getFont_Label());
91         infoLine.setBorder(BorderFactory.createRaisedBevelBorder());
92         infoLine.setHorizontalAlignment(SwingConstants.CENTER);
93         infoLine.setHorizontalTextPosition(SwingConstants.CENTER);
94         infoLine.setText("info");
95         mainLayout.setHgap(2);
96         mainLayout.setVgap(2);
97         this.add(statusLine, BorderLayout.CENTER);
98         this.add(statusDB, BorderLayout.EAST);
99         this.add(infoLine, BorderLayout.NORTH);
100     } // jbInit
101

102     /*************************************************************************/
103
104     /**
105      * Set Standard Status Line (non error)
106      * @param text text
107      */

108     public void setStatusLine (String JavaDoc text)
109     {
110         if (text == null)
111             setStatusLine("", false);
112         else
113             setStatusLine(text, false);
114     } // setStatusLine
115

116     /**
117      * Set Status Line
118      * @param text text
119      * @param error error
120      */

121     public void setStatusLine (String JavaDoc text, boolean error)
122     {
123         mt_error = error;
124         mt_text = text;
125         if (mt_error)
126             statusLine.setForeground(CompierePLAF.getTextColor_Issue());
127         else
128             statusLine.setForeground(CompierePLAF.getTextColor_OK());
129         statusLine.setText(" " + mt_text);
130         //
131
Thread.yield();
132     } // setStatusLine
133

134     /**
135      * Get Status Line text
136      * @return StatusLine text
137      */

138     public String JavaDoc getStatusLine ()
139     {
140         return statusLine.getText().trim();
141     } // setStatusLine
142

143     /**
144      * Set ToolTip of StatusLine
145      * @param tip tip
146      */

147     public void setStatusToolTip (String JavaDoc tip)
148     {
149         statusLine.setToolTipText(tip);
150     } // setStatusToolTip
151

152     /**
153      * Set Status DB Info
154      * @param text text
155      * @param created created
156      * @param createdBy breated by
157      * @param updated updated
158      * @param updatedBy updated by
159      * @param info info
160      */

161     public void setStatusDB (String JavaDoc text, Timestamp created,
162         Object JavaDoc createdBy, Timestamp updated, Object JavaDoc updatedBy, String JavaDoc info)
163     {
164     // Log.trace(Log.l2_Sub, "StatusBar.setStatusDB - " + text + " - " + created + "/" + createdBy);
165
if (text == null || text.length() == 0)
166         {
167             statusDB.setText("");
168             statusDB.setVisible(false);
169         }
170         else
171         {
172             StringBuffer JavaDoc sb = new StringBuffer JavaDoc (" ");
173             sb.append(text).append(" ");
174             statusDB.setText(sb.toString());
175             if (!statusDB.isVisible())
176                 statusDB.setVisible(true);
177         }
178
179         // Save
180
m_text = text;
181         m_created = created;
182         m_createdBy = createdBy;
183         m_updated = updated;
184         m_updatedBy = updatedBy;
185         m_info = info;
186     } // setStatusDB
187

188     /**
189      * Set Status DB Info
190      * @param text text
191      */

192     public void setStatusDB (String JavaDoc text)
193     {
194         setStatusDB (text, null, null, null, null, null);
195     } // setStatusDB
196

197     /**
198      * Set Status DB Info
199      * @param no no
200      */

201     public void setStatusDB (int no)
202     {
203         setStatusDB (String.valueOf(no), null, null, null, null, null);
204     } // setStatusDB
205

206     /**
207      * Set Info Line
208      * @param text text
209      */

210     public void setInfo (String JavaDoc text)
211     {
212         if (!infoLine.isVisible())
213             infoLine.setVisible(true);
214         infoLine.setText(text);
215     } // setInfo
216

217     /**
218      * Add Component to East of StatusBar
219      * @param component component
220      */

221     public void addStatusComponent (JComponent component)
222     {
223         this.add(component, BorderLayout.EAST);
224     } // addStatusComponent
225

226     /**
227      * Show WHO
228      * @param e event
229      */

230     void mouseClicked(MouseEvent e)
231     {
232         Log.trace(Log.l2_Sub, "StatusBar.mouseClicked - WHO");
233         if (m_created == null && m_updated == null)
234             return;
235
236         // Get Person Info
237
String JavaDoc createdBy = null;
238         String JavaDoc updatedBy = null;
239         int createdByint = 0;
240         if (m_createdBy != null)
241             createdByint = Integer.parseInt(m_createdBy.toString());
242         int updatedByint = 0;
243         if (m_updatedBy != null)
244             updatedByint = Integer.parseInt(m_updatedBy.toString());
245         String JavaDoc SQL = "SELECT AD_User_ID, Name FROM AD_User WHERE AD_User_ID=? OR AD_User_ID=?";
246         try
247         {
248             PreparedStatement pstmt = DB.prepareStatement(SQL);
249             pstmt.setInt(1, createdByint);
250             pstmt.setInt(2, updatedByint);
251             ResultSet rs = pstmt.executeQuery();
252             while (rs.next())
253             {
254                 if (rs.getInt(1) == createdByint)
255                     createdBy = rs.getString(2);
256                 else
257                     updatedBy = rs.getString(2);
258             }
259             rs.close();
260             pstmt.close();
261         }
262         catch (SQLException e1)
263         {
264             Log.error ("StatusBar.mouseClicked", e1);
265         }
266
267         if (createdByint == updatedByint)
268             updatedBy = createdBy;
269
270         // Format String
271
StringBuffer JavaDoc msg = new StringBuffer JavaDoc();
272         SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime);
273         msg.append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(createdBy);
274         msg.append(" - ").append(format.format(m_created)).append("\n");
275         if (!m_created.equals(m_updated) || createdByint != updatedByint)
276         {
277             msg.append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(updatedBy);
278             msg.append(" - ").append(format.format(m_updated)).append("\n");
279         }
280         if (m_info != null && m_info.length() > 0)
281             msg.append("\n(").append(m_info).append(")\n");
282
283         // display who
284
JOptionPane.showMessageDialog(null,
285                 msg.toString(), // message
286
Msg.getMsg(Env.getCtx(), "Who") + m_text, // title
287
JOptionPane.INFORMATION_MESSAGE);
288     } // addStatusComponent
289

290 } // StatusBar
291

292
293 /*****************************************************************************/
294
295 /**
296  * Mouse Adapter for Status Bar (statusDB)
297  */

298 class StatusBar_mouseAdapter extends java.awt.event.MouseAdapter JavaDoc
299 {
300     private StatusBar adaptee;
301
302     /**
303      * Constructor
304      * @param adaptee adaptee
305      */

306     StatusBar_mouseAdapter(StatusBar adaptee)
307     {
308         this.adaptee = adaptee;
309     }
310
311     /**
312      * Click
313      * @param e event
314      */

315     public void mouseClicked(MouseEvent e)
316     {
317         adaptee.mouseClicked(e);
318     }
319 } // StatusBar_mouseAdapter
320
Popular Tags