products/Sources/formale Sprachen/Isabelle/Tools/jEdit/dist/doc/users-guide/macro-analysis.html |
 |
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Analysis of the Macro</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="jEdit 5.6 User's Guide"><link rel="up" href="dialog-macro.html" title="Chapter 14. A Dialog-Based Macro"><link rel="prev" href="add-prefix-and-suffix.html" title="Listing of the Macro"><link rel="next" href="macro-tips.html" title="Chapter 15. Macro Tips and Techniques"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Analysis of the Macro</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="add-prefix-and-suffix.html">Prev</a> </td><th width="60%" align="center">Chapter 14. A Dialog-Based Macro</th><td width="20%" align="right"> <a accesskey="n" href="macro-tips.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="macro-analysis"></a>Analysis of the Macro</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="explain-imports"></a>Import Statements</h3></div></div></div><div class="informalexample"><pre class="programlisting">// import statement
import javax.swing.border.*;</pre></div><p>This macro makes use of classes in the
<code class="literal">javax.swing.border</code> package, which is not
automatically imported. As we mentioned previously (see <a class="xref" href="first-example.html" title="The Mandatory First Example">the section called “The Mandatory First Example”</a>), jEdit's implementation of BeanShell
causes a number of classes to be automatically imported. Classes
that are not automatically imported must be identified by a full
qualified name or be the subject of an <code class="function">import</code>
statement.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="explain-create-dialog"></a>Create the Dialog</h3></div></div></div><div class="informalexample"><pre class="programlisting">// create dialog object
title = <span class="quote">“<span class="quote">Add prefix and suffix to selected lines</span>”</span>;
dialog = new JDialog(view, title, false);
content = new JPanel(new BorderLayout());
content.setBorder(new EmptyBorder(12, 12, 12, 12));
dialog.setContentPane(content);</pre></div><p>To get input for the macro, we need a dialog that provides for
input of the prefix and suffix strings, an <span class="guibutton"><strong>OK</strong></span>
button to perform text insertion, and a
<span class="guibutton"><strong>Cancel</strong></span> button in case we change our mind. We
have decided to make the dialog window non-modal. This will allow us
to move around in the text buffer to find things we may need
(including text to cut and paste) while the macro is running and the
dialog is visible.</p><p>The Java object we need is a <code class="classname">JDialog</code>
object from the Swing package. To construct one, we use the
<code class="function">new</code> keyword and call a
<em class="glossterm">constructor</em> function. The constructor we use
takes three parameters: the owner of the new dialog, the title to be
displayed in the dialog frame, and a <code class="classname">boolean</code>
parameter (<code class="constant">true</code> or <code class="constant">false</code>)
that specifies whether the dialog will be modal or non-modal. We
define the variable <code class="varname">title</code> using a string literal,
then use it immediately in the <code class="classname">JDialog</code>
constructor.</p><p>A <code class="classname">JDialog</code> object is a window containing
a single object called a <em class="glossterm">content pane</em>. The
content pane in turn contains the various visible components of the
dialog. A <code class="classname">JDialog</code> creates an empty content
pane for itself as during its construction. However, to control the
dialog's appearance as much as possible, we will separately create
our own content pane and attach it to the
<code class="classname">JDialog</code>. We do this by creating a
<code class="classname">JPanel</code> object. A
<code class="classname">JPanel</code> is a lightweight container for other
components that can be set to a given size and color. It also
contains a <em class="glossterm">layout</em> scheme for arranging the
size and position of its components. Here we are constructing a
<code class="classname">JPanel</code> as a content pane with a
<code class="classname">BorderLayout</code>. We put a
<code class="classname">EmptyBorder</code> inside it to serve as a margin
between the edge of the window and the components inside. We then
attach the <code class="classname">JPanel</code> as the dialog's content
pane, replacing the dialog's home-grown version.A BorderLayout is one of the simpler
layout schemes available for container objects like
<code class="classname">JPanel</code>. A <code class="classname">BorderLayout</code>
divides the container into five sections: <span class="quote">“<span class="quote">North</span>”</span>,
<span class="quote">“<span class="quote">South</span>”</span>, <span class="quote">“<span class="quote">East</span>”</span>, <span class="quote">“<span class="quote">West</span>”</span> and
<span class="quote">“<span class="quote">Center</span>”</span>. Components are added to the layout using the
container's add method, specifying the
component to be added and the section to which it is assigned.
Building a component like our dialog window involves building a set
of nested containers and specifying the location of each of their
member components. We have taken the first step by creating a
<code class="classname">JPanel</code> as the dialog's content pane. |
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|