1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="plugin-tips">
<title>Plugin Tips and Techniques</title>
<!-- jEdit buffer-local properties: -->
<!-- :tabSize=2:indentSize=2:noTabs=true: -->
<!-- :xml.root=users-guide.xml: -->
<section id="utility-classes">
<title> Utility Classes </title>
<para> If you need to check what the current running platform is,
see <classname>org.gjt.sp.jedit.OperatingSystem</classname>. </para>
<para> If you need to compare file names and don't want to
worry about whether you are on a case-sensitive file system or not,
use <function>MiscUtilities.pathsEqual()</function>. See that
class for other useful path manipulation routines. </para>
<para> There are other helpful classes in <package>org.gjt.sp.util</package>,
such as <classname>HtmlUtilities</classname>, <classname>StandardUtilities</classname>,
<classname>IOUtilities</classname>, and <classname>Log</classname>.
In particular, the <classname>Log</classname> class is recommended
for reporting errors and also logging debug information.
</para>
<para> If your plugin needs to "find a word" (using word boundaries) somewhere
in the buffer, you might want to reuse the <classname>org.gjt.sp.jedit.TextUtilities</classname>
class. </para>
</section>
<section id="plugin-tips-libraries">
<title>Bundling Additional Class Libraries</title>
<para>Recall that any class whose name ends with
<classname>Plugin.class</classname> is called a plugin core class. JAR
files with no plugin core classes are also loaded by jEdit; the classes
they contain are made available to other plugins. Many plugins that rely
on third-party class libraries ship them as separate JAR files. The
libraries will be available inside the jEdit environment but are not
part of a general classpath or library collection when running other
Java applications.</para>
<para>A plugin that bundles extra JAR files must list them in the
<filename>plugin.<replaceable>class name</replaceable>.jars</filename>
property. See the documentation for the <ulink
url="../api/org/gjt/sp/jedit/EditPlugin.html">
<classname>EditPlugin</classname></ulink> class for details.</para>
</section>
<section id="plugin-tips-non-java-libraries">
<title>Bundling Additional Non-Java Libraries</title>
<para>If your plugin bundles non-Java files, like native libraries, you
need to list them in the <filename>plugin.<replaceable>class
name</replaceable>.files</filename> property. If you don't do so, they
don't get deleted if the plugin is uninstalled. See the documentation
for the <ulink url="../api/org/gjt/sp/jedit/EditPlugin.html">
<classname>EditPlugin</classname></ulink> class for details.</para>
</section>
<section id="plugin-tips-plugin-data">
<title>Storing plugin data</title>
<para>If your plugin needs to create files and store data in the
filesystem, you should use the <methodname>getPluginHome()</methodname>
API of the <classname>EditPlugin</classname> class. To signal that you
use the plugin home API you have to set the
<filename>plugin.<replaceable>class
name</replaceable>.usePluginHome</filename> property to
<constant>true</constant>. Even if your plugin doesn't create any files,
you should set the property to <constant>true</constant>, so that e. g.
the plugin manager knows that there is actually no data in favor of not
knowing if there is any data and thus displaying that it doesn't know
the data size. See the documentation for the <ulink
url="../api/org/gjt/sp/jedit/EditPlugin.html"><classname>EditPlugin</classname></ulink>
class for details.</para>
</section>
<section id="plugin-tips-colors">
<title>Plugin colors</title>
<para>There are a number of colors used by the View that should also be
used by plugins where possible. This helps promote a consistent color
scheme throughout jEdit.
</para><para>
The main color properties are:
</para>
<itemizedlist>
<listitem><para><literal>view.bgColor</literal> - the background color of the main text area</para></listitem>
<listitem><para><literal>view.fgColor</literal> - the base foreground color for text in the main text area</para></listitem>
<listitem><para><literal>view.lineHighlightColor</literal> - color of the current line highlight</para></listitem>
<listitem><para><literal>view.selectionColor</literal> - the color of selected text in the main text area</para></listitem>
<listitem><para><literal>view.caretColor</literal> - the color of the caret in the main text area</para></listitem>
<listitem><para><literal>view.eolMarkerColor</literal> - the color of the end-of-line marker</para></listitem>
</itemizedlist>
<para>
To use these colors in your plugin, use
<programlisting>jEdit.getColorProperty("view.whatever", default_color)</programlisting>
</para>
<para>
For example, the QuickNotepad example should have lines like this:
</para>
<programlisting>
textarea.setBackground(jEdit.getColorProperty("view.bgColor", Color.WHITE));
textarea.setForeground(jEdit.getColorProperty("view.fgColor", Color.BLACK));
</programlisting><para>
This sets the foreground and background colors of QuickNotepad to be the same
as those in the View.
</para>
<para>
There are other color properties that may be useful, depending on what your
plugin displays.
</para>
<para>
Gutter colors:
</para><itemizedlist>
<listitem><para><literal>view.gutter.bgColor</literal></para></listitem>
<listitem><para><literal>view.gutter.currentLineColor</literal></para></listitem>
<listitem><para><literal>view.gutter.fgColor</literal></para></listitem>
<listitem><para><literal>view.gutter.focusBorderColor</literal></para></listitem>
<listitem><para><literal>view.gutter.foldColor</literal></para></listitem>
<listitem><para><literal>view.gutter.highlightColor</literal></para></listitem>
<listitem><para><literal>view.gutter.markerColor</literal></para></listitem>
<listitem><para><literal>view.gutter.noFocusBorderColor</literal></para></listitem>
<listitem><para><literal>view.gutter.registerColor</literal></para></listitem>
<listitem><para><literal>view.gutter.structureHighlightColor</literal></para></listitem>
</itemizedlist>
<para>
Status bar colors:
</para>
<itemizedlist>
<listitem><para><literal>view.status.background</literal></para></listitem>
<listitem><para><literal>view.status.foreground</literal></para></listitem>
<listitem><para><literal>view.status.memory.background</literal></para></listitem>
<listitem><para><literal>view.status.memory.foreground</literal></para></listitem>
</itemizedlist>
<para>
</para><para>
Structure highlight colors:
</para><itemizedlist>
<listitem><para><literal>view.structureHighlightColor</literal></para></listitem>
<listitem><para><literal>view.structureHighlightColor</literal></para></listitem>
</itemizedlist>
<para>
Style colors. Use <classname>GUIUtilities.parseStyle</classname> for these.
</para>
<itemizedlist>
<listitem><para><literal>view.style.comment1</literal></para></listitem>
<listitem><para><literal>view.style.comment2</literal></para></listitem>
<listitem><para><literal>view.style.comment3</literal></para></listitem>
<listitem><para><literal>view.style.comment4</literal></para></listitem>
<listitem><para><literal>view.style.digit</literal></para></listitem>
<listitem><para><literal>view.style.foldLine.0</literal></para></listitem>
<listitem><para><literal>view.style.foldLine.1</literal></para></listitem>
<listitem><para><literal>view.style.foldLine.2</literal></para></listitem>
<listitem><para><literal>view.style.foldLine.3</literal></para></listitem>
<listitem><para><literal>view.style.function</literal></para></listitem>
<listitem><para><literal>view.style.invalid</literal></para></listitem>
<listitem><para><literal>view.style.keyword1</literal></para></listitem>
<listitem><para><literal>view.style.keyword2</literal></para></listitem>
<listitem><para><literal>view.style.keyword3</literal></para></listitem>
<listitem><para><literal>view.style.keyword4</literal></para></listitem>
<listitem><para><literal>view.style.label</literal></para></listitem>
<listitem><para><literal>view.style.literal1</literal></para></listitem>
<listitem><para><literal>view.style.literal2</literal></para></listitem>
<listitem><para><literal>view.style.literal3</literal></para></listitem>
<listitem><para><literal>view.style.literal4</literal></para></listitem>
<listitem><para><literal>view.style.markup</literal></para></listitem>
<listitem><para><literal>view.style.operator</literal></para></listitem>
<listitem><para><literal>view.wrapGuideColor</literal></para></listitem>
</itemizedlist>
<para>
For example, here is a setting for a fold line color:
</para>
<programlisting>
view.style.foldLine.0=color\:\#000000 bgColor\:\#f5deb8 style\:b
</programlisting>
<para>
Passing the value to <classname>GUIUtilities.parseStyle</classname> will
return a SyntaxStyle object, which you can query for background color,
foreground color, and font.
</para>
</section>
</chapter>
|