src/share/classes/javax/swing/text/JTextComponent.java

Print this page




  67 
  68 import javax.print.attribute.*;
  69 
  70 import sun.awt.AppContext;
  71 
  72 
  73 import sun.swing.PrintingStatus;
  74 import sun.swing.SwingUtilities2;
  75 import sun.swing.text.TextComponentPrintable;
  76 import sun.swing.SwingAccessor;
  77 
  78 /**
  79  * <code>JTextComponent</code> is the base class for swing text
  80  * components.  It tries to be compatible with the
  81  * <code>java.awt.TextComponent</code> class
  82  * where it can reasonably do so.  Also provided are other services
  83  * for additional flexibility (beyond the pluggable UI and bean
  84  * support).
  85  * You can find information on how to use the functionality
  86  * this class provides in
  87  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html">General Rules for Using Text Components</a>,
  88  * a section in <em>The Java Tutorial.</em>
  89  *
  90  * <p>
  91  * <dl>
  92  * <dt><b><font size=+1>Caret Changes</font></b>
  93  * <dd>
  94  * The caret is a pluggable object in swing text components.
  95  * Notification of changes to the caret position and the selection
  96  * are sent to implementations of the <code>CaretListener</code>
  97  * interface that have been registered with the text component.
  98  * The UI will install a default caret unless a customized caret
  99  * has been set. <br>
 100  * By default the caret tracks all the document changes
 101  * performed on the Event Dispatching Thread and updates it's position
 102  * accordingly if an insertion occurs before or at the caret position
 103  * or a removal occurs before the caret position. <code>DefaultCaret</code>
 104  * tries to make itself visible which may lead to scrolling
 105  * of a text component within <code>JScrollPane</code>. The default caret
 106  * behavior can be changed by the {@link DefaultCaret#setUpdatePolicy} method.
 107  * <br>


2198      * being processed until printing is complete. It is only
2199      * recommended when printing from an application with no
2200      * visible GUI.
2201      *
2202      * <p>
2203      * Note: In <i>headless</i> mode, {@code showPrintDialog} and
2204      * {@code interactive} parameters are ignored and no dialogs are
2205      * shown.
2206      *
2207      * <p>
2208      * This method ensures the {@code document} is not mutated during printing.
2209      * To indicate it visually, {@code setEnabled(false)} is set for the
2210      * duration of printing.
2211      *
2212      * <p>
2213      * This method uses {@link #getPrintable} to render document content.
2214      *
2215      * <p>
2216      * This method is thread-safe, although most Swing methods are not. Please
2217      * see <A
2218      * HREF="http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html">
2219      * Concurrency in Swing</A> for more information.
2220      *
2221      * <p>
2222      * <b>Sample Usage</b>. This code snippet shows a cross-platform print
2223      * dialog and then prints the {@code JTextComponent} in <i>interactive</i> mode
2224      * unless the user cancels the dialog:
2225      *
2226      * <pre>
2227      * textComponent.print(new MessageFormat(&quot;My text component header&quot;),
2228      *     new MessageFormat(&quot;Footer. Page - {0}&quot;), true, null, null, true);
2229      * </pre>
2230      * <p>
2231      * Executing this code off the <i>Event Dispatch Thread</i>
2232      * performs printing on the <i>background</i>.
2233      * The following pattern might be used for <i>background</i>
2234      * printing:
2235      * <pre>
2236      *     FutureTask&lt;Boolean&gt; future =
2237      *         new FutureTask&lt;Boolean&gt;(
2238      *             new Callable&lt;Boolean&gt;() {


2456      * ensure that the {@code document} is not mutated while this {@code Printable}
2457      * is used. Printing behavior is undefined when the {@code document} is
2458      * mutated during printing.
2459      *
2460      * <p>
2461      * Page header and footer text can be added to the output by providing
2462      * {@code MessageFormat} arguments. The printing code requests
2463      * {@code Strings} from the formats, providing a single item which may be
2464      * included in the formatted string: an {@code Integer} representing the
2465      * current page number.
2466      *
2467      * <p>
2468      * The returned {@code Printable} when printed, formats the
2469      * document content appropriately for the page size. For correct
2470      * line wrapping the {@code imageable width} of all pages must be the
2471      * same. See {@link java.awt.print.PageFormat#getImageableWidth}.
2472      *
2473      * <p>
2474      * This method is thread-safe, although most Swing methods are not. Please
2475      * see <A
2476      * HREF="http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html">
2477      * Concurrency in Swing</A> for more information.
2478      *
2479      * <p>
2480      * The returned {@code Printable} can be printed on any thread.
2481      *
2482      * <p>
2483      * This implementation returned {@code Printable} performs all painting on
2484      * the <i>Event Dispatch Thread</i>, regardless of what thread it is
2485      * used on.
2486      *
2487      * @param headerFormat the text, in {@code MessageFormat}, to be
2488      *        used as the header, or {@code null} for no header
2489      * @param footerFormat the text, in {@code MessageFormat}, to be
2490      *        used as the footer, or {@code null} for no footer
2491      * @return a {@code Printable} for use in printing content of this
2492      *         {@code JTextComponent}
2493      *
2494      *
2495      * @see java.awt.print.Printable
2496      * @see java.awt.print.PageFormat




  67 
  68 import javax.print.attribute.*;
  69 
  70 import sun.awt.AppContext;
  71 
  72 
  73 import sun.swing.PrintingStatus;
  74 import sun.swing.SwingUtilities2;
  75 import sun.swing.text.TextComponentPrintable;
  76 import sun.swing.SwingAccessor;
  77 
  78 /**
  79  * <code>JTextComponent</code> is the base class for swing text
  80  * components.  It tries to be compatible with the
  81  * <code>java.awt.TextComponent</code> class
  82  * where it can reasonably do so.  Also provided are other services
  83  * for additional flexibility (beyond the pluggable UI and bean
  84  * support).
  85  * You can find information on how to use the functionality
  86  * this class provides in
  87  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html">General Rules for Using Text Components</a>,
  88  * a section in <em>The Java Tutorial.</em>
  89  *
  90  * <p>
  91  * <dl>
  92  * <dt><b><font size=+1>Caret Changes</font></b>
  93  * <dd>
  94  * The caret is a pluggable object in swing text components.
  95  * Notification of changes to the caret position and the selection
  96  * are sent to implementations of the <code>CaretListener</code>
  97  * interface that have been registered with the text component.
  98  * The UI will install a default caret unless a customized caret
  99  * has been set. <br>
 100  * By default the caret tracks all the document changes
 101  * performed on the Event Dispatching Thread and updates it's position
 102  * accordingly if an insertion occurs before or at the caret position
 103  * or a removal occurs before the caret position. <code>DefaultCaret</code>
 104  * tries to make itself visible which may lead to scrolling
 105  * of a text component within <code>JScrollPane</code>. The default caret
 106  * behavior can be changed by the {@link DefaultCaret#setUpdatePolicy} method.
 107  * <br>


2198      * being processed until printing is complete. It is only
2199      * recommended when printing from an application with no
2200      * visible GUI.
2201      *
2202      * <p>
2203      * Note: In <i>headless</i> mode, {@code showPrintDialog} and
2204      * {@code interactive} parameters are ignored and no dialogs are
2205      * shown.
2206      *
2207      * <p>
2208      * This method ensures the {@code document} is not mutated during printing.
2209      * To indicate it visually, {@code setEnabled(false)} is set for the
2210      * duration of printing.
2211      *
2212      * <p>
2213      * This method uses {@link #getPrintable} to render document content.
2214      *
2215      * <p>
2216      * This method is thread-safe, although most Swing methods are not. Please
2217      * see <A
2218      * HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">
2219      * Concurrency in Swing</A> for more information.
2220      *
2221      * <p>
2222      * <b>Sample Usage</b>. This code snippet shows a cross-platform print
2223      * dialog and then prints the {@code JTextComponent} in <i>interactive</i> mode
2224      * unless the user cancels the dialog:
2225      *
2226      * <pre>
2227      * textComponent.print(new MessageFormat(&quot;My text component header&quot;),
2228      *     new MessageFormat(&quot;Footer. Page - {0}&quot;), true, null, null, true);
2229      * </pre>
2230      * <p>
2231      * Executing this code off the <i>Event Dispatch Thread</i>
2232      * performs printing on the <i>background</i>.
2233      * The following pattern might be used for <i>background</i>
2234      * printing:
2235      * <pre>
2236      *     FutureTask&lt;Boolean&gt; future =
2237      *         new FutureTask&lt;Boolean&gt;(
2238      *             new Callable&lt;Boolean&gt;() {


2456      * ensure that the {@code document} is not mutated while this {@code Printable}
2457      * is used. Printing behavior is undefined when the {@code document} is
2458      * mutated during printing.
2459      *
2460      * <p>
2461      * Page header and footer text can be added to the output by providing
2462      * {@code MessageFormat} arguments. The printing code requests
2463      * {@code Strings} from the formats, providing a single item which may be
2464      * included in the formatted string: an {@code Integer} representing the
2465      * current page number.
2466      *
2467      * <p>
2468      * The returned {@code Printable} when printed, formats the
2469      * document content appropriately for the page size. For correct
2470      * line wrapping the {@code imageable width} of all pages must be the
2471      * same. See {@link java.awt.print.PageFormat#getImageableWidth}.
2472      *
2473      * <p>
2474      * This method is thread-safe, although most Swing methods are not. Please
2475      * see <A
2476      * HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">
2477      * Concurrency in Swing</A> for more information.
2478      *
2479      * <p>
2480      * The returned {@code Printable} can be printed on any thread.
2481      *
2482      * <p>
2483      * This implementation returned {@code Printable} performs all painting on
2484      * the <i>Event Dispatch Thread</i>, regardless of what thread it is
2485      * used on.
2486      *
2487      * @param headerFormat the text, in {@code MessageFormat}, to be
2488      *        used as the header, or {@code null} for no header
2489      * @param footerFormat the text, in {@code MessageFormat}, to be
2490      *        used as the footer, or {@code null} for no footer
2491      * @return a {@code Printable} for use in printing content of this
2492      *         {@code JTextComponent}
2493      *
2494      *
2495      * @see java.awt.print.Printable
2496      * @see java.awt.print.PageFormat