1*cdf0e10cSrcweir // package name: as default, start with complex 2*cdf0e10cSrcweir package qa; 3*cdf0e10cSrcweir 4*cdf0e10cSrcweir // imports 5*cdf0e10cSrcweir import complexlib.ComplexTestCase; 6*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 7*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 8*cdf0e10cSrcweir import com.sun.star.uno.Type; 9*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 10*cdf0e10cSrcweir 11*cdf0e10cSrcweir import java.io.PrintWriter; 12*cdf0e10cSrcweir import java.util.Hashtable; 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir import com.sun.star.lang.*; 15*cdf0e10cSrcweir import com.sun.star.beans.*; 16*cdf0e10cSrcweir import com.sun.star.frame.*; 17*cdf0e10cSrcweir import com.sun.star.chart.*; 18*cdf0e10cSrcweir import com.sun.star.drawing.*; 19*cdf0e10cSrcweir import com.sun.star.awt.*; 20*cdf0e10cSrcweir import com.sun.star.container.*; 21*cdf0e10cSrcweir import com.sun.star.util.XCloseable; 22*cdf0e10cSrcweir import com.sun.star.util.CloseVetoException; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 25*cdf0e10cSrcweir import com.sun.star.comp.helper.ComponentContext; 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir /** 28*cdf0e10cSrcweir * The following Complex Test will test the 29*cdf0e10cSrcweir * com.sun.star.document.IndexedPropertyValues 30*cdf0e10cSrcweir * service 31*cdf0e10cSrcweir */ 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir public class TestCaseOldAPI extends ComplexTestCase { 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // The name of the tested service 36*cdf0e10cSrcweir private final String testedServiceName = 37*cdf0e10cSrcweir "com.sun.star.chart.ChartDocument"; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // The first of the mandatory functions: 40*cdf0e10cSrcweir /** 41*cdf0e10cSrcweir * Return the name of the test. 42*cdf0e10cSrcweir * In this case it is the actual name of the service. 43*cdf0e10cSrcweir * @return The tested service. 44*cdf0e10cSrcweir */ 45*cdf0e10cSrcweir public String getTestObjectName() { 46*cdf0e10cSrcweir return testedServiceName; 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir // The second of the mandatory functions: return all test methods as an 50*cdf0e10cSrcweir // array. There is only one test function in this example. 51*cdf0e10cSrcweir /** 52*cdf0e10cSrcweir * Return all test methods. 53*cdf0e10cSrcweir * @return The test methods. 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir public String[] getTestMethodNames() { 56*cdf0e10cSrcweir // For some tests a view needs to be created. Accessing the model via 57*cdf0e10cSrcweir // this program and the view may lead to problems 58*cdf0e10cSrcweir boolean bAvoidViewCreation = false; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir if( bAvoidViewCreation ) 61*cdf0e10cSrcweir return new String[] { 62*cdf0e10cSrcweir "testData", 63*cdf0e10cSrcweir "testChartType", 64*cdf0e10cSrcweir "testArea", 65*cdf0e10cSrcweir "testAggregation", 66*cdf0e10cSrcweir "testFactory", 67*cdf0e10cSrcweir "testDataSeriesAndPoints", 68*cdf0e10cSrcweir "testStatistics", 69*cdf0e10cSrcweir "testStockProperties" 70*cdf0e10cSrcweir }; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir return new String[] { 73*cdf0e10cSrcweir "testData", 74*cdf0e10cSrcweir "testChartType", 75*cdf0e10cSrcweir "testTitle", 76*cdf0e10cSrcweir "testSubTitle", 77*cdf0e10cSrcweir "testDiagram", 78*cdf0e10cSrcweir "testAxis", 79*cdf0e10cSrcweir "testLegend", 80*cdf0e10cSrcweir "testArea", 81*cdf0e10cSrcweir "testAggregation", 82*cdf0e10cSrcweir "testFactory", 83*cdf0e10cSrcweir "testDataSeriesAndPoints", 84*cdf0e10cSrcweir "testStatistics", 85*cdf0e10cSrcweir "testStockProperties" 86*cdf0e10cSrcweir }; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // ____________ 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir public void before() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir // set to "true" to get a view 94*cdf0e10cSrcweir mbCreateView = true; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir if( mbCreateView ) 97*cdf0e10cSrcweir mxChartModel = createDocument( "schart" ); 98*cdf0e10cSrcweir else 99*cdf0e10cSrcweir mxChartModel = createChartModel(); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir mxOldDoc = (XChartDocument) UnoRuntime.queryInterface( 102*cdf0e10cSrcweir XChartDocument.class, mxChartModel ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // ____________ 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir public void after() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface( 110*cdf0e10cSrcweir XCloseable.class, mxChartModel ); 111*cdf0e10cSrcweir assure( "document is no XCloseable", xCloseable != null ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // do not close document if there exists a view 114*cdf0e10cSrcweir if( ! mbCreateView ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir try 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir xCloseable.close( true ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir catch( CloseVetoException ex ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir failed( ex.getMessage() ); 123*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // ____________ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir public void testTitle() 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir try 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface( 135*cdf0e10cSrcweir XPropertySet.class, mxOldDoc ); 136*cdf0e10cSrcweir assure( "Chart Document is no XPropertySet", xDocProp != null ); 137*cdf0e10cSrcweir xDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); 138*cdf0e10cSrcweir assure( "Property HasMainTitle", AnyConverter.toBoolean( 139*cdf0e10cSrcweir xDocProp.getPropertyValue( "HasMainTitle" ))); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir XShape xTitleShape = mxOldDoc.getTitle(); 142*cdf0e10cSrcweir XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface( 143*cdf0e10cSrcweir XPropertySet.class, xTitleShape ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // set property via old API 146*cdf0e10cSrcweir if( xTitleProp != null ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir String aTitle = " Overwritten by Old API "; 149*cdf0e10cSrcweir float fHeight = (float)17.0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir xTitleProp.setPropertyValue( "String", aTitle ); 152*cdf0e10cSrcweir xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) ); 155*cdf0e10cSrcweir assure( "Changing CharHeight via old API failed", fNewHeight == fHeight ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir String aNewTitle = AnyConverter.toString( xTitleProp.getPropertyValue( "String" ) ); 158*cdf0e10cSrcweir assure( "Property \"String\" failed", aNewTitle.equals( aTitle )); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // move title 162*cdf0e10cSrcweir Point aSetPos = new Point(); 163*cdf0e10cSrcweir aSetPos.X = 1000; 164*cdf0e10cSrcweir aSetPos.Y = 200; 165*cdf0e10cSrcweir xTitleShape.setPosition( aSetPos ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir Point aNewPos = xTitleShape.getPosition(); 168*cdf0e10cSrcweir assure( "Title Position X", approxEqual( aNewPos.X, aSetPos.X, 1 )); 169*cdf0e10cSrcweir assure( "Title Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 )); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir catch( Exception ex ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir failed( ex.getMessage() ); 174*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // ____________ 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir public void testSubTitle() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir try 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface( 185*cdf0e10cSrcweir XPropertySet.class, mxOldDoc ); 186*cdf0e10cSrcweir assure( "Chart Document is no XPropertySet", xDocProp != null ); 187*cdf0e10cSrcweir xDocProp.setPropertyValue( "HasSubTitle", new Boolean( true )); 188*cdf0e10cSrcweir assure( "Property HasSubTitle", AnyConverter.toBoolean( 189*cdf0e10cSrcweir xDocProp.getPropertyValue( "HasSubTitle" ))); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir XShape xTitleShape = mxOldDoc.getSubTitle(); 192*cdf0e10cSrcweir XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface( 193*cdf0e10cSrcweir XPropertySet.class, xTitleShape ); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // set Property via old API 196*cdf0e10cSrcweir if( xTitleProp != null ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir int nColor = 0x009acd; // DeepSkyBlue3 199*cdf0e10cSrcweir float fWeight = FontWeight.BOLD; 200*cdf0e10cSrcweir float fHeight = (float)14.0; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir xTitleProp.setPropertyValue( "CharColor", new Integer( nColor ) ); 203*cdf0e10cSrcweir xTitleProp.setPropertyValue( "CharWeight", new Float( fWeight )); 204*cdf0e10cSrcweir xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) ); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir int nNewColor = AnyConverter.toInt( xTitleProp.getPropertyValue( "CharColor" ) ); 207*cdf0e10cSrcweir assure( "Changing CharColor via old API failed", nNewColor == nColor ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir float fNewWeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharWeight" ) ); 210*cdf0e10cSrcweir assure( "Changing CharWeight via old API failed", fNewWeight == fWeight ); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) ); 213*cdf0e10cSrcweir assure( "Changing CharHeight via old API failed", fNewHeight == fHeight ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir catch( Exception ex ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir failed( ex.getMessage() ); 219*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // ------------ 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir public void testDiagram() 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir try 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir // testing wall 230*cdf0e10cSrcweir XDiagram xDia = mxOldDoc.getDiagram(); 231*cdf0e10cSrcweir if( xDia != null ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir X3DDisplay xDisp = (X3DDisplay) UnoRuntime.queryInterface( 234*cdf0e10cSrcweir X3DDisplay.class, xDia ); 235*cdf0e10cSrcweir assure( "X3DDisplay not supported", xDisp != null ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // Wall 238*cdf0e10cSrcweir XPropertySet xProp = xDisp.getWall(); 239*cdf0e10cSrcweir if( xProp != null ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir int nColor = 0xffe1ff; // thistle1 242*cdf0e10cSrcweir xProp.setPropertyValue( "FillColor", new Integer( nColor ) ); 243*cdf0e10cSrcweir int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) ); 244*cdf0e10cSrcweir assure( "Changing FillColor via old API failed", nNewColor == nColor ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir assure( "Wrong Diagram Type", xDia.getDiagramType().equals( 248*cdf0e10cSrcweir "com.sun.star.chart.BarDiagram" )); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir // Diagram properties 251*cdf0e10cSrcweir xProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xDia ); 252*cdf0e10cSrcweir assure( "Diagram is no property set", xProp != null ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // y-axis 255*cdf0e10cSrcweir boolean bFirstYAxisText = false; 256*cdf0e10cSrcweir xProp.setPropertyValue( "HasYAxisDescription", new Boolean( bFirstYAxisText )); 257*cdf0e10cSrcweir boolean bNewFirstYAxisText = AnyConverter.toBoolean( 258*cdf0e10cSrcweir xProp.getPropertyValue( "HasYAxisDescription" )); 259*cdf0e10cSrcweir assure( "Removing description of first y-axis", bNewFirstYAxisText == bFirstYAxisText ); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // boolean bYAxisTitle = true; 262*cdf0e10cSrcweir // xProp.setPropertyValue( "HasYAxisTitle", new Boolean( bYAxisTitle )); 263*cdf0e10cSrcweir // boolean bNewYAxisTitle = AnyConverter.toBoolean( 264*cdf0e10cSrcweir // xProp.getPropertyValue( "HasYAxisTitle" )); 265*cdf0e10cSrcweir // assure( "Adding y-axis title", bNewYAxisTitle == bYAxisTitle ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir // set title text 268*cdf0e10cSrcweir // XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface( 269*cdf0e10cSrcweir // XAxisYSupplier.class, mxOldDoc.getDiagram() ); 270*cdf0e10cSrcweir // assure( "Diagram is no y-axis supplier", xYAxisSuppl != null ); 271*cdf0e10cSrcweir // XPropertySet xAxisTitleProp = (XPropertySet) UnoRuntime.queryInterface( 272*cdf0e10cSrcweir // XPropertySet.class, xYAxisSuppl.getYAxisTitle() ); 273*cdf0e10cSrcweir // assure( "Y-Axis Title is no XPropertySet", xAxisTitleProp != null ); 274*cdf0e10cSrcweir // xAxisTitleProp.setPropertyValue( "String", "New y axis title" ); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir // second y-axis 277*cdf0e10cSrcweir boolean bSecondaryYAxis = true; 278*cdf0e10cSrcweir xProp.setPropertyValue( "HasSecondaryYAxis", new Boolean( bSecondaryYAxis )); 279*cdf0e10cSrcweir boolean bNewSecYAxisValue = AnyConverter.toBoolean( 280*cdf0e10cSrcweir xProp.getPropertyValue( "HasSecondaryYAxis" )); 281*cdf0e10cSrcweir assure( "Adding a second y-axis does not work", bNewSecYAxisValue == bSecondaryYAxis ); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir XTwoAxisYSupplier xSecYAxisSuppl = (XTwoAxisYSupplier) UnoRuntime.queryInterface( 284*cdf0e10cSrcweir XTwoAxisYSupplier.class, xDia ); 285*cdf0e10cSrcweir assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl != null ); 286*cdf0e10cSrcweir assure( "No second y-axis found", xSecYAxisSuppl.getSecondaryYAxis() != null ); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir // move diagram 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir XShape xDiagramShape = (XShape) UnoRuntime.queryInterface( 292*cdf0e10cSrcweir XShape.class, xDia ); 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir Point aOldPos = xDiagramShape.getPosition(); 295*cdf0e10cSrcweir int xDiff = 20; 296*cdf0e10cSrcweir int yDiff = 20; 297*cdf0e10cSrcweir Point aSetPos = new Point(); 298*cdf0e10cSrcweir aSetPos.X = aOldPos.X + xDiff; 299*cdf0e10cSrcweir aSetPos.Y = aOldPos.Y + yDiff; 300*cdf0e10cSrcweir xDiagramShape.setPosition( aSetPos ); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir Point aNewPos = xDiagramShape.getPosition(); 303*cdf0e10cSrcweir //System.out.println( "set X = " + aSetPos.X + ", new X = " + aNewPos.X ); 304*cdf0e10cSrcweir //System.out.println( "set Y = " + aSetPos.Y + ", new Y = " + aNewPos.Y ); 305*cdf0e10cSrcweir assure( "Diagram Position X", approxEqual( aNewPos.X, aSetPos.X, 1 )); 306*cdf0e10cSrcweir assure( "Diagram Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 )); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // size diagram 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir XShape xDiagramShape = (XShape) UnoRuntime.queryInterface( 312*cdf0e10cSrcweir XShape.class, xDia ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir Size aOldSize = xDiagramShape.getSize(); 315*cdf0e10cSrcweir int xDiff = aOldSize.Width/2+2; 316*cdf0e10cSrcweir int yDiff = aOldSize.Height/2+2; 317*cdf0e10cSrcweir Size aSetSize = new Size(); 318*cdf0e10cSrcweir aSetSize.Width = aOldSize.Width - xDiff; 319*cdf0e10cSrcweir aSetSize.Height = aOldSize.Height - yDiff; 320*cdf0e10cSrcweir xDiagramShape.setSize( aSetSize ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir Size aNewSize = xDiagramShape.getSize(); 323*cdf0e10cSrcweir //System.out.println( "set width = " + aSetSize.Width + ", new width = " + aNewSize.Width ); 324*cdf0e10cSrcweir //System.out.println( "set height = " + aSetSize.Height + ", new height = " + aNewSize.Height ); 325*cdf0e10cSrcweir assure( "Diagram Width", approxEqual( aNewSize.Width, aSetSize.Width, 2 )); 326*cdf0e10cSrcweir assure( "Diagram Height", approxEqual( aNewSize.Height, aSetSize.Height, 2 )); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir catch( Exception ex ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir failed( ex.getMessage() ); 332*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // ------------ 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir public void testAxis() 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir try 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface( 343*cdf0e10cSrcweir XAxisYSupplier.class, mxOldDoc.getDiagram() ); 344*cdf0e10cSrcweir assure( "Diagram is no y-axis supplier", xYAxisSuppl != null ); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir XPropertySet xProp = xYAxisSuppl.getYAxis(); 347*cdf0e10cSrcweir assure( "No y-axis found", xProp != null ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir double fMax1, fMax2; 350*cdf0e10cSrcweir Object oMax = xProp.getPropertyValue( "Max" ); 351*cdf0e10cSrcweir assure( "No Maximum set", AnyConverter.isDouble( oMax )); 352*cdf0e10cSrcweir fMax1 = AnyConverter.toDouble( oMax ); 353*cdf0e10cSrcweir log.println( "Maximum retrieved: " + fMax1 ); 354*cdf0e10cSrcweir //todo: the view has to be built before there is an explicit value 355*cdf0e10cSrcweir // assure( "Max is 0.0", fMax1 > 0.0 ); 356*cdf0e10cSrcweir xProp.setPropertyValue( "AutoMax", new Boolean( false )); 357*cdf0e10cSrcweir oMax = xProp.getPropertyValue( "Max" ); 358*cdf0e10cSrcweir assure( "No Maximum set", AnyConverter.isDouble( oMax )); 359*cdf0e10cSrcweir fMax2 = AnyConverter.toDouble( oMax ); 360*cdf0e10cSrcweir log.println( "Maximum with AutoMax off: " + fMax2 ); 361*cdf0e10cSrcweir assure( "maxima differ", fMax1 == fMax2 ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir double nNewMax = 12.3; 364*cdf0e10cSrcweir double nNewOrigin = 2.7; 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir xProp.setPropertyValue( "Max", new Double( nNewMax )); 367*cdf0e10cSrcweir assure( "AutoMax is on", ! AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMax" )) ); 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir assure( "Maximum value invalid", 370*cdf0e10cSrcweir approxEqual( 371*cdf0e10cSrcweir AnyConverter.toDouble( xProp.getPropertyValue( "Max" )), 372*cdf0e10cSrcweir nNewMax )); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir xProp.setPropertyValue( "AutoMin", new Boolean( true )); 375*cdf0e10cSrcweir assure( "AutoMin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMin" )) ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir xProp.setPropertyValue( "Origin", new Double( nNewOrigin )); 378*cdf0e10cSrcweir assure( "Origin invalid", 379*cdf0e10cSrcweir approxEqual( 380*cdf0e10cSrcweir AnyConverter.toDouble( xProp.getPropertyValue( "Origin" )), 381*cdf0e10cSrcweir nNewOrigin )); 382*cdf0e10cSrcweir xProp.setPropertyValue( "AutoOrigin", new Boolean( true )); 383*cdf0e10cSrcweir assure( "AutoOrigin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoOrigin" )) ); 384*cdf0e10cSrcweir Object oOrigin = xProp.getPropertyValue( "Origin" ); 385*cdf0e10cSrcweir assure( "No Origin set", AnyConverter.isDouble( oOrigin )); 386*cdf0e10cSrcweir log.println( "Origin retrieved: " + AnyConverter.toDouble( oOrigin )); 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir xProp.setPropertyValue( "Logarithmic", new Boolean( true )); 389*cdf0e10cSrcweir assure( "Scaling is not logarithmic", 390*cdf0e10cSrcweir AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) ); 391*cdf0e10cSrcweir xProp.setPropertyValue( "Logarithmic", new Boolean( false )); 392*cdf0e10cSrcweir assure( "Scaling is not logarithmic", 393*cdf0e10cSrcweir ! AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) ); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir int nNewColor = 0xcd853f; // peru 396*cdf0e10cSrcweir xProp.setPropertyValue( "LineColor", new Integer( nNewColor )); 397*cdf0e10cSrcweir assure( "Property LineColor", 398*cdf0e10cSrcweir AnyConverter.toInt( xProp.getPropertyValue( "LineColor" )) == nNewColor ); 399*cdf0e10cSrcweir float fNewCharHeight = (float)(16.0); 400*cdf0e10cSrcweir xProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight )); 401*cdf0e10cSrcweir assure( "Property CharHeight", 402*cdf0e10cSrcweir AnyConverter.toFloat( xProp.getPropertyValue( "CharHeight" )) == fNewCharHeight ); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir int nNewTextRotation = 700; // in 1/100 degrees 405*cdf0e10cSrcweir xProp.setPropertyValue( "TextRotation", new Integer( nNewTextRotation )); 406*cdf0e10cSrcweir assure( "Property TextRotation", 407*cdf0e10cSrcweir AnyConverter.toInt( xProp.getPropertyValue( "TextRotation" )) == nNewTextRotation ); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir double fStepMain = 10.0; 410*cdf0e10cSrcweir xProp.setPropertyValue( "StepMain", new Double( fStepMain )); 411*cdf0e10cSrcweir assure( "Property StepMain", 412*cdf0e10cSrcweir AnyConverter.toDouble( xProp.getPropertyValue( "StepMain" )) == fStepMain ); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir // note: fStepHelp must be a divider of fStepMain, because 415*cdf0e10cSrcweir // internally, the help-step is stored as an integer number of 416*cdf0e10cSrcweir // substeps 417*cdf0e10cSrcweir double fStepHelp = 5.0; 418*cdf0e10cSrcweir xProp.setPropertyValue( "StepHelp", new Double( fStepHelp )); 419*cdf0e10cSrcweir assure( "Property StepHelp", 420*cdf0e10cSrcweir AnyConverter.toDouble( xProp.getPropertyValue( "StepHelp" )) == fStepHelp ); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir xProp.setPropertyValue( "DisplayLabels", new Boolean( false )); 423*cdf0e10cSrcweir assure( "Property DisplayLabels", ! AnyConverter.toBoolean( 424*cdf0e10cSrcweir xProp.getPropertyValue( "DisplayLabels" ))); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir catch( Exception ex ) 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir failed( ex.getMessage() ); 429*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir // ------------ 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir public void testLegend() 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir XShape xLegend = mxOldDoc.getLegend(); 438*cdf0e10cSrcweir assure( "No Legend returned", xLegend != null ); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir XPropertySet xLegendProp = (XPropertySet) UnoRuntime.queryInterface( 441*cdf0e10cSrcweir XPropertySet.class, xLegend ); 442*cdf0e10cSrcweir assure( "Legend is no property set", xLegendProp != null ); 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir try 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir ChartLegendPosition eNewPos = ChartLegendPosition.BOTTOM; 447*cdf0e10cSrcweir xLegendProp.setPropertyValue( "Alignment", eNewPos ); 448*cdf0e10cSrcweir assure( "Property Alignment", 449*cdf0e10cSrcweir AnyConverter.toObject( 450*cdf0e10cSrcweir new Type( ChartLegendPosition.class ), 451*cdf0e10cSrcweir xLegendProp.getPropertyValue( "Alignment" )) == eNewPos ); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir float fNewCharHeight = (float)(11.0); 454*cdf0e10cSrcweir xLegendProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight )); 455*cdf0e10cSrcweir assure( "Property CharHeight", 456*cdf0e10cSrcweir AnyConverter.toFloat( xLegendProp.getPropertyValue( "CharHeight" )) == fNewCharHeight ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // move legend 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir Point aOldPos = xLegend.getPosition(); 461*cdf0e10cSrcweir int xDiff = 20; 462*cdf0e10cSrcweir int yDiff = 20; 463*cdf0e10cSrcweir Point aSetPos = new Point(); 464*cdf0e10cSrcweir aSetPos.X = aOldPos.X + xDiff; 465*cdf0e10cSrcweir aSetPos.Y = aOldPos.Y + yDiff; 466*cdf0e10cSrcweir xLegend.setPosition( aSetPos ); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir Point aNewPos = xLegend.getPosition(); 469*cdf0e10cSrcweir assure( "Legend Position X", approxEqual( aNewPos.X, aSetPos.X, 1 )); 470*cdf0e10cSrcweir assure( "Legend Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 )); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir catch( Exception ex ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir failed( ex.getMessage() ); 476*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir // ------------ 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir public void testArea() 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir XPropertySet xArea = mxOldDoc.getArea(); 485*cdf0e10cSrcweir assure( "No Area", xArea != null ); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir try 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir int nColor = 0xf5fffa; // mint cream 490*cdf0e10cSrcweir xArea.setPropertyValue( "FillColor", new Integer( nColor ) ); 491*cdf0e10cSrcweir xArea.setPropertyValue( "FillStyle", FillStyle.SOLID ); 492*cdf0e10cSrcweir // XPropertySetInfo xInfo = xArea.getPropertySetInfo(); 493*cdf0e10cSrcweir // assure( "Area does not support ChartUserDefinedAttributes", 494*cdf0e10cSrcweir // xInfo.hasPropertyByName( "ChartUserDefinedAttributes" )); 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir // String aTestAttributeName = "test:foo"; 497*cdf0e10cSrcweir // String aTestAttributeValue = "content"; 498*cdf0e10cSrcweir // XNameContainer xUserDefAttributes = (XNameContainer) AnyConverter.toObject( 499*cdf0e10cSrcweir // new Type( XNameContainer.class ), xArea.getPropertyValue( "ChartUserDefinedAttributes" )); 500*cdf0e10cSrcweir // xUserDefAttributes.insertByName( aTestAttributeName, aTestAttributeValue ); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir // String aContent = AnyConverter.toString( xUserDefAttributes.getByName( aTestAttributeName )); 503*cdf0e10cSrcweir // assure( "Wrong content in UserDefinedAttributes container", 504*cdf0e10cSrcweir // aContent.equals( aTestAttributeValue )); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir int nNewColor = AnyConverter.toInt( xArea.getPropertyValue( "FillColor" ) ); 507*cdf0e10cSrcweir assure( "Changing FillColor of Area failed", nNewColor == nColor ); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir catch( Exception ex ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir failed( ex.getMessage() ); 512*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir // ------------ 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir public void testChartType() 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( 521*cdf0e10cSrcweir XMultiServiceFactory.class, mxOldDoc ); 522*cdf0e10cSrcweir assure( "document is no factory", xFact != null ); 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir try 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir String aMyServiceName = new String( "com.sun.star.chart.BarDiagram" ); 527*cdf0e10cSrcweir String aServices[] = xFact.getAvailableServiceNames(); 528*cdf0e10cSrcweir boolean bServiceFound = false; 529*cdf0e10cSrcweir for( int i = 0; i < aServices.length; ++i ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if( aServices[ i ].equals( aMyServiceName )) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir bServiceFound = true; 534*cdf0e10cSrcweir break; 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir assure( "getAvailableServiceNames did not return " + aMyServiceName, bServiceFound ); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir if( bServiceFound ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir XDiagram xDia = (XDiagram) UnoRuntime.queryInterface( 542*cdf0e10cSrcweir XDiagram.class, xFact.createInstance( aMyServiceName )); 543*cdf0e10cSrcweir assure( aMyServiceName + " could not be created", xDia != null ); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir mxOldDoc.setDiagram( xDia ); 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( 548*cdf0e10cSrcweir XPropertySet.class, xDia ); 549*cdf0e10cSrcweir assure( "Diagram is no XPropertySet", xDiaProp != null ); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir xDiaProp.setPropertyValue( "Stacked", new Boolean( true )); 552*cdf0e10cSrcweir assure( "StackMode could not be set correctly", 553*cdf0e10cSrcweir AnyConverter.toBoolean( 554*cdf0e10cSrcweir xDiaProp.getPropertyValue( "Stacked" ))); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir xDiaProp.setPropertyValue( "Dim3D", new Boolean( false )); 557*cdf0e10cSrcweir assure( "Dim3D could not be set correctly", 558*cdf0e10cSrcweir ! AnyConverter.toBoolean( 559*cdf0e10cSrcweir xDiaProp.getPropertyValue( "Dim3D" ))); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir xDiaProp.setPropertyValue( "Vertical", new Boolean( true )); 562*cdf0e10cSrcweir assure( "Vertical could not be set correctly", 563*cdf0e10cSrcweir AnyConverter.toBoolean( 564*cdf0e10cSrcweir xDiaProp.getPropertyValue( "Vertical" ))); 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir // reset to bar-chart 568*cdf0e10cSrcweir // aMyServiceName = new String( "com.sun.star.chart.BarDiagram" ); 569*cdf0e10cSrcweir // XDiagram xDia = (XDiagram) UnoRuntime.queryInterface( 570*cdf0e10cSrcweir // XDiagram.class, xFact.createInstance( aMyServiceName )); 571*cdf0e10cSrcweir // assure( aMyServiceName + " could not be created", xDia != null ); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir // mxOldDoc.setDiagram( xDia ); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir catch( Exception ex ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir failed( ex.getMessage() ); 578*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir // ------------ 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir public void testAggregation() 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir // query to new type 587*cdf0e10cSrcweir XChartDocument xDiaProv = (XChartDocument) UnoRuntime.queryInterface( 588*cdf0e10cSrcweir XChartDocument.class, mxOldDoc ); 589*cdf0e10cSrcweir assure( "query to new interface failed", xDiaProv != null ); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir com.sun.star.chart.XChartDocument xDoc = (com.sun.star.chart.XChartDocument) UnoRuntime.queryInterface( 592*cdf0e10cSrcweir com.sun.star.chart.XChartDocument.class, xDiaProv ); 593*cdf0e10cSrcweir assure( "querying back to old interface failed", xDoc != null ); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir // ------------ 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir public void testDataSeriesAndPoints() 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir try 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir XDiagram xDia = mxOldDoc.getDiagram(); 603*cdf0e10cSrcweir assure( "Invalid Diagram", xDia != null ); 604*cdf0e10cSrcweir XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( 605*cdf0e10cSrcweir XMultiServiceFactory.class, mxOldDoc ); 606*cdf0e10cSrcweir assure( "document is no factory", xFact != null ); 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir // FillColor 609*cdf0e10cSrcweir XPropertySet xProp = xDia.getDataRowProperties( 0 ); 610*cdf0e10cSrcweir int nColor = 0xffd700; // gold 611*cdf0e10cSrcweir xProp.setPropertyValue( "FillColor", new Integer( nColor )); 612*cdf0e10cSrcweir int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) ); 613*cdf0e10cSrcweir assure( "Changing FillColor of Data Series failed", nNewColor == nColor ); 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir // Gradient 616*cdf0e10cSrcweir assure( "No DataRowProperties for series 0", xProp != null ); 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir // note: the FillGradient property is optional, however it was 619*cdf0e10cSrcweir // supported in the old chart's API 620*cdf0e10cSrcweir XNameContainer xGradientTable = (XNameContainer) UnoRuntime.queryInterface( 621*cdf0e10cSrcweir XNameContainer.class, 622*cdf0e10cSrcweir xFact.createInstance( "com.sun.star.drawing.GradientTable" )); 623*cdf0e10cSrcweir assure( "no gradient table", xGradientTable != null ); 624*cdf0e10cSrcweir String aGradientName = "NewAPITestGradient"; 625*cdf0e10cSrcweir Gradient aGradient = new Gradient(); 626*cdf0e10cSrcweir aGradient.Style = GradientStyle.LINEAR; 627*cdf0e10cSrcweir aGradient.StartColor = 0xe0ffff; // light cyan 628*cdf0e10cSrcweir aGradient.EndColor = 0xff8c00; // dark orange 629*cdf0e10cSrcweir aGradient.Angle = 300; // 30 degrees 630*cdf0e10cSrcweir aGradient.Border = 15; 631*cdf0e10cSrcweir aGradient.XOffset = 0; 632*cdf0e10cSrcweir aGradient.YOffset = 0; 633*cdf0e10cSrcweir aGradient.StartIntensity = 100; 634*cdf0e10cSrcweir aGradient.EndIntensity = 80; 635*cdf0e10cSrcweir aGradient.StepCount = 23; 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir xGradientTable.insertByName( aGradientName, aGradient ); 638*cdf0e10cSrcweir xProp.setPropertyValue( "FillStyle", FillStyle.GRADIENT ); 639*cdf0e10cSrcweir xProp.setPropertyValue( "FillGradientName", aGradientName ); 640*cdf0e10cSrcweir String aNewGradientName = AnyConverter.toString( xProp.getPropertyValue( "FillGradientName" )); 641*cdf0e10cSrcweir assure( "GradientName", aNewGradientName.equals( aGradientName )); 642*cdf0e10cSrcweir Gradient aNewGradient = (Gradient) AnyConverter.toObject( 643*cdf0e10cSrcweir new Type( Gradient.class ), 644*cdf0e10cSrcweir xGradientTable.getByName( aNewGradientName )); 645*cdf0e10cSrcweir assure( "Gradient Style", aNewGradient.Style == aGradient.Style ); 646*cdf0e10cSrcweir assure( "Gradient StartColor", aNewGradient.StartColor == aGradient.StartColor ); 647*cdf0e10cSrcweir assure( "Gradient EndColor", aNewGradient.EndColor == aGradient.EndColor ); 648*cdf0e10cSrcweir assure( "Gradient Angle", aNewGradient.Angle == aGradient.Angle ); 649*cdf0e10cSrcweir assure( "Gradient Border", aNewGradient.Border == aGradient.Border ); 650*cdf0e10cSrcweir assure( "Gradient XOffset", aNewGradient.XOffset == aGradient.XOffset ); 651*cdf0e10cSrcweir assure( "Gradient YOffset", aNewGradient.YOffset == aGradient.YOffset ); 652*cdf0e10cSrcweir assure( "Gradient StartIntensity", aNewGradient.StartIntensity == aGradient.StartIntensity ); 653*cdf0e10cSrcweir assure( "Gradient EndIntensity", aNewGradient.EndIntensity == aGradient.EndIntensity ); 654*cdf0e10cSrcweir assure( "Gradient StepCount", aNewGradient.StepCount == aGradient.StepCount ); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir // Hatch 657*cdf0e10cSrcweir xProp = xDia.getDataPointProperties( 1, 0 ); 658*cdf0e10cSrcweir assure( "No DataPointProperties for (1,0)", xProp != null ); 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir // note: the FillHatch property is optional, however it was 661*cdf0e10cSrcweir // supported in the old chart's API 662*cdf0e10cSrcweir XNameContainer xHatchTable = (XNameContainer) UnoRuntime.queryInterface( 663*cdf0e10cSrcweir XNameContainer.class, 664*cdf0e10cSrcweir xFact.createInstance( "com.sun.star.drawing.HatchTable" )); 665*cdf0e10cSrcweir assure( "no hatch table", xHatchTable != null ); 666*cdf0e10cSrcweir String aHatchName = "NewAPITestHatch"; 667*cdf0e10cSrcweir Hatch aHatch = new Hatch(); 668*cdf0e10cSrcweir aHatch.Style = HatchStyle.DOUBLE; 669*cdf0e10cSrcweir aHatch.Color = 0xd2691e; // chocolate 670*cdf0e10cSrcweir aHatch.Distance = 200; // 2 mm (?) 671*cdf0e10cSrcweir aHatch.Angle = 230; // 23 degrees 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir xHatchTable.insertByName( aHatchName, aHatch ); 674*cdf0e10cSrcweir xProp.setPropertyValue( "FillHatchName", aHatchName ); 675*cdf0e10cSrcweir xProp.setPropertyValue( "FillStyle", FillStyle.HATCH ); 676*cdf0e10cSrcweir xProp.setPropertyValue( "FillBackground", new Boolean( true )); 677*cdf0e10cSrcweir String aNewHatchName = AnyConverter.toString( xProp.getPropertyValue( "FillHatchName" )); 678*cdf0e10cSrcweir assure( "HatchName", aNewHatchName.equals( aHatchName )); 679*cdf0e10cSrcweir Hatch aNewHatch = (Hatch) AnyConverter.toObject( 680*cdf0e10cSrcweir new Type( Hatch.class ), 681*cdf0e10cSrcweir xHatchTable.getByName( aNewHatchName )); 682*cdf0e10cSrcweir assure( "Hatch Style", aNewHatch.Style == aHatch.Style ); 683*cdf0e10cSrcweir assure( "Hatch Color", aNewHatch.Color == aHatch.Color ); 684*cdf0e10cSrcweir assure( "Hatch Distance", aNewHatch.Distance == aHatch.Distance ); 685*cdf0e10cSrcweir assure( "Hatch Angle", aNewHatch.Angle == aHatch.Angle ); 686*cdf0e10cSrcweir assure( "FillBackground", AnyConverter.toBoolean( xProp.getPropertyValue( "FillBackground" )) ); 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir catch( Exception ex ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir failed( ex.getMessage() ); 691*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir // ------------ 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir public void testStatistics() 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir try 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir XDiagram xDia = mxOldDoc.getDiagram(); 702*cdf0e10cSrcweir assure( "Invalid Diagram", xDia != null ); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir XPropertySet xProp = xDia.getDataRowProperties( 0 ); 705*cdf0e10cSrcweir assure( "No DataRowProperties for first series", xProp != null ); 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir xProp.setPropertyValue( "MeanValue", new Boolean( true )); 708*cdf0e10cSrcweir assure( "No MeanValue", AnyConverter.toBoolean( xProp.getPropertyValue( "MeanValue" )) ); 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir catch( Exception ex ) 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir failed( ex.getMessage() ); 713*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir // ------------ 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir public void setStockData_Type4() 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir try 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( 724*cdf0e10cSrcweir XPropertySet.class, mxOldDoc.getDiagram() ); 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir ChartDataRowSource eNewSource = ChartDataRowSource.ROWS; 727*cdf0e10cSrcweir xDiaProp.setPropertyValue( "DataRowSource", eNewSource ); 728*cdf0e10cSrcweir assure( "Couldn't set \"DataRowSource\" property at Diagram", 729*cdf0e10cSrcweir AnyConverter.toObject( 730*cdf0e10cSrcweir new Type( ChartDataRowSource.class ), 731*cdf0e10cSrcweir xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource ); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir double aData[][] = 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir { 100.0, 200.0, 300.0, 250.0, 300.0 }, 736*cdf0e10cSrcweir { 6.5, 4.5, 6.0, 5.5, 3.5 }, 737*cdf0e10cSrcweir { 1.0, 1.5, 2.0, 2.5, 3.0 }, 738*cdf0e10cSrcweir { 6.0, 6.5, 7.0, 6.5, 5.0 }, 739*cdf0e10cSrcweir { 6.0, 5.5, 4.0, 4.5, 4.0 } 740*cdf0e10cSrcweir }; 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir String[] aRowDescriptions = 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir "Volume", "Open", "Min", "Max", "Close" 745*cdf0e10cSrcweir }; 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir String[] aColumnDescriptions = 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir "First Row", "Second Row", "Third Row", "Fourth Row", "Fifth Row" 750*cdf0e10cSrcweir }; 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir XChartData xData = mxOldDoc.getData(); 754*cdf0e10cSrcweir XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface( 755*cdf0e10cSrcweir XChartDataArray.class, xData ); 756*cdf0e10cSrcweir assure( "document has no XChartDataArray", xDataArray != null ); 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir xDataArray.setData( aData ); 759*cdf0e10cSrcweir xDataArray.setRowDescriptions( aRowDescriptions ); 760*cdf0e10cSrcweir xDataArray.setColumnDescriptions( aColumnDescriptions ); 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir mxOldDoc.attachData( xData ); 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir catch( Exception ex ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir failed( ex.getMessage() ); 767*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir // ------------ 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir public void testStockProperties() 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir try 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir setStockData_Type4(); 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( 780*cdf0e10cSrcweir XMultiServiceFactory.class, mxOldDoc ); 781*cdf0e10cSrcweir assure( "document is no factory", xFact != null ); 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir String aMyServiceName = new String( "com.sun.star.chart.StockDiagram" ); 784*cdf0e10cSrcweir XDiagram xDia = (XDiagram) UnoRuntime.queryInterface( 785*cdf0e10cSrcweir XDiagram.class, xFact.createInstance( aMyServiceName )); 786*cdf0e10cSrcweir assure( aMyServiceName + " could not be created", xDia != null ); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir mxOldDoc.setDiagram( xDia ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( 791*cdf0e10cSrcweir XPropertySet.class, xDia ); 792*cdf0e10cSrcweir assure( "Diagram is no XPropertySet", xDiaProp != null ); 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir xDiaProp.setPropertyValue( "Volume", new Boolean( true )); 795*cdf0e10cSrcweir assure( "Has Volume", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "Volume" ))); 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir xDiaProp.setPropertyValue( "UpDown", new Boolean( true )); 798*cdf0e10cSrcweir assure( "Has UpDown", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "UpDown" ))); 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir // MinMaxLine 801*cdf0e10cSrcweir XStatisticDisplay xMinMaxProvider = (XStatisticDisplay) UnoRuntime.queryInterface( 802*cdf0e10cSrcweir XStatisticDisplay.class, xDia ); 803*cdf0e10cSrcweir assure( "Diagram is no XStatisticDisplay", xMinMaxProvider != null ); 804*cdf0e10cSrcweir XPropertySet xMinMaxProp = xMinMaxProvider.getMinMaxLine(); 805*cdf0e10cSrcweir assure( "No MinMaxLine", xMinMaxProp != null ); 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir int nLineColor = 0x458b00; // chartreuse4 808*cdf0e10cSrcweir xMinMaxProp.setPropertyValue( "LineColor", new Integer( nLineColor )); 809*cdf0e10cSrcweir int nNewColor = AnyConverter.toInt( xMinMaxProp.getPropertyValue( "LineColor" ) ); 810*cdf0e10cSrcweir assure( "Changing LineColor of MinMax Line", nNewColor == nLineColor ); 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir catch( Exception ex ) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir failed( ex.getMessage() ); 815*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir // ------------ 820*cdf0e10cSrcweir 821*cdf0e10cSrcweir public void testFactory() 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir try 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( 826*cdf0e10cSrcweir XMultiServiceFactory.class, mxOldDoc ); 827*cdf0e10cSrcweir assure( "document is no factory", xFact != null ); 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir Object aTestTable = xFact.createInstance( "com.sun.star.drawing.GradientTable" ); 830*cdf0e10cSrcweir assure( "Couldn't create gradient table via factory", aTestTable != null ); 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir catch( Exception ex ) 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir failed( ex.getMessage() ); 835*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir // ------------ 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir public void testData() 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir try 844*cdf0e10cSrcweir { 845*cdf0e10cSrcweir // set data 846*cdf0e10cSrcweir double aData[][] = { 847*cdf0e10cSrcweir { 1.0, 1.5, 2.0, 2.5, 3.0 }, 848*cdf0e10cSrcweir { 2.0, 2.5, 3.0, 3.5, 4.0 }, 849*cdf0e10cSrcweir { 3.0, 3.5, 4.0, 4.5, 5.0 } 850*cdf0e10cSrcweir }; 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir String[] aColumnDescriptions = { 853*cdf0e10cSrcweir "First Column", "Second Column", "Third Column", 854*cdf0e10cSrcweir "Fourth Column", "Fifth Column" 855*cdf0e10cSrcweir }; 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir String[] aRowDescriptions = { 858*cdf0e10cSrcweir "First Row", "Second Row", "Third Row" 859*cdf0e10cSrcweir }; 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( 862*cdf0e10cSrcweir XPropertySet.class, mxOldDoc.getDiagram() ); 863*cdf0e10cSrcweir ChartDataRowSource eNewSource = ChartDataRowSource.ROWS; 864*cdf0e10cSrcweir xDiaProp.setPropertyValue( "DataRowSource", eNewSource ); 865*cdf0e10cSrcweir assure( "Couldn't set \"DataRowSource\" property at Diagram", 866*cdf0e10cSrcweir AnyConverter.toObject( 867*cdf0e10cSrcweir new Type( ChartDataRowSource.class ), 868*cdf0e10cSrcweir xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource ); 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir XChartData xData = mxOldDoc.getData(); 871*cdf0e10cSrcweir XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface( 872*cdf0e10cSrcweir XChartDataArray.class, xData ); 873*cdf0e10cSrcweir assure( "document has no XChartDataArray", xDataArray != null ); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir xDataArray.setData( aData ); 876*cdf0e10cSrcweir xDataArray.setRowDescriptions( aRowDescriptions ); 877*cdf0e10cSrcweir xDataArray.setColumnDescriptions( aColumnDescriptions ); 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir mxOldDoc.attachData( xData ); 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir // get data 882*cdf0e10cSrcweir double aReadData[][]; 883*cdf0e10cSrcweir String[] aReadColumnDescriptions; 884*cdf0e10cSrcweir String[] aReadRowDescriptions; 885*cdf0e10cSrcweir 886*cdf0e10cSrcweir // refetch data 887*cdf0e10cSrcweir xData = mxOldDoc.getData(); 888*cdf0e10cSrcweir xDataArray = (XChartDataArray) UnoRuntime.queryInterface( 889*cdf0e10cSrcweir XChartDataArray.class, xData ); 890*cdf0e10cSrcweir assure( "document has no XChartDataArray", xDataArray != null ); 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir aReadData = xDataArray.getData(); 893*cdf0e10cSrcweir aReadRowDescriptions = xDataArray.getRowDescriptions(); 894*cdf0e10cSrcweir aReadColumnDescriptions = xDataArray.getColumnDescriptions(); 895*cdf0e10cSrcweir 896*cdf0e10cSrcweir // compare to values set before 897*cdf0e10cSrcweir assure( "Data size differs", aData.length == aReadData.length ); 898*cdf0e10cSrcweir for( int i=0; i<aReadData.length; ++i ) 899*cdf0e10cSrcweir { 900*cdf0e10cSrcweir assure( "Data size differs", aData[i].length == aReadData[i].length ); 901*cdf0e10cSrcweir for( int j=0; j<aReadData[i].length; ++j ) 902*cdf0e10cSrcweir assure( "Data differs", aData[i][j] == aReadData[i][j] ); 903*cdf0e10cSrcweir } 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir assure( "Column Description size differs", aColumnDescriptions.length == aReadColumnDescriptions.length ); 906*cdf0e10cSrcweir for( int i=0; i<aReadColumnDescriptions.length; ++i ) 907*cdf0e10cSrcweir assure( "Column Descriptions differ", aColumnDescriptions[i].equals( aReadColumnDescriptions[i] )); 908*cdf0e10cSrcweir 909*cdf0e10cSrcweir assure( "Row Description size differs", aRowDescriptions.length == aReadRowDescriptions.length ); 910*cdf0e10cSrcweir for( int i=0; i<aReadRowDescriptions.length; ++i ) 911*cdf0e10cSrcweir assure( "Row Descriptions differ", aRowDescriptions[i].equals( aReadRowDescriptions[i] )); 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir catch( Exception ex ) 914*cdf0e10cSrcweir { 915*cdf0e10cSrcweir failed( ex.getMessage() ); 916*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir // ================================================================================ 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir private XModel mxChartModel; 923*cdf0e10cSrcweir private XChartDocument mxOldDoc; 924*cdf0e10cSrcweir private boolean mbCreateView; 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 927*cdf0e10cSrcweir 928*cdf0e10cSrcweir private XModel createDocument( String sDocType ) 929*cdf0e10cSrcweir { 930*cdf0e10cSrcweir XModel aResult = null; 931*cdf0e10cSrcweir try 932*cdf0e10cSrcweir { 933*cdf0e10cSrcweir XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( 934*cdf0e10cSrcweir XComponentLoader.class, 935*cdf0e10cSrcweir ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.frame.Desktop" ) ); 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir aResult = (XModel) UnoRuntime.queryInterface( 938*cdf0e10cSrcweir XModel.class, 939*cdf0e10cSrcweir aLoader.loadComponentFromURL( "private:factory/" + sDocType, 940*cdf0e10cSrcweir "_blank", 941*cdf0e10cSrcweir 0, 942*cdf0e10cSrcweir new PropertyValue[ 0 ] ) ); 943*cdf0e10cSrcweir } 944*cdf0e10cSrcweir catch( Exception ex ) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir failed( ex.getMessage() ); 947*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 948*cdf0e10cSrcweir } 949*cdf0e10cSrcweir 950*cdf0e10cSrcweir return aResult; 951*cdf0e10cSrcweir } 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir // ------------ 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir public XModel createChartModel() 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir XModel aResult = null; 958*cdf0e10cSrcweir try 959*cdf0e10cSrcweir { 960*cdf0e10cSrcweir aResult = (XModel) UnoRuntime.queryInterface( 961*cdf0e10cSrcweir XModel.class, 962*cdf0e10cSrcweir ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.comp.chart2.ChartModel" ) ); 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir catch( Exception ex ) 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir failed( ex.getMessage() ); 967*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 968*cdf0e10cSrcweir } 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir return aResult; 971*cdf0e10cSrcweir } 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir // ------------ 974*cdf0e10cSrcweir 975*cdf0e10cSrcweir private XComponentContext getComponentContext( XMultiServiceFactory xFact ) 976*cdf0e10cSrcweir { 977*cdf0e10cSrcweir XComponentContext xResult = null; 978*cdf0e10cSrcweir 979*cdf0e10cSrcweir XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface( 980*cdf0e10cSrcweir XPropertySet.class, xFact ); 981*cdf0e10cSrcweir if( xProp != null ) 982*cdf0e10cSrcweir try 983*cdf0e10cSrcweir { 984*cdf0e10cSrcweir xResult = (XComponentContext) 985*cdf0e10cSrcweir AnyConverter.toObject( 986*cdf0e10cSrcweir new Type( XComponentContext.class ), 987*cdf0e10cSrcweir xProp.getPropertyValue( "DefaultContext" ) ); 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir catch( Exception ex ) 990*cdf0e10cSrcweir { 991*cdf0e10cSrcweir failed( ex.getMessage() ); 992*cdf0e10cSrcweir ex.printStackTrace( (PrintWriter)log ); 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir return xResult; 996*cdf0e10cSrcweir } 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir // ------------ 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir private void printInterfacesAndServices( Object oObj ) 1001*cdf0e10cSrcweir { 1002*cdf0e10cSrcweir log.println( "Services:" ); 1003*cdf0e10cSrcweir util.dbg.getSuppServices( oObj ); 1004*cdf0e10cSrcweir log.println( "Interfaces:" ); 1005*cdf0e10cSrcweir util.dbg.printInterfaces( (XInterface)oObj, true ); 1006*cdf0e10cSrcweir } 1007*cdf0e10cSrcweir 1008*cdf0e10cSrcweir // ------------ 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir /// see rtl/math.hxx 1011*cdf0e10cSrcweir private boolean approxEqual( double a, double b ) 1012*cdf0e10cSrcweir { 1013*cdf0e10cSrcweir if( a == b ) 1014*cdf0e10cSrcweir return true; 1015*cdf0e10cSrcweir double x = a - b; 1016*cdf0e10cSrcweir return (x < 0.0 ? -x : x) 1017*cdf0e10cSrcweir < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0))); 1018*cdf0e10cSrcweir } 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir // ------------ 1021*cdf0e10cSrcweir /** returns true if a and b differ no more than tolerance. 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir @param tolerance 1024*cdf0e10cSrcweir must be non-negative 1025*cdf0e10cSrcweir */ 1026*cdf0e10cSrcweir private boolean approxEqual( int a, int b, int tolerance ) 1027*cdf0e10cSrcweir { 1028*cdf0e10cSrcweir if( a != b ) 1029*cdf0e10cSrcweir log.println( "Integer values differ by " + java.lang.Math.abs( a-b )); 1030*cdf0e10cSrcweir return ( ( a - tolerance <= b ) || 1031*cdf0e10cSrcweir ( a + tolerance >= b )); 1032*cdf0e10cSrcweir } 1033*cdf0e10cSrcweir } 1034