package com.digi.config.util; import java.awt.Cursor; import java.util.Stack; import java.awt.Component; import javax.swing.JLabel; /** * This class is used for putting up the busy cursor when in gui mode */ public class Busy { private static StatusDisplay guiComponent =null; private static Stack messages =new Stack(); private static String initialMsg =""; /** * This method registers the GUI Component that the busy cursor is to be * displayed in. This should be done once at the beginning of the application *

* @param theComponent the gui component to show the busy cursor and status text (implements * the StatusDisplay interface. */ public static void registerGUIComponent(StatusDisplay theComponent) { guiComponent=theComponent; // Finish this... // provide support such that if no gui component is passed in, then we put up // a temporary busy dialog that informs the user that work is in progress and // what the current message is. } /** * This method turns on the busy cursor. If the cursor is already * on, it bumps a count of the number of busy sections. *

* Note: If no component is registered, then this method does nothing. */ public static void begin(String msg) { try { String lastMsg=""; // if Just turning busy, turn on busy cursor if (messages.isEmpty()) { if (guiComponent!=null) { initialMsg=guiComponent.getStatusText(); lastMsg=initialMsg; } } else { lastMsg=(String)messages.peek(); } // Use message passed in. If none passed in, then use previous busy message if ((msg==null)||(msg.trim().length()==0)) { msg=lastMsg; } // push this message on the message stack && update the message area messages.push(msg); if (guiComponent!=null) { guiComponent.updateStatus(true, msg); } } catch (Exception e) { // finish this... msg work SystemLog.log("Internal Error: ending busy cursor"); SystemLog.log(e); } } public static void begin() { begin(null); } /** * This method decrements the count of busy sections by one. When the count reaches * zero, this method turns off the busy cursor. *

* Note: If no component is registered, then this method does nothing. */ public static void end() { String lastMsg=""; try { messages.pop(); if (messages.isEmpty()) { lastMsg=initialMsg; } else { lastMsg=(String)messages.peek(); } } catch (Exception e) { // finish this... msg work SystemLog.log("Internal Error: ending busy cursor"); SystemLog.log(e); } if (guiComponent!=null) { guiComponent.updateStatus(false, lastMsg); } } }