xref: /trunk/main/framework/qa/complex/loadAllDocuments/StatusIndicator.java (revision c64e43daf4d868cd69bdcfc2b096656257af5a06)
176b6b121SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
376b6b121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
476b6b121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
576b6b121SAndrew Rist  * distributed with this work for additional information
676b6b121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
776b6b121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
876b6b121SAndrew Rist  * "License"); you may not use this file except in compliance
976b6b121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1176b6b121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1376b6b121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1476b6b121SAndrew Rist  * software distributed under the License is distributed on an
1576b6b121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1676b6b121SAndrew Rist  * KIND, either express or implied.  See the License for the
1776b6b121SAndrew Rist  * specific language governing permissions and limitations
1876b6b121SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2076b6b121SAndrew Rist  *************************************************************/
2176b6b121SAndrew Rist 
22cdf0e10cSrcweir package complex.loadAllDocuments;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // __________ Imports __________
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // structs, const, ...
27cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // exceptions
30cdf0e10cSrcweir import com.sun.star.uno.Exception;
31cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // interfaces
34cdf0e10cSrcweir import com.sun.star.task.XStatusIndicator;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // helper
37cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // others
40cdf0e10cSrcweir //import java.lang.*;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir // __________ Implementation __________
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /**
45cdf0e10cSrcweir  * Implemets a simple status indicator, which
46cdf0e10cSrcweir  * provide informations about state of a load request.
47cdf0e10cSrcweir  * It can be used as an argument e.g. for loadComponentFromURL().
48cdf0e10cSrcweir  */
49cdf0e10cSrcweir public class StatusIndicator implements com.sun.star.task.XStatusIndicator
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     // ____________________
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /**
54cdf0e10cSrcweir      * @const SHOWSTATUS_NO         don't show the status - but save information about using of this indicator object
5507a3d7f1SPedro Giffuni      * @const SHOWSTATUS_LOG        the possible set protocol object will be used (it covers STDOUT, STDERR automatically too)
56cdf0e10cSrcweir      * @const SHOWSTATUS_DIALOG     the status will be shown inside a java dialog
57cdf0e10cSrcweir      * @const SHOWSTATUS_LINK       the status will be notified to interested listener (one listener only!)
58cdf0e10cSrcweir      */
59cdf0e10cSrcweir     public static final int SHOWSTATUS_NO       =   0;
60cdf0e10cSrcweir     public static final int SHOWSTATUS_LOG      =   1;
61cdf0e10cSrcweir     public static final int SHOWSTATUS_DIALOG   =   4;
62cdf0e10cSrcweir     public static final int SHOWSTATUS_LINK     =   8;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // ____________________
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     /**
67cdf0e10cSrcweir      * @member m_sText      text, which describe the current status
68cdf0e10cSrcweir      * @member m_nRange     max value for any progress
69cdf0e10cSrcweir      * @member m_nValue     the progress value
70cdf0e10cSrcweir      * @member m_nOut       regulate, how the status will be shown
71cdf0e10cSrcweir      * @member m_aProtocol  used for logging and transport information about used interface of this object
72cdf0e10cSrcweir      */
73cdf0e10cSrcweir     private String          m_sText     ;
74cdf0e10cSrcweir     private int             m_nRange    ;
75cdf0e10cSrcweir     private int             m_nValue    ;
76cdf0e10cSrcweir     private int             m_nOut      ;
77cdf0e10cSrcweir //    private Protocol        m_aProtocol ;
78cdf0e10cSrcweir     private boolean         m_bWasUsed  ;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     // ____________________
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /**
83cdf0e10cSrcweir      * ctor
84cdf0e10cSrcweir      * It's initialize an object of this class with default values.
85cdf0e10cSrcweir      */
StatusIndicator( int nOut)86cdf0e10cSrcweir     public StatusIndicator( int nOut)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         m_sText     = new String()  ;
89cdf0e10cSrcweir         m_nRange    = 100           ;
90cdf0e10cSrcweir         m_nValue    = 0             ;
91cdf0e10cSrcweir         m_nOut      = nOut          ;
92cdf0e10cSrcweir         //m_aProtocol = aProtocol     ;
93cdf0e10cSrcweir         m_bWasUsed  = false;
94cdf0e10cSrcweir //        aProtocol.resetUsingState();
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // ____________________
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /**
100cdf0e10cSrcweir      * It starts the progress and set the initial text and range.
101cdf0e10cSrcweir      *
102cdf0e10cSrcweir      * @param sText
103cdf0e10cSrcweir      *          the initial text for showing
104cdf0e10cSrcweir      *
105cdf0e10cSrcweir      * @param nRange
106cdf0e10cSrcweir      *          the new range for following progress
107cdf0e10cSrcweir      */
start( String sText, int nRange )108cdf0e10cSrcweir     public void start( /*IN*/String sText, /*IN*/int nRange )
109cdf0e10cSrcweir     {
110cdf0e10cSrcweir         synchronized(this)
111cdf0e10cSrcweir         {
112cdf0e10cSrcweir             //m_aProtocol.log("start("+sText+","+nRange+")\n");
113cdf0e10cSrcweir             m_bWasUsed = true;
114cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             m_sText  = sText ;
117cdf0e10cSrcweir             m_nRange = nRange;
118cdf0e10cSrcweir             m_nValue = 0     ;
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir         impl_show();
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // ____________________
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     /**
126cdf0e10cSrcweir      * Finish the progress and reset internal members.
127cdf0e10cSrcweir      */
end()128cdf0e10cSrcweir     public void end()
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         synchronized(this)
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             //m_aProtocol.log("end()\n");
133cdf0e10cSrcweir             m_bWasUsed = true;
134cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             m_sText  = new String();
137cdf0e10cSrcweir             m_nRange = 100;
138cdf0e10cSrcweir             m_nValue = 0;
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         impl_show();
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // ____________________
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     /**
146cdf0e10cSrcweir      * Set the new description text.
147cdf0e10cSrcweir      *
148cdf0e10cSrcweir      * @param sText
149cdf0e10cSrcweir      *          the new text for showing
150cdf0e10cSrcweir      */
setText( String sText )151cdf0e10cSrcweir     public void setText( /*IN*/String sText )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         synchronized(this)
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             //m_aProtocol.log("setText("+sText+")\n");
156cdf0e10cSrcweir             m_bWasUsed = true;
157cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             m_sText = sText;
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir         impl_show();
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // ____________________
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     /**
167cdf0e10cSrcweir      * Set the new progress value.
168cdf0e10cSrcweir      *
169cdf0e10cSrcweir      * @param nValue
170cdf0e10cSrcweir      *          the new progress value
171cdf0e10cSrcweir      *          Must fit the range!
172cdf0e10cSrcweir      */
setValue( int nValue )173cdf0e10cSrcweir     public void setValue( /*IN*/int nValue )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         synchronized(this)
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             //m_aProtocol.log("setValue("+nValue+")\n");
178cdf0e10cSrcweir             m_bWasUsed = true;
179cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir             if (nValue<=m_nRange)
182cdf0e10cSrcweir                 m_nValue = nValue;
183cdf0e10cSrcweir         }
184cdf0e10cSrcweir         impl_show();
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // ____________________
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     /**
190cdf0e10cSrcweir      * Reset text and progress value to her defaults.
191cdf0e10cSrcweir      */
reset()192cdf0e10cSrcweir     public void reset()
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         synchronized(this)
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             //m_aProtocol.log("reset()\n");
197cdf0e10cSrcweir             m_bWasUsed = true;
198cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir             m_sText = new String();
201cdf0e10cSrcweir             m_nValue = 0;
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir         impl_show();
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     // ____________________
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     /**
209cdf0e10cSrcweir      * Internal helper to show the status.
210cdf0e10cSrcweir      * Currently it's implement as normal text out on stdout.
211*c64e43daSmseidel      * But of course other things are possible here too.
212cdf0e10cSrcweir      * e.g. a dialog
213cdf0e10cSrcweir      */
impl_show()214cdf0e10cSrcweir     private void impl_show()
215cdf0e10cSrcweir     {
216cdf0e10cSrcweir /*        synchronized(this)
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             if ((m_nOut & SHOWSTATUS_LOG) == SHOWSTATUS_LOG)
219cdf0e10cSrcweir                 //m_aProtocol.log("\t["+m_nValue+"/"+m_nRange+"] "+m_sText+"\n");
220cdf0e10cSrcweir 
221cdf0e10cSrcweir             //if ((m_nOut & SHOWSTATUS_DIALOG) == SHOWSTATUS_DIALOG)
222cdf0e10cSrcweir                 // not supported yet!
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             //if ((m_nOut & SHOWSTATUS_LINK) == SHOWSTATUS_LINK)
225cdf0e10cSrcweir                 // not supported yet!
226cdf0e10cSrcweir         } */
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir 
wasUsed()229cdf0e10cSrcweir     public boolean wasUsed() {
230cdf0e10cSrcweir         return m_bWasUsed;
231cdf0e10cSrcweir     }
232cdf0e10cSrcweir }
233