1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.drawing; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo; 26cdf0e10cSrcweir import lib.MultiPropertyTest; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.awt.XBitmap; 29cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 30cdf0e10cSrcweir import com.sun.star.uno.Type; 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** 33cdf0e10cSrcweir * Testing <code>com.sun.star.drawing.FillProperties</code> 34cdf0e10cSrcweir * service properties : 35cdf0e10cSrcweir * <ul> 36cdf0e10cSrcweir * <li><code> FillStyle</code></li> 37cdf0e10cSrcweir * <li><code> FillColor</code></li> 38cdf0e10cSrcweir * <li><code> FillTransparence</code></li> 39cdf0e10cSrcweir * <li><code> FillTransparenceGradientName</code></li> 40cdf0e10cSrcweir * <li><code> FillTransparenceGradient</code></li> 41cdf0e10cSrcweir * <li><code> FillGradientName</code></li> 42cdf0e10cSrcweir * <li><code> FillGradient</code></li> 43cdf0e10cSrcweir * <li><code> FillHatchName</code></li> 44cdf0e10cSrcweir * <li><code> FillHatch</code></li> 45cdf0e10cSrcweir * <li><code> FillBitmapName</code></li> 46cdf0e10cSrcweir * <li><code> FillBitmap</code></li> 47cdf0e10cSrcweir * <li><code> FillBitmapURL</code></li> 48cdf0e10cSrcweir * <li><code> FillBitmapOffsetX</code></li> 49cdf0e10cSrcweir * <li><code> FillBitmapOffsetY</code></li> 50cdf0e10cSrcweir * <li><code> FillBitmapPositionOffsetX</code></li> 51cdf0e10cSrcweir * <li><code> FillBitmapPositionOffsetY</code></li> 52cdf0e10cSrcweir * <li><code> FillBitmapRectanglePoint</code></li> 53cdf0e10cSrcweir * <li><code> FillBitmapLogicalSize</code></li> 54cdf0e10cSrcweir * <li><code> FillBitmapSizeX</code></li> 55cdf0e10cSrcweir * <li><code> FillBitmapSizeY</code></li> 56cdf0e10cSrcweir * <li><code> FillBitmapMode</code></li> 57cdf0e10cSrcweir * <li><code> FillBackground</code></li> 58cdf0e10cSrcweir * </ul> <p> 59cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>. 60cdf0e10cSrcweir * @see com.sun.star.drawing.FillProperties 61cdf0e10cSrcweir */ 62cdf0e10cSrcweir public class _FillProperties extends MultiPropertyTest { 63cdf0e10cSrcweir 64cdf0e10cSrcweir XBitmap the_bitmap = null; 65cdf0e10cSrcweir XBitmap the_secondBitmap = null; 66cdf0e10cSrcweir /** 67cdf0e10cSrcweir * Property tester which changes URL. 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir protected PropertyTester URLTester = new PropertyTester() { 70cdf0e10cSrcweir 71cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 72cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 73cdf0e10cSrcweir if (oldValue.equals(util.utils.getFullTestURL("space-metal.jpg"))) { 74cdf0e10cSrcweir return util.utils.getFullTestURL("crazy-blue.jpg"); 75cdf0e10cSrcweir } else { 76cdf0e10cSrcweir return util.utils.getFullTestURL("space-metal.jpg"); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir /** 81cdf0e10cSrcweir * Property tester which switches two strings. 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir protected PropertyTester StringTester = new PropertyTester() { 84cdf0e10cSrcweir 85cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 86cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 87cdf0e10cSrcweir if (oldValue.equals(str1)) { 88cdf0e10cSrcweir return str2; 89cdf0e10cSrcweir } else { 90cdf0e10cSrcweir return str1; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir /** 95cdf0e10cSrcweir * Property tester which switches two XBitmap objects. 96cdf0e10cSrcweir */ 97cdf0e10cSrcweir protected PropertyTester BitmapTester = new PropertyTester() { 98cdf0e10cSrcweir 99cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) 100cdf0e10cSrcweir throws java.lang.IllegalArgumentException { 101cdf0e10cSrcweir if (util.ValueComparer.equalValue(oldValue, the_bitmap)) { 102cdf0e10cSrcweir return the_secondBitmap; 103cdf0e10cSrcweir } else { 104cdf0e10cSrcweir return the_bitmap; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir }; 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** 110cdf0e10cSrcweir * This property must have an URL format 111cdf0e10cSrcweir */ _FillBitmapURL()112cdf0e10cSrcweir public void _FillBitmapURL() { 113cdf0e10cSrcweir log.println("Testing with custom Property tester"); 114cdf0e10cSrcweir testProperty("FillBitmapURL", URLTester); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir public String str1 = ""; 117cdf0e10cSrcweir public String str2 = ""; 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** 120cdf0e10cSrcweir * This property must have predefined values 121cdf0e10cSrcweir */ _FillGradientName()122cdf0e10cSrcweir public void _FillGradientName() { 123cdf0e10cSrcweir log.println("Testing with custom Property tester"); 124cdf0e10cSrcweir str1 = "Gradient 1"; 125cdf0e10cSrcweir str2 = "Gradient 3"; 126cdf0e10cSrcweir testProperty("FillGradientName", StringTester); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir /** 130cdf0e10cSrcweir * This property must have predefined values 131cdf0e10cSrcweir */ _FillBitmapName()132cdf0e10cSrcweir public void _FillBitmapName() { 133cdf0e10cSrcweir log.println("Testing with custom Property tester"); 134cdf0e10cSrcweir str1 = "Sky"; 135cdf0e10cSrcweir str2 = "Blank"; 136cdf0e10cSrcweir testProperty("FillBitmapName", StringTester); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** 140cdf0e10cSrcweir * This property must have predefined values 141cdf0e10cSrcweir */ _FillTransparenceGradientName()142cdf0e10cSrcweir public void _FillTransparenceGradientName() { 143cdf0e10cSrcweir log.println("Testing with custom Property tester"); 144cdf0e10cSrcweir str1 = "Transparency 2"; 145cdf0e10cSrcweir str2 = "Transparency 1"; 146cdf0e10cSrcweir testProperty("FillTransparenceGradientName", StringTester); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir /** 150cdf0e10cSrcweir * This property must have predefined values 151cdf0e10cSrcweir */ _FillHatchName()152cdf0e10cSrcweir public void _FillHatchName() { 153cdf0e10cSrcweir log.println("Testing with custom Property tester"); 154cdf0e10cSrcweir str1 = "Black 0 degrees"; 155cdf0e10cSrcweir str2 = "Black 45 degrees"; 156cdf0e10cSrcweir testProperty("FillHatchName", StringTester); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir /** 160cdf0e10cSrcweir * This property is very interesting. After setting URL of bitmap you get 161cdf0e10cSrcweir * <code>XBitmap</code> interface of the image file specified. 162cdf0e10cSrcweir * The method first gets two different bitmaps and then tests the property. 163cdf0e10cSrcweir */ _FillBitmap()164cdf0e10cSrcweir public void _FillBitmap() { 165cdf0e10cSrcweir 166cdf0e10cSrcweir String propName = "FillBitmap"; 167cdf0e10cSrcweir 168cdf0e10cSrcweir XPropertySetInfo info = oObj.getPropertySetInfo(); 169cdf0e10cSrcweir 170cdf0e10cSrcweir if (!info.hasPropertyByName(propName)) { 171cdf0e10cSrcweir if (isOptional(propName)) { 172cdf0e10cSrcweir // skipping optional property test 173cdf0e10cSrcweir log.println("Property '" + propName + "' is optional and not supported"); 174cdf0e10cSrcweir tRes.tested(propName, true); 175cdf0e10cSrcweir return; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } else { 178cdf0e10cSrcweir 179cdf0e10cSrcweir try { 180cdf0e10cSrcweir 181cdf0e10cSrcweir oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("crazy-blue.jpg")); 182cdf0e10cSrcweir 183cdf0e10cSrcweir the_bitmap = (XBitmap) AnyConverter.toObject( 184cdf0e10cSrcweir new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap")); 185cdf0e10cSrcweir 186cdf0e10cSrcweir oObj.setPropertyValue("FillBitmapURL", util.utils.getFullTestURL("space-metal.jpg")); 187cdf0e10cSrcweir 188cdf0e10cSrcweir the_secondBitmap = (XBitmap) AnyConverter.toObject( 189cdf0e10cSrcweir new Type(XBitmap.class), oObj.getPropertyValue("FillBitmap")); 190cdf0e10cSrcweir 191cdf0e10cSrcweir testProperty("FillBitmap", BitmapTester); 192cdf0e10cSrcweir 193cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e) { 194cdf0e10cSrcweir log.println("Couldn't change Bitmap"); 195cdf0e10cSrcweir e.printStackTrace(log); 196cdf0e10cSrcweir tRes.tested("FillBitmap", false); 197cdf0e10cSrcweir 198cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e) { 199cdf0e10cSrcweir log.println("Couldn't change Bitmap"); 200cdf0e10cSrcweir e.printStackTrace(log); 201cdf0e10cSrcweir tRes.tested("FillBitmap", false); 202cdf0e10cSrcweir 203cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 204cdf0e10cSrcweir log.println("Couldn't change Bitmap"); 205cdf0e10cSrcweir e.printStackTrace(log); 206cdf0e10cSrcweir tRes.tested("FillBitmap", false); 207cdf0e10cSrcweir 208cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 209cdf0e10cSrcweir log.println("Couldn't change Bitmap"); 210cdf0e10cSrcweir e.printStackTrace(log); 211cdf0e10cSrcweir tRes.tested("FillBitmap", false); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir } 215cdf0e10cSrcweir } 216