tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / odk / examples / DevelopersGuide / OfficeDev / Linguistic / PropChgHelper.java
blob46fcff061a88e8c0cee2edd852656c7fc72d6698
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
37 import com.sun.star.linguistic2.XLinguServiceEventListener;
38 import com.sun.star.linguistic2.LinguServiceEvent;
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.beans.XPropertyChangeListener;
41 import com.sun.star.beans.PropertyChangeEvent;
42 import com.sun.star.lang.EventObject;
43 import com.sun.star.uno.XInterface;
45 import java.util.ArrayList;
47 public class PropChgHelper implements
48 XPropertyChangeListener,
49 XLinguServiceEventBroadcaster
51 private final XInterface xEvtSource;
52 private final String[] aPropNames;
53 private XPropertySet xPropSet;
54 private final ArrayList<XLinguServiceEventListener> aLngSvcEvtListeners;
56 public PropChgHelper(
57 XInterface xEvtSource,
58 String[] aPropNames )
60 this.xEvtSource = xEvtSource;
61 this.aPropNames = aPropNames;
62 xPropSet = null;
63 aLngSvcEvtListeners = new ArrayList<XLinguServiceEventListener>();
66 public XInterface GetEvtSource()
68 return xEvtSource;
71 public XPropertySet GetPropSet()
73 return xPropSet;
78 public void LaunchEvent( LinguServiceEvent aEvt )
80 int nCnt = aLngSvcEvtListeners.size();
81 for (int i = 0; i < nCnt; ++i)
83 XLinguServiceEventListener xLstnr =
84 aLngSvcEvtListeners.get(i);
85 if (xLstnr != null)
86 xLstnr.processLinguServiceEvent( aEvt );
90 public void AddAsListenerTo( XPropertySet xPropertySet )
92 // do not listen any longer to the old property set (if any)
93 RemoveAsListener();
95 // set new property set to be used and register as listener to it
96 xPropSet = xPropertySet;
97 if (xPropSet != null)
99 int nLen = aPropNames.length;
100 for (int i = 0; i < nLen; ++i)
102 if (aPropNames[i].length() != 0)
104 try {
105 xPropSet.addPropertyChangeListener(
106 aPropNames[i], this );
108 catch( Exception e ) {
115 private void RemoveAsListener()
117 if (xPropSet != null)
119 int nLen = aPropNames.length;
120 for (int i = 0; i < nLen; ++i)
122 if (aPropNames[i].length() != 0)
124 try {
125 xPropSet.removePropertyChangeListener(
126 aPropNames[i], this );
128 catch( Exception e ) {
133 xPropSet = null;
137 // __________ interface methods __________
140 // XEventListener
142 public void disposing( EventObject aSource )
143 throws com.sun.star.uno.RuntimeException
145 if (aSource.Source == xPropSet)
147 RemoveAsListener();
152 // XPropertyChangeListener
154 public void propertyChange( PropertyChangeEvent aEvt )
155 throws com.sun.star.uno.RuntimeException
157 // will be overridden in derived classes
161 // XLinguServiceEventBroadcaster
163 public boolean addLinguServiceEventListener(
164 XLinguServiceEventListener xListener )
165 throws com.sun.star.uno.RuntimeException
167 boolean bRes = false;
168 if (xListener != null)
170 bRes = aLngSvcEvtListeners.add( xListener );
172 return bRes;
175 public boolean removeLinguServiceEventListener(
176 XLinguServiceEventListener xListener )
177 throws com.sun.star.uno.RuntimeException
179 boolean bRes = false;
180 if (xListener != null)
182 int nIdx = aLngSvcEvtListeners.indexOf( xListener );
183 if (nIdx != -1)
185 aLngSvcEvtListeners.remove( nIdx );
186 bRes = true;
189 return bRes;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */