2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 //this script acts as a handler for the buttons in the Highlight dialog
19 importClass(Packages.com.sun.star.uno.UnoRuntime);
20 importClass(Packages.com.sun.star.uno.Type);
21 importClass(Packages.com.sun.star.uno.AnyConverter);
23 importClass(Packages.com.sun.star.awt.XButton);
24 importClass(Packages.com.sun.star.awt.XControl);
25 importClass(Packages.com.sun.star.awt.ActionEvent);
26 importClass(Packages.com.sun.star.awt.XControlModel);
27 importClass(Packages.com.sun.star.awt.XControlContainer);
28 importClass(Packages.com.sun.star.awt.XDialog);
29 importClass(Packages.com.sun.star.awt.XTextComponent);
31 importClass(Packages.com.sun.star.util.XReplaceable);
32 importClass(Packages.com.sun.star.util.XReplaceDescriptor);
33 importClass(Packages.com.sun.star.util.XPropertyReplace);
35 importClass(Packages.com.sun.star.beans.XPropertySet);
36 importClass(Packages.com.sun.star.beans.PropertyValue);
38 // Scripting Framework DialogFactory class
39 importClass(Packages.com.sun.star.script.framework.browse.DialogFactory);
41 // Get the ActionEvent object from the ARGUMENTS list
44 // Each argument is of type Any so we must use the AnyConverter class to
45 // convert it into the interface or primitive type we expect
46 button = AnyConverter.toObject(new Type(XButton), event.Source);
48 // We can now query for the model of the button and get its properties
49 control = UnoRuntime.queryInterface(XControl, button);
50 cmodel = control.getModel();
51 pset = UnoRuntime.queryInterface(XPropertySet, cmodel);
53 if (pset.getPropertyValue("Label").equals("Exit"))
55 // We can get the XDialog in which this control appears by calling
56 // getContext() on the XControl interface
57 xDialog = UnoRuntime.queryInterface(
58 XDialog, control.getContext());
65 // We can get the list of controls for this dialog by calling
66 // getContext() on the XControl interface of the button
67 controls = UnoRuntime.queryInterface(
68 XControlContainer, control.getContext());
70 // Now get the text field control from the list
72 UnoRuntime.queryInterface(
73 XTextComponent, controls.getControl("HighlightTextField"));
75 searchKey = textField.getText();
77 // highlight the text in red
78 red = java.awt.Color.red.getRGB();
81 UnoRuntime.queryInterface(XReplaceable, XSCRIPTCONTEXT.getDocument());
83 descriptor = replaceable.createReplaceDescriptor();
85 // Gets a XPropertyReplace object for altering the properties
86 // of the replaced text
87 xPropertyReplace = UnoRuntime.queryInterface(XPropertyReplace, descriptor);
89 // Sets the replaced text property fontweight value to Bold
90 wv = new PropertyValue("CharWeight", -1,
91 new java.lang.Float(Packages.com.sun.star.awt.FontWeight.BOLD),
92 Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
94 // Sets the replaced text property color value to RGB parameter
95 cv = new PropertyValue("CharColor", -1,
96 new java.lang.Integer(red),
97 Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
99 // Apply the properties
105 xPropertyReplace.setReplaceAttributes(props);
107 // Only matches whole words and case sensitive
108 descriptor.setPropertyValue(
109 "SearchCaseSensitive", new java.lang.Boolean(true));
110 descriptor.setPropertyValue("SearchWords", new java.lang.Boolean(true));
112 // Replaces all instances of searchKey with new Text properties
113 // and gets the number of instances of the searchKey
114 descriptor.setSearchString(searchKey);
115 descriptor.setReplaceString(searchKey);
116 replaceable.replaceAll(descriptor);
119 java.lang.System.err.println("Error setting up search properties"