Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
cedcb9cd
Kaydet (Commit)
cedcb9cd
authored
Şub 06, 2003
tarafından
Tomas O'Connor
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add BeanShell equivalents of Java examples.
Fix MemoryUsage example to use AnyConverter instead of just casting.
üst
528ae502
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
224 additions
and
0 deletions
+224
-0
highlighter.bsh
scripting/examples/beanshell/Highlight/highlighter.bsh
+136
-0
parcel-descriptor.xml
scripting/examples/beanshell/Highlight/parcel-descriptor.xml
+16
-0
interactive.bsh
...g/examples/beanshell/InteractiveBeanShell/interactive.bsh
+1
-0
parcel-descriptor.xml
...ples/beanshell/InteractiveBeanShell/parcel-descriptor.xml
+18
-0
memusage.bsh
scripting/examples/beanshell/MemoryUsage/memusage.bsh
+37
-0
parcel-descriptor.xml
...ting/examples/beanshell/MemoryUsage/parcel-descriptor.xml
+16
-0
No files found.
scripting/examples/beanshell/Highlight/highlighter.bsh
0 → 100644
Dosyayı görüntüle @
cedcb9cd
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XReplaceable;
import com.sun.star.util.XReplaceDescriptor;
import com.sun.star.util.XPropertyReplace;
import com.sun.star.beans.PropertyValue;
import com.sun.star.text.XTextDocument;
import drafts.com.sun.star.script.framework.XScriptContext;
int replaceText(searchKey, color, bold) {
result = 0;
try {
// Create an XReplaceable object and an XReplaceDescriptor
replaceable = (XReplaceable)
UnoRuntime.queryInterface(XReplaceable.class, xTextDocument);
descriptor =
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
// Gets a XPropertyReplace object for altering the properties
// of the replaced text
xPropertyReplace = (XPropertyReplace)
UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
// Sets the replaced text property fontweight value to Bold or Normal
wv = null;
if (bold) {
wv = new PropertyValue("CharWeight", -1,
new Float(com.sun.star.awt.FontWeight.BOLD),
com.sun.star.beans.PropertyState.DIRECT_VALUE);
}
else {
wv = new PropertyValue("CharWeight", -1,
new Float(com.sun.star.awt.FontWeight.NORMAL),
com.sun.star.beans.PropertyState.DIRECT_VALUE);
}
// Sets the replaced text property color value to RGB color parameter
cv = new PropertyValue("CharColor", -1, new Integer(color),
com.sun.star.beans.PropertyState.DIRECT_VALUE);
// Apply the properties
PropertyValue[] props = { cv, wv };
xPropertyReplace.setReplaceAttributes(props);
// Only matches whole words and case sensitive
descriptor.setPropertyValue("SearchCaseSensitive", new Boolean(true));
descriptor.setPropertyValue("SearchWords", new Boolean(true));
// Replaces all instances of searchKey with new Text properties
// and gets the number of instances of the searchKey
descriptor.setSearchString(searchKey);
descriptor.setReplaceString(searchKey);
result = replaceable.replaceAll(descriptor);
}
catch (Exception e) {
}
return result;
}
searchKey = "";
// The context variable is of type XScriptContext and is available to
// all BeanShell scripts executed by the Script Framework
xTextDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, context.getDocument());
// Create a JButton and add an ActionListener
// When clicked the value for the searchKey is read and passed to replaceText
myListener = new ActionListener() {
actionPerformed(ActionEvent e) {
searchKey = findTextBox.getText();
if(searchKey.equalsIgnoreCase("")) {
JOptionPane.showMessageDialog(null,
"No text entered for search",
"No text", JOptionPane.INFORMATION_MESSAGE);
}
else {
// highlight the text in red
cRed = new Color(255, 0, 0);
red = cRed.getRGB();
num = replaceText(searchKey, red, true);
if(num > 0) {
int response = JOptionPane.showConfirmDialog(null,
searchKey + " was found " + num +
" times\nDo you wish to keep the text highlighted?",
"Confirm highlight", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (response == 1) {
cBlack = new Color(255, 255, 255);
black = cBlack.getRGB();
replaceText(searchKey, black, false);
}
}
else {
JOptionPane.showMessageDialog(null,
"No matches were found", "Not found",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
};
searchButton = new JButton("Highlight");
searchButton.addActionListener(myListener);
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(searchButton);
// Create a JPanel containing one JTextField for the search text.
searchPanel = new JPanel();
searchPanel.setLayout(new FlowLayout());
findTextBox = new JTextField(20);
findWhat = new JLabel("Find What: ");
searchPanel.add(findWhat);
searchPanel.add(findTextBox);
// Create frame and add a window listener
frame = new JFrame("Highlight Text");
frame.setSize(350,130);
frame.setLocation(430,430);
frame.setResizable(false);
// Add the panel and button to the frame
frame.getContentPane().setLayout(new GridLayout(2,1,10,10));
frame.getContentPane().add(searchPanel);
frame.getContentPane().add(buttonPanel);
frame.setVisible(true);
frame.pack();
scripting/examples/beanshell/Highlight/parcel-descriptor.xml
0 → 100755
Dosyayı görüntüle @
cedcb9cd
<?xml version="1.0" encoding="UTF-8"?>
<parcel
language=
"BeanShell"
xmlns:parcel=
"scripting.dtd"
>
<script
language=
"BeanShell"
>
<locale
lang=
"en"
>
<displayname
value=
"Highlighter"
/>
<description>
Text highlighting
</description>
</locale>
<functionname
value=
"highlighter.bsh"
/>
<logicalname
value=
"Highlighter.BeanShell"
/>
</script>
</parcel>
scripting/examples/beanshell/InteractiveBeanShell/interactive.bsh
0 → 100755
Dosyayı görüntüle @
cedcb9cd
editor();
scripting/examples/beanshell/InteractiveBeanShell/parcel-descriptor.xml
0 → 100644
Dosyayı görüntüle @
cedcb9cd
<?xml version="1.0" encoding="UTF-8"?>
<parcel
xmlns:parcel=
"scripting.dtd"
>
<script
language=
"BeanShell"
>
<locale
lang=
"en"
>
<displayname
value=
"Interactive BeanShell"
/>
<description>
Pops up a window into which you can type BeanShell code and run it against the current document
</description>
</locale>
<functionname
value=
"interactive.bsh"
/>
<logicalname
value=
"Interactive.BeanShell"
/>
<languagedepprops>
</languagedepprops>
</script>
</parcel>
scripting/examples/beanshell/MemoryUsage/memusage.bsh
0 → 100644
Dosyayı görüntüle @
cedcb9cd
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.lang.XComponent;
import com.sun.star.container.XIndexAccess;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.sheet.XSpreadsheet;
import drafts.com.sun.star.script.framework.XScriptContext;
addEntry(date, total, free) {
// The context variable is of type XScriptContext and is available to
// all BeanShell scripts executed by the Script Framework
comp = context.getDocument();
doc = (XSpreadsheetDocument)
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
index = (XIndexAccess)
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
sheet = (XSpreadsheet) AnyConverter.toObject(
new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
sheet.getCellByPosition(0, 1).setValue(total - free);
sheet.getCellByPosition(1, 1).setValue(free);
sheet.getCellByPosition(2, 1).setValue(total);
sheet.getCellByPosition(0, 2).setFormula(date);
}
runtime = Runtime.getRuntime();
generator = new Random();
date = new Date();
len = (int)(generator.nextFloat() * runtime.freeMemory() / 5);
bytes = new byte[len];
addEntry(date.toString(), runtime.totalMemory(), runtime.freeMemory());
scripting/examples/beanshell/MemoryUsage/parcel-descriptor.xml
0 → 100644
Dosyayı görüntüle @
cedcb9cd
<?xml version="1.0" encoding="UTF-8"?>
<parcel
language=
"BeanShell"
xmlns:parcel=
"scripting.dtd"
>
<script
language=
"BeanShell"
>
<locale
lang=
"en"
>
<displayname
value=
"BeanShell JVM Usage"
/>
<description>
Updates a spreadsheet with the current memory usage statistics for the Java Virtual Machine
</description>
</locale>
<functionname
value=
"memusage.bsh"
/>
<logicalname
value=
"MemoryUsage.BeanShell"
/>
</script>
</parcel>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment