1*d71964d5SAndrew Rist// ************************************************************* 2*d71964d5SAndrew Rist// 3*d71964d5SAndrew Rist// Licensed to the Apache Software Foundation (ASF) under one 4*d71964d5SAndrew Rist// or more contributor license agreements. See the NOTICE file 5*d71964d5SAndrew Rist// distributed with this work for additional information 6*d71964d5SAndrew Rist// regarding copyright ownership. The ASF licenses this file 7*d71964d5SAndrew Rist// to you under the Apache License, Version 2.0 (the 8*d71964d5SAndrew Rist// "License"); you may not use this file except in compliance 9*d71964d5SAndrew Rist// with the License. You may obtain a copy of the License at 10*d71964d5SAndrew Rist// 11*d71964d5SAndrew Rist// http://www.apache.org/licenses/LICENSE-2.0 12*d71964d5SAndrew Rist// 13*d71964d5SAndrew Rist// Unless required by applicable law or agreed to in writing, 14*d71964d5SAndrew Rist// software distributed under the License is distributed on an 15*d71964d5SAndrew Rist// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d71964d5SAndrew Rist// KIND, either express or implied. See the License for the 17*d71964d5SAndrew Rist// specific language governing permissions and limitations 18*d71964d5SAndrew Rist// under the License. 19*d71964d5SAndrew Rist// 20*d71964d5SAndrew Rist// ************************************************************* 21cdf0e10cSrcweir//this script acts as a handler for the buttons in the Highlight dialog 22cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.UnoRuntime); 23cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.Type); 24cdf0e10cSrcweirimportClass(Packages.com.sun.star.uno.AnyConverter); 25cdf0e10cSrcweir 26cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XButton); 27cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XControl); 28cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.ActionEvent); 29cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XControlModel); 30cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XControlContainer); 31cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XDialog); 32cdf0e10cSrcweirimportClass(Packages.com.sun.star.awt.XTextComponent); 33cdf0e10cSrcweir 34cdf0e10cSrcweirimportClass(Packages.com.sun.star.util.XReplaceable); 35cdf0e10cSrcweirimportClass(Packages.com.sun.star.util.XReplaceDescriptor); 36cdf0e10cSrcweirimportClass(Packages.com.sun.star.util.XPropertyReplace); 37cdf0e10cSrcweir 38cdf0e10cSrcweirimportClass(Packages.com.sun.star.beans.XPropertySet); 39cdf0e10cSrcweirimportClass(Packages.com.sun.star.beans.PropertyValue); 40cdf0e10cSrcweir 41cdf0e10cSrcweir// Scripting Framework DialogFactory class 42cdf0e10cSrcweirimportClass(Packages.com.sun.star.script.framework.browse.DialogFactory); 43cdf0e10cSrcweir 44cdf0e10cSrcweir// Get the ActionEvent object from the ARGUMENTS list 45cdf0e10cSrcweirevent = ARGUMENTS[0]; 46cdf0e10cSrcweir 47cdf0e10cSrcweir// Each argument is of type Any so we must use the AnyConverter class to 48cdf0e10cSrcweir// convert it into the interface or primitive type we expect 49cdf0e10cSrcweirbutton = AnyConverter.toObject(new Type(XButton), event.Source); 50cdf0e10cSrcweir 51cdf0e10cSrcweir// We can now query for the model of the button and get its properties 52cdf0e10cSrcweircontrol = UnoRuntime.queryInterface(XControl, button); 53cdf0e10cSrcweircmodel = control.getModel(); 54cdf0e10cSrcweirpset = UnoRuntime.queryInterface(XPropertySet, cmodel); 55cdf0e10cSrcweir 56cdf0e10cSrcweirif (pset.getPropertyValue("Label").equals("Exit")) 57cdf0e10cSrcweir{ 58cdf0e10cSrcweir // We can get the XDialog in which this control appears by calling 59cdf0e10cSrcweir // getContext() on the XControl interface 60cdf0e10cSrcweir xDialog = UnoRuntime.queryInterface( 61cdf0e10cSrcweir XDialog, control.getContext()); 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Close the dialog 64cdf0e10cSrcweir xDialog.endExecute(); 65cdf0e10cSrcweir} 66cdf0e10cSrcweirelse 67cdf0e10cSrcweir{ 68cdf0e10cSrcweir // We can get the list of controls for this dialog by calling 69cdf0e10cSrcweir // getContext() on the XControl interface of the button 70cdf0e10cSrcweir controls = UnoRuntime.queryInterface( 71cdf0e10cSrcweir XControlContainer, control.getContext()); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // Now get the text field control from the list 74cdf0e10cSrcweir textField = 75cdf0e10cSrcweir UnoRuntime.queryInterface( 76cdf0e10cSrcweir XTextComponent, controls.getControl("HighlightTextField")); 77cdf0e10cSrcweir 78cdf0e10cSrcweir searchKey = textField.getText(); 79cdf0e10cSrcweir 80cdf0e10cSrcweir // highlight the text in red 81cdf0e10cSrcweir red = java.awt.Color.red.getRGB(); 82cdf0e10cSrcweir 83cdf0e10cSrcweir replaceable = 84cdf0e10cSrcweir UnoRuntime.queryInterface(XReplaceable, XSCRIPTCONTEXT.getDocument()); 85cdf0e10cSrcweir 86cdf0e10cSrcweir descriptor = replaceable.createReplaceDescriptor(); 87cdf0e10cSrcweir 88cdf0e10cSrcweir // Gets a XPropertyReplace object for altering the properties 89cdf0e10cSrcweir // of the replaced text 90cdf0e10cSrcweir xPropertyReplace = UnoRuntime.queryInterface(XPropertyReplace, descriptor); 91cdf0e10cSrcweir 92cdf0e10cSrcweir // Sets the replaced text property fontweight value to Bold 93cdf0e10cSrcweir wv = new PropertyValue("CharWeight", -1, 94cdf0e10cSrcweir new java.lang.Float(Packages.com.sun.star.awt.FontWeight.BOLD), 95cdf0e10cSrcweir Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE); 96cdf0e10cSrcweir 97cdf0e10cSrcweir // Sets the replaced text property color value to RGB parameter 98cdf0e10cSrcweir cv = new PropertyValue("CharColor", -1, 99cdf0e10cSrcweir new java.lang.Integer(red), 100cdf0e10cSrcweir Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // Apply the properties 103cdf0e10cSrcweir props = new Array; 104cdf0e10cSrcweir props[0] = cv; 105cdf0e10cSrcweir props[1] = wv; 106cdf0e10cSrcweir 107cdf0e10cSrcweir try { 108cdf0e10cSrcweir xPropertyReplace.setReplaceAttributes(props); 109cdf0e10cSrcweir 110cdf0e10cSrcweir // Only matches whole words and case sensitive 111cdf0e10cSrcweir descriptor.setPropertyValue( 112cdf0e10cSrcweir "SearchCaseSensitive", new java.lang.Boolean(true)); 113cdf0e10cSrcweir descriptor.setPropertyValue("SearchWords", new java.lang.Boolean(true)); 114cdf0e10cSrcweir 115cdf0e10cSrcweir // Replaces all instances of searchKey with new Text properties 116cdf0e10cSrcweir // and gets the number of instances of the searchKey 117cdf0e10cSrcweir descriptor.setSearchString(searchKey); 118cdf0e10cSrcweir descriptor.setReplaceString(searchKey); 119cdf0e10cSrcweir replaceable.replaceAll(descriptor); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir catch (e) { 122cdf0e10cSrcweir java.lang.System.err.println("Error setting up search properties" 123cdf0e10cSrcweir + e.getMessage()); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir} 126