1 //this script acts as a handler for the buttons in the Highlight dialog
2 importClass(Packages.com.sun.star.uno.UnoRuntime);
3 importClass(Packages.com.sun.star.uno.Type);
4 importClass(Packages.com.sun.star.uno.AnyConverter);
6 importClass(Packages.com.sun.star.awt.XButton);
7 importClass(Packages.com.sun.star.awt.XControl);
8 importClass(Packages.com.sun.star.awt.ActionEvent);
9 importClass(Packages.com.sun.star.awt.XControlModel);
10 importClass(Packages.com.sun.star.awt.XControlContainer);
11 importClass(Packages.com.sun.star.awt.XDialog);
12 importClass(Packages.com.sun.star.awt.XTextComponent);
14 importClass(Packages.com.sun.star.util.XReplaceable);
15 importClass(Packages.com.sun.star.util.XReplaceDescriptor);
16 importClass(Packages.com.sun.star.util.XPropertyReplace);
18 importClass(Packages.com.sun.star.beans.XPropertySet);
19 importClass(Packages.com.sun.star.beans.PropertyValue);
21 // Scripting Framework DialogFactory class
22 importClass(Packages.com.sun.star.script.framework.browse.DialogFactory);
24 // Get the ActionEvent object from the ARGUMENTS list
27 // Each argument is of type Any so we must use the AnyConverter class to
28 // convert it into the interface or primitive type we expect
29 button = AnyConverter.toObject(new Type(XButton), event.Source);
31 // We can now query for the model of the button and get its properties
32 control = UnoRuntime.queryInterface(XControl, button);
33 cmodel = control.getModel();
34 pset = UnoRuntime.queryInterface(XPropertySet, cmodel);
36 if (pset.getPropertyValue("Label").equals("Exit"))
38 // We can get the XDialog in which this control appears by calling
39 // getContext() on the XControl interface
40 xDialog = UnoRuntime.queryInterface(
41 XDialog, control.getContext());
48 // We can get the list of controls for this dialog by calling
49 // getContext() on the XControl interface of the button
50 controls = UnoRuntime.queryInterface(
51 XControlContainer, control.getContext());
53 // Now get the text field control from the list
55 UnoRuntime.queryInterface(
56 XTextComponent, controls.getControl("HighlightTextField"));
58 searchKey = textField.getText();
60 // highlight the text in red
61 red = java.awt.Color.red.getRGB();
64 UnoRuntime.queryInterface(XReplaceable, XSCRIPTCONTEXT.getDocument());
66 descriptor = replaceable.createReplaceDescriptor();
68 // Gets a XPropertyReplace object for altering the properties
69 // of the replaced text
70 xPropertyReplace = UnoRuntime.queryInterface(XPropertyReplace, descriptor);
72 // Sets the replaced text property fontweight value to Bold
73 wv = new PropertyValue("CharWeight", -1,
74 new java.lang.Float(Packages.com.sun.star.awt.FontWeight.BOLD),
75 Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
77 // Sets the replaced text property color value to RGB parameter
78 cv = new PropertyValue("CharColor", -1,
79 new java.lang.Integer(red),
80 Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
82 // Apply the properties
88 xPropertyReplace.setReplaceAttributes(props);
90 // Only matches whole words and case sensitive
91 descriptor.setPropertyValue(
92 "SearchCaseSensitive", new java.lang.Boolean(true));
93 descriptor.setPropertyValue("SearchWords", new java.lang.Boolean(true));
95 // Replaces all instances of searchKey with new Text properties
96 // and gets the number of instances of the searchKey
97 descriptor.setSearchString(searchKey);
98 descriptor.setReplaceString(searchKey);
99 replaceable.replaceAll(descriptor);
102 java.lang.System.err.println("Error setting up search properties"