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