jdk/src/share/classes/java/awt/Graphics.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.io.*;
  28 import java.lang.*;

  29 import java.util.*;
  30 import java.awt.image.ImageObserver;
  31 import java.text.AttributedCharacterIterator;
  32 
  33 /**
  34  * The <code>Graphics</code> class is the abstract base class for
  35  * all graphics contexts that allow an application to draw onto
  36  * components that are realized on various devices, as well as
  37  * onto off-screen images.
  38  * <p>
  39  * A <code>Graphics</code> object encapsulates state information needed
  40  * for the basic rendering operations that Java supports.  This
  41  * state information includes the following properties:
  42  * <p>
  43  * <ul>
  44  * <li>The <code>Component</code> object on which to draw.
  45  * <li>A translation origin for rendering and clipping coordinates.
  46  * <li>The current clip.
  47  * <li>The current color.
  48  * <li>The current font.


 827      * graphics context's current font and color. The baseline of the
 828      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 829      * graphics context's coordinate system.
 830      * <p>
 831      * Use of this method is not recommended as each byte is interpreted
 832      * as a Unicode code point in the range 0 to 255, and so can only be
 833      * used to draw Latin characters in that range.
 834      * @param data the data to be drawn
 835      * @param offset the start offset in the data
 836      * @param length the number of bytes that are drawn
 837      * @param x the <i>x</i> coordinate of the baseline of the text
 838      * @param y the <i>y</i> coordinate of the baseline of the text
 839      * @throws NullPointerException if <code>data</code> is <code>null</code>.
 840      * @throws IndexOutOfBoundsException if <code>offset</code> or
 841      * <code>length</code>is less than zero, or <code>offset+length</code>
 842      * is greater than the length of the <code>data</code> array.
 843      * @see         java.awt.Graphics#drawChars
 844      * @see         java.awt.Graphics#drawString
 845      */
 846     public void drawBytes(byte data[], int offset, int length, int x, int y) {
 847         drawString(new String(data, 0, offset, length), x, y);
 848     }
 849 
 850     /**
 851      * Draws as much of the specified image as is currently available.
 852      * The image is drawn with its top-left corner at
 853      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
 854      * space. Transparent pixels in the image do not affect whatever
 855      * pixels are already there.
 856      * <p>
 857      * This method returns immediately in all cases, even if the
 858      * complete image has not yet been loaded, and it has not been dithered
 859      * and converted for the current output device.
 860      * <p>
 861      * If the image has completely loaded and its pixels are
 862      * no longer being changed, then
 863      * <code>drawImage</code> returns <code>true</code>.
 864      * Otherwise, <code>drawImage</code> returns <code>false</code>
 865      * and as more of
 866      * the image becomes available
 867      * or it is time to draw another frame of animation,




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.io.*;
  28 import java.lang.*;
  29 import java.nio.charset.StandardCharsets;
  30 import java.util.*;
  31 import java.awt.image.ImageObserver;
  32 import java.text.AttributedCharacterIterator;
  33 
  34 /**
  35  * The <code>Graphics</code> class is the abstract base class for
  36  * all graphics contexts that allow an application to draw onto
  37  * components that are realized on various devices, as well as
  38  * onto off-screen images.
  39  * <p>
  40  * A <code>Graphics</code> object encapsulates state information needed
  41  * for the basic rendering operations that Java supports.  This
  42  * state information includes the following properties:
  43  * <p>
  44  * <ul>
  45  * <li>The <code>Component</code> object on which to draw.
  46  * <li>A translation origin for rendering and clipping coordinates.
  47  * <li>The current clip.
  48  * <li>The current color.
  49  * <li>The current font.


 828      * graphics context's current font and color. The baseline of the
 829      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 830      * graphics context's coordinate system.
 831      * <p>
 832      * Use of this method is not recommended as each byte is interpreted
 833      * as a Unicode code point in the range 0 to 255, and so can only be
 834      * used to draw Latin characters in that range.
 835      * @param data the data to be drawn
 836      * @param offset the start offset in the data
 837      * @param length the number of bytes that are drawn
 838      * @param x the <i>x</i> coordinate of the baseline of the text
 839      * @param y the <i>y</i> coordinate of the baseline of the text
 840      * @throws NullPointerException if <code>data</code> is <code>null</code>.
 841      * @throws IndexOutOfBoundsException if <code>offset</code> or
 842      * <code>length</code>is less than zero, or <code>offset+length</code>
 843      * is greater than the length of the <code>data</code> array.
 844      * @see         java.awt.Graphics#drawChars
 845      * @see         java.awt.Graphics#drawString
 846      */
 847     public void drawBytes(byte data[], int offset, int length, int x, int y) {
 848         drawString(new String(data, offset, length, StandardCharsets.ISO_8859_1), x, y);
 849     }
 850 
 851     /**
 852      * Draws as much of the specified image as is currently available.
 853      * The image is drawn with its top-left corner at
 854      * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
 855      * space. Transparent pixels in the image do not affect whatever
 856      * pixels are already there.
 857      * <p>
 858      * This method returns immediately in all cases, even if the
 859      * complete image has not yet been loaded, and it has not been dithered
 860      * and converted for the current output device.
 861      * <p>
 862      * If the image has completely loaded and its pixels are
 863      * no longer being changed, then
 864      * <code>drawImage</code> returns <code>true</code>.
 865      * Otherwise, <code>drawImage</code> returns <code>false</code>
 866      * and as more of
 867      * the image becomes available
 868      * or it is time to draw another frame of animation,