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