<?xml version="1.0" encoding="UTF-8"?>
<chapter id="plugin-tips">
    <title>Plugin Tips and Techniques</title>
    <!-- jEdit buffer-local properties: -->
    <!-- :tabSize=1:indentSize=1:noTabs=true: -->
    <!-- :xml.root=users-guide.xml: -->

    <sect1 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>
    </sect1>

    <sect1 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>
    </sect1>

    <sect1 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>
    </sect1>
    
    <sect1 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>view.bgColor - the background color of the main text area</listitem>
          <listitem>view.fgColor - the base foreground color for text in the main text area</listitem>
          <listitem>view.lineHighlightColor - color of the current line highlight</listitem>
          <listitem>view.selectionColor - the color of selected text in the main text area</listitem>
          <listitem>view.caretColor - the color of the caret in the main text area</listitem>
          <listitem>view.eolMarkerColor - the color of the end-of-line marker</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>view.gutter.bgColor</listitem>
         <listitem>view.gutter.currentLineColor</listitem>
         <listitem>view.gutter.fgColor</listitem>
         <listitem>view.gutter.focusBorderColor</listitem>
         <listitem>view.gutter.foldColor</listitem>
         <listitem>view.gutter.highlightColor</listitem>
         <listitem>view.gutter.markerColor</listitem>
         <listitem>view.gutter.noFocusBorderColor</listitem>
         <listitem>view.gutter.registerColor</listitem>
         <listitem>view.gutter.structureHighlightColor</listitem>
         </itemizedlist>
         <para>
        Status bar colors:
        </para>
        <itemizedlist>
          <listitem>view.status.background</listitem>
          <listitem>view.status.foreground</listitem>
          <listitem>view.status.memory.background</listitem>
          <listitem>view.status.memory.foreground</listitem>
         </itemizedlist>
         <para>
        </para><para>
        Structure highlight colors:
        </para><itemizedlist>
         <listitem>view.structureHighlightColor</listitem>
         <listitem>view.structureHighlightColor</listitem>
         </itemizedlist>
        <para>
        Style colors.  Use <classname>GUIUtilities.parseStyle</classname> for these.
        </para>
        <itemizedlist>
          <listitem>view.style.comment1</listitem>
          <listitem>view.style.comment2</listitem>
          <listitem>view.style.comment3</listitem>
          <listitem>view.style.comment4</listitem>
          <listitem>view.style.digit</listitem>
          <listitem>view.style.foldLine.0</listitem>
          <listitem>view.style.foldLine.1</listitem>
          <listitem>view.style.foldLine.2</listitem>
          <listitem>view.style.foldLine.3</listitem>
          <listitem>view.style.function</listitem>
          <listitem>view.style.invalid</listitem>
          <listitem>view.style.keyword1</listitem>
          <listitem>view.style.keyword2</listitem>
          <listitem>view.style.keyword3</listitem>
          <listitem>view.style.keyword4</listitem>
          <listitem>view.style.label</listitem>
          <listitem>view.style.literal1</listitem>
          <listitem>view.style.literal2</listitem>
          <listitem>view.style.literal3</listitem>
          <listitem>view.style.literal4</listitem>
          <listitem>view.style.markup</listitem>
          <listitem>view.style.operator</listitem>
          <listitem>view.wrapGuideColor</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>
     </sect1>
</chapter>
