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