134dd1e25SAndrew Rist /**************************************************************
2*be8bac39Smseidel  *
334dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
534dd1e25SAndrew Rist  * distributed with this work for additional information
634dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
734dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*be8bac39Smseidel  *
1134dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*be8bac39Smseidel  *
1334dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist  * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
1734dd1e25SAndrew Rist  * specific language governing permissions and limitations
1834dd1e25SAndrew Rist  * under the License.
19*be8bac39Smseidel  *
2034dd1e25SAndrew Rist  *************************************************************/
2134dd1e25SAndrew Rist 
2234dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // base classes
25cdf0e10cSrcweir import com.sun.star.uno.XInterface;
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.uno.Type;
28cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
29cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // factories
32cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
33cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // graphics stuff
36cdf0e10cSrcweir import com.sun.star.drawing.*;
37cdf0e10cSrcweir import com.sun.star.awt.Point;
38cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
39cdf0e10cSrcweir import com.sun.star.awt.Size;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // chart stuff
42cdf0e10cSrcweir import com.sun.star.chart.*;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // property access
45cdf0e10cSrcweir import com.sun.star.beans.*;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // Add-In stuff
48cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
49cdf0e10cSrcweir import com.sun.star.util.XRefreshable;
50cdf0e10cSrcweir import com.sun.star.lang.XServiceName;
51cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
52cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // Exceptions
55cdf0e10cSrcweir import com.sun.star.uno.Exception;
56cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir import javax.swing.JOptionPane;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir public class JavaSampleChartAddIn extends WeakBase implements
61cdf0e10cSrcweir     XInitialization,
62cdf0e10cSrcweir     XRefreshable,
63cdf0e10cSrcweir     XDiagram,
64cdf0e10cSrcweir     XServiceName,
65cdf0e10cSrcweir     XServiceInfo
66cdf0e10cSrcweir {
JavaSampleChartAddIn()67cdf0e10cSrcweir     public JavaSampleChartAddIn()
68cdf0e10cSrcweir     {}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     // __________ interface methods __________
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // XInitialization
initialize( Object[] aArguments )73cdf0e10cSrcweir     public void initialize( Object[] aArguments )
74cdf0e10cSrcweir         throws Exception, RuntimeException
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         if( aArguments.length > 0 )
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             maChartDocument = (XChartDocument) UnoRuntime.queryInterface(
79cdf0e10cSrcweir                 XChartDocument.class, aArguments[ 0 ]);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir             XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface(
82cdf0e10cSrcweir                 XPropertySet.class, maChartDocument );
83cdf0e10cSrcweir             if( aDocProp != null )
84cdf0e10cSrcweir             {
85cdf0e10cSrcweir                 // set base diagram which will be extended in refresh()
86cdf0e10cSrcweir                 aDocProp.setPropertyValue( "BaseDiagram", "com.sun.star.chart.XYDiagram" );
87cdf0e10cSrcweir             }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             // get the draw page
90cdf0e10cSrcweir             XDrawPageSupplier aPageSupp = (XDrawPageSupplier) UnoRuntime.queryInterface(
91cdf0e10cSrcweir                 XDrawPageSupplier.class, maChartDocument );
92cdf0e10cSrcweir             if( aPageSupp != null )
93cdf0e10cSrcweir                 maDrawPage = (XDrawPage) UnoRuntime.queryInterface(
94cdf0e10cSrcweir                     XDrawPage.class, aPageSupp.getDrawPage() );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir             // get a factory for creating shapes
97cdf0e10cSrcweir             maShapeFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
98cdf0e10cSrcweir                 XMultiServiceFactory.class, maChartDocument );
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     // XRefreshable
refresh()103cdf0e10cSrcweir     public void refresh() throws RuntimeException
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         // recycle shapes in first call, if document was loaded
106cdf0e10cSrcweir         if( maBottomLine == null ||
107cdf0e10cSrcweir             maTopLine == null )
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             // try to recycle loaded shapes
110cdf0e10cSrcweir             XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface(
111cdf0e10cSrcweir                 XPropertySet.class, maChartDocument );
112cdf0e10cSrcweir             if( aDocProp != null )
113cdf0e10cSrcweir             {
114cdf0e10cSrcweir                 try
115cdf0e10cSrcweir                 {
116cdf0e10cSrcweir                     XIndexAccess aShapesIA = (XIndexAccess) UnoRuntime.queryInterface(
117cdf0e10cSrcweir                         XIndexAccess.class, aDocProp.getPropertyValue( "AdditionalShapes" ));
118cdf0e10cSrcweir                     if( aShapesIA != null &&
119cdf0e10cSrcweir                         aShapesIA.getCount() > 0 )
120cdf0e10cSrcweir                     {
121cdf0e10cSrcweir                         XShape aShape;
122cdf0e10cSrcweir                         String aName;
123cdf0e10cSrcweir                         for( int i = aShapesIA.getCount() - 1; i >= 0; --i )
124cdf0e10cSrcweir                         {
125cdf0e10cSrcweir                             aShape = (XShape) UnoRuntime.queryInterface(
126cdf0e10cSrcweir                                 XShape.class, aShapesIA.getByIndex( i ));
127cdf0e10cSrcweir                             if( aShape != null )
128cdf0e10cSrcweir                             {
129cdf0e10cSrcweir                                 XPropertySet aProp = (XPropertySet) UnoRuntime.queryInterface(
130cdf0e10cSrcweir                                     XPropertySet.class, aShape );
131cdf0e10cSrcweir                                 aName = (String) aProp.getPropertyValue( "Name" );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir                                 if( aName.equals( "top" ))
134cdf0e10cSrcweir                                 {
135cdf0e10cSrcweir                                     maTopLine = aShape;
136cdf0e10cSrcweir                                 }
137cdf0e10cSrcweir                                 else if( aName.equals( "bottom" ))
138cdf0e10cSrcweir                                 {
139cdf0e10cSrcweir                                     maBottomLine = aShape;
140cdf0e10cSrcweir                                 }
141cdf0e10cSrcweir                             }
142cdf0e10cSrcweir                         }
143cdf0e10cSrcweir                     }
144cdf0e10cSrcweir                 }
145cdf0e10cSrcweir                 catch( Exception ex )
146cdf0e10cSrcweir                 {
147cdf0e10cSrcweir                     JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE );
148cdf0e10cSrcweir                 }
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         // create top line if it does not yet exist
153cdf0e10cSrcweir         try
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             if( maTopLine == null )
156cdf0e10cSrcweir             {
157cdf0e10cSrcweir                 maTopLine = (XShape) UnoRuntime.queryInterface(
158cdf0e10cSrcweir                     XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" ));
159cdf0e10cSrcweir                 maDrawPage.add( maTopLine );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir                 // make line red and thicker
162cdf0e10cSrcweir                 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
163cdf0e10cSrcweir                     XPropertySet.class, maTopLine );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "LineColor", new Integer( 0xe01010 ));
166cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "LineWidth", new Integer( 50 ));
167cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "Name", "top" );
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         catch( Exception ex )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE );
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // create bottom line if it does not yet exist
176cdf0e10cSrcweir         try
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir             if( maBottomLine == null )
179cdf0e10cSrcweir             {
180cdf0e10cSrcweir                 maBottomLine = (XShape) UnoRuntime.queryInterface(
181cdf0e10cSrcweir                     XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" ));
182cdf0e10cSrcweir                 maDrawPage.add( maBottomLine );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir                 // make line green and thicker
185cdf0e10cSrcweir                 XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
186cdf0e10cSrcweir                     XPropertySet.class, maBottomLine );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "LineColor", new Integer( 0x10e010 ));
189cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "LineWidth", new Integer( 50 ));
190cdf0e10cSrcweir                 aShapeProp.setPropertyValue( "Name", "bottom" );
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         catch( Exception ex )
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         if( maTopLine == null ||
199cdf0e10cSrcweir             maBottomLine == null )
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             JOptionPane.showMessageDialog( null, "One of the lines is still null", "Assertion", JOptionPane.WARNING_MESSAGE );
202cdf0e10cSrcweir             return;
203cdf0e10cSrcweir         }
204*be8bac39Smseidel 
205cdf0e10cSrcweir         // position lines
206cdf0e10cSrcweir         // --------------
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         // get data
209cdf0e10cSrcweir         XChartDataArray aDataArray = (XChartDataArray) UnoRuntime.queryInterface(
210cdf0e10cSrcweir             XChartDataArray.class, maChartDocument.getData());
211cdf0e10cSrcweir         double aData[][] = aDataArray.getData();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         // get axes
214cdf0e10cSrcweir         XDiagram aDiagram = maChartDocument.getDiagram();
215cdf0e10cSrcweir         XShape aXAxis = (XShape) UnoRuntime.queryInterface(
216cdf0e10cSrcweir             XShape.class, ((XAxisXSupplier) UnoRuntime.queryInterface(
217cdf0e10cSrcweir                                XAxisXSupplier.class, aDiagram )).getXAxis() );
218cdf0e10cSrcweir         XShape aYAxis = (XShape) UnoRuntime.queryInterface(
219cdf0e10cSrcweir             XShape.class, ((XAxisYSupplier) UnoRuntime.queryInterface(
220cdf0e10cSrcweir                                XAxisYSupplier.class, aDiagram )).getYAxis() );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         // calculate points for hull
223cdf0e10cSrcweir         final int nLength = aData.length;
224cdf0e10cSrcweir         int i, j;
225cdf0e10cSrcweir         double fMax, fMin;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir         Point aMaxPtSeq[][] = new Point[ 1 ][];
228cdf0e10cSrcweir         aMaxPtSeq[ 0 ] = new Point[ nLength ];
229cdf0e10cSrcweir         Point aMinPtSeq[][] = new Point[ 1 ][];
230cdf0e10cSrcweir         aMinPtSeq[ 0 ] = new Point[ nLength ];
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         for( i = 0; i < nLength; i++ )
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             fMin = fMax = aData[ i ][ 1 ];
235cdf0e10cSrcweir             for( j = 1; j < aData[ i ].length; j++ )
236cdf0e10cSrcweir             {
237cdf0e10cSrcweir                 if( aData[ i ][ j ] > fMax )
238cdf0e10cSrcweir                     fMax = aData[ i ][ j ];
239cdf0e10cSrcweir                 else if( aData[ i ][ j ] < fMin )
240cdf0e10cSrcweir                     fMin = aData[ i ][ j ];
241cdf0e10cSrcweir             }
242cdf0e10cSrcweir             aMaxPtSeq[ 0 ][ i ] = new Point( getAxisPosition( aXAxis, aData[ i ][ 0 ], false ),
243cdf0e10cSrcweir                                              getAxisPosition( aYAxis, fMax, true ));
244cdf0e10cSrcweir             aMinPtSeq[ 0 ][ i ] = new Point( getAxisPosition( aXAxis, aData[ i ][ 0 ], false ),
245cdf0e10cSrcweir                                              getAxisPosition( aYAxis, fMin, true ));
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         // apply point sequences to lines
249cdf0e10cSrcweir         try
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
252cdf0e10cSrcweir                 XPropertySet.class, maTopLine );
253cdf0e10cSrcweir             aShapeProp.setPropertyValue( "PolyPolygon", aMaxPtSeq );
254*be8bac39Smseidel 
255cdf0e10cSrcweir             aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
256cdf0e10cSrcweir                 XPropertySet.class, maBottomLine );
257cdf0e10cSrcweir             aShapeProp.setPropertyValue( "PolyPolygon", aMinPtSeq );
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         catch( Exception ex )
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE );
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
addRefreshListener( com.sun.star.util.XRefreshListener aListener )265cdf0e10cSrcweir     public void addRefreshListener( com.sun.star.util.XRefreshListener aListener )
266cdf0e10cSrcweir         throws RuntimeException
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         // we don't want this but we have to implement the interface
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
removeRefreshListener( com.sun.star.util.XRefreshListener aListener )271cdf0e10cSrcweir     public void removeRefreshListener( com.sun.star.util.XRefreshListener aListener )
272cdf0e10cSrcweir         throws RuntimeException
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         // we don't want this but we have to implement the interface
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     // XServiceName
getServiceName()279cdf0e10cSrcweir     public String getServiceName() throws RuntimeException
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         return new String( smServiceName );
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     // XServiceInfo
supportsService( String aServiceName )285cdf0e10cSrcweir     public boolean supportsService( String aServiceName )
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         String[] aServices = getSupportedServiceNames_Static();
288cdf0e10cSrcweir         int i, nLength = aServices.length;
289cdf0e10cSrcweir         boolean bResult = false;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         for( i = 0; !bResult && i < nLength; ++i )
292cdf0e10cSrcweir             bResult = aServiceName.equals( aServices[ i ] );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         return bResult;
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
getImplementationName()297cdf0e10cSrcweir     public String getImplementationName()
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         return( JavaSampleChartAddIn.class.getName() );
300cdf0e10cSrcweir     }
301*be8bac39Smseidel 
getSupportedServiceNames()302cdf0e10cSrcweir     public String[] getSupportedServiceNames()
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         return getSupportedServiceNames_Static();
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     // XDiagram
getDiagramType()308cdf0e10cSrcweir     public String getDiagramType() throws RuntimeException
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         return new String( smServiceName );
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
getDataRowProperties( int nRow )313cdf0e10cSrcweir     public XPropertySet getDataRowProperties( int nRow )
314cdf0e10cSrcweir         throws com.sun.star.lang.IndexOutOfBoundsException, RuntimeException
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         return maChartDocument.getDiagram().getDataRowProperties( nRow );
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
getDataPointProperties( int nCol, int nRow )319cdf0e10cSrcweir     public XPropertySet getDataPointProperties( int nCol, int nRow )
320cdf0e10cSrcweir         throws com.sun.star.lang.IndexOutOfBoundsException, RuntimeException
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir         return maChartDocument.getDiagram().getDataPointProperties( nCol, nRow );
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     // XShape : XDiagram
getSize()326cdf0e10cSrcweir     public Size getSize() throws RuntimeException
327cdf0e10cSrcweir     {
328cdf0e10cSrcweir         return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getSize();
329cdf0e10cSrcweir     }
setSize( Size aSize )330cdf0e10cSrcweir     public void setSize( Size aSize ) throws RuntimeException, PropertyVetoException
331cdf0e10cSrcweir     {
332cdf0e10cSrcweir         ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setSize( aSize );
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir 
getPosition()335cdf0e10cSrcweir     public Point getPosition() throws RuntimeException
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getPosition();
338cdf0e10cSrcweir     }
setPosition( Point aPos )339cdf0e10cSrcweir     public void setPosition( Point aPos ) throws RuntimeException
340cdf0e10cSrcweir     {
341cdf0e10cSrcweir         ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setPosition( aPos );
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     // XShapeDescriptor : XShape : XDiagram
getShapeType()345cdf0e10cSrcweir     public String getShapeType() throws RuntimeException
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         return new String( "com.sun.star.comp.Chart.JavaSampleDiagramShape" );
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     // __________ private members __________
352cdf0e10cSrcweir     private com.sun.star.chart.XChartDocument       maChartDocument;
353cdf0e10cSrcweir     private com.sun.star.drawing.XDrawPage          maDrawPage;
354cdf0e10cSrcweir     private com.sun.star.lang.XMultiServiceFactory  maShapeFactory;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     // shapes added by add-in
357cdf0e10cSrcweir     private com.sun.star.drawing.XShape             maTopLine;
358cdf0e10cSrcweir     private com.sun.star.drawing.XShape             maBottomLine;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     // __________ private methods __________
361cdf0e10cSrcweir 
getAxisPosition( XShape aAxis, double fValue, boolean bVertical )362cdf0e10cSrcweir     private int getAxisPosition( XShape aAxis, double fValue, boolean bVertical )
363cdf0e10cSrcweir     {
364cdf0e10cSrcweir         int nResult = 0;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         if( aAxis != null )
367cdf0e10cSrcweir         {
368cdf0e10cSrcweir             XPropertySet aAxisProp = (XPropertySet) UnoRuntime.queryInterface(
369cdf0e10cSrcweir                 XPropertySet.class, aAxis );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir             try
372cdf0e10cSrcweir             {
373cdf0e10cSrcweir                 double fMin, fMax;
374cdf0e10cSrcweir                 fMin = ((Double) aAxisProp.getPropertyValue( "Min" )).doubleValue();
375cdf0e10cSrcweir                 fMax = ((Double) aAxisProp.getPropertyValue( "Max" )).doubleValue();
376cdf0e10cSrcweir                 double fRange = fMax - fMin;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir                 if( fMin <= fValue && fValue <= fMax &&
379cdf0e10cSrcweir                     fRange != 0 )
380cdf0e10cSrcweir                 {
381cdf0e10cSrcweir                     if( bVertical )
382cdf0e10cSrcweir                     {
383cdf0e10cSrcweir                         nResult = aAxis.getPosition().Y +
384cdf0e10cSrcweir                             (int)((double)(aAxis.getSize().Height) *
385cdf0e10cSrcweir                                   (1.0 - (( fValue - fMin ) / fRange )));
386cdf0e10cSrcweir                     }
387cdf0e10cSrcweir                     else
388cdf0e10cSrcweir                     {
389cdf0e10cSrcweir                         nResult = aAxis.getPosition().X +
390cdf0e10cSrcweir                             (int)((double)(aAxis.getSize().Width) *
391cdf0e10cSrcweir                                   (( fValue - fMin ) / fRange ));
392cdf0e10cSrcweir                     }
393cdf0e10cSrcweir                 }
394cdf0e10cSrcweir 			}
395cdf0e10cSrcweir 			catch( Exception ex )
396cdf0e10cSrcweir 			{
397cdf0e10cSrcweir                 JOptionPane.showMessageDialog( null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE );
398cdf0e10cSrcweir             }
399cdf0e10cSrcweir 		}
400cdf0e10cSrcweir         return nResult;
401cdf0e10cSrcweir 	}
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     // __________ static things __________
404cdf0e10cSrcweir 
405*be8bac39Smseidel     private static final String smServiceName = "com.sun.star.comp.Chart.JavaSampleChartAddIn";
406cdf0e10cSrcweir 
getSupportedServiceNames_Static()407cdf0e10cSrcweir     public static String[] getSupportedServiceNames_Static()
408cdf0e10cSrcweir     {
409cdf0e10cSrcweir         String[] aResult = { smServiceName,
410cdf0e10cSrcweir                              "com.sun.star.chart.Diagram",
411cdf0e10cSrcweir                              "com.sun.star.chart.ChartAxisYSupplier" };
412cdf0e10cSrcweir         return aResult;
413cdf0e10cSrcweir     }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     /**
417cdf0e10cSrcweir      * Returns a factory for creating the service.
418cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
419cdf0e10cSrcweir      * <p>
420cdf0e10cSrcweir      * @return  returns a <code>XSingleServiceFactory</code> for creating the component
421cdf0e10cSrcweir      * @param   implName     the name of the implementation for which a service is desired
422cdf0e10cSrcweir      * @param   multiFactory the service manager to be used if needed
423cdf0e10cSrcweir      * @param   regKey       the registryKey
424cdf0e10cSrcweir      * @see                  com.sun.star.comp.loader.JavaLoader
425cdf0e10cSrcweir      */
__getServiceFactory( String implName, XMultiServiceFactory multiFactory, com.sun.star.registry.XRegistryKey regKey )426cdf0e10cSrcweir     public static XSingleServiceFactory __getServiceFactory(
427cdf0e10cSrcweir         String implName,
428cdf0e10cSrcweir         XMultiServiceFactory multiFactory,
429cdf0e10cSrcweir         com.sun.star.registry.XRegistryKey regKey )
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         XSingleServiceFactory xSingleServiceFactory = null;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         if( implName.equals( JavaSampleChartAddIn.class.getName()) )
434cdf0e10cSrcweir         {
435cdf0e10cSrcweir             xSingleServiceFactory = com.sun.star.comp.loader.FactoryHelper.getServiceFactory(
436cdf0e10cSrcweir                 JavaSampleChartAddIn.class, smServiceName,
437*be8bac39Smseidel                 multiFactory, regKey );
438cdf0e10cSrcweir         }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir         return xSingleServiceFactory;
441cdf0e10cSrcweir     }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     /**
444cdf0e10cSrcweir      * Writes the service information into the given registry key.
445cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
446cdf0e10cSrcweir      * <p>
447cdf0e10cSrcweir      * @return  returns true if the operation succeeded
448cdf0e10cSrcweir      * @param   regKey       the registryKey
449cdf0e10cSrcweir      * @see                  com.sun.star.comp.loader.JavaLoader
450cdf0e10cSrcweir      */
451cdf0e10cSrcweir     // This method not longer necessary since OOo 3.4 where the component registration
452cdf0e10cSrcweir     // was changed to passive component registration. For more details see
453*be8bac39Smseidel     // https://wiki.openoffice.org/wiki/Passive_Component_Registration
454cdf0e10cSrcweir 
455cdf0e10cSrcweir //    public static boolean __writeRegistryServiceInfo( com.sun.star.registry.XRegistryKey regKey )
456cdf0e10cSrcweir //     {
457cdf0e10cSrcweir //         boolean bResult = true;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir //         String[] aServices = getSupportedServiceNames_Static();
460cdf0e10cSrcweir //         int i, nLength = aServices.length;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir //         for( i = 0; i < nLength; ++i )
463cdf0e10cSrcweir //         {
464cdf0e10cSrcweir //             bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
465cdf0e10cSrcweir //                 JavaSampleChartAddIn.class.getName(), aServices[ i ], regKey );
466cdf0e10cSrcweir //         }
467cdf0e10cSrcweir //         return bResult;
468cdf0e10cSrcweir //     }
469cdf0e10cSrcweir }
470*be8bac39Smseidel 
471