⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicgraphicsutils.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* BasicGraphicsUtils.java   Copyright (C) 2003 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.basic;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Insets;import java.awt.Rectangle;import java.awt.font.FontRenderContext;import java.awt.font.LineMetrics;import java.awt.font.TextLayout;import java.awt.geom.Rectangle2D;import javax.swing.AbstractButton;import javax.swing.SwingUtilities;/** * A utility class providing commonly used drawing and measurement * routines. * * @author Sascha Brawer (brawer@dandelis.ch) */public class BasicGraphicsUtils{  /**   * Constructor. It is utterly unclear why this class should   * be constructable, but this is what the API specification   * says.   */  public BasicGraphicsUtils()  {  }  /**   * Draws a rectangle that appears etched into the surface, given   * four colors that are used for drawing.   *   * <p><img src="doc-files/BasicGraphicsUtils-1.png" width="360"   * height="200" alt="[An illustration that shows which pixels   * get painted in what color]" />   *   * @param g the graphics into which the rectangle is drawn.   * @param x the x coordinate of the rectangle.   * @param y the y coordinate of the rectangle.   * @param width the width of the rectangle in pixels.   * @param height the height of the rectangle in pixels.   *   * @param shadow the color that will be used for painting   *        the outer side of the top and left edges.   *   * @param darkShadow the color that will be used for painting   *        the inner side of the top and left edges.   *   * @param highlight the color that will be used for painting   *        the inner side of the bottom and right edges.   *   * @param lightHighlight the color that will be used for painting   *        the outer side of the bottom and right edges.   *   * @see #getEtchedInsets()   * @see javax.swing.border.EtchedBorder   */  public static void drawEtchedRect(Graphics g,                                    int x, int y, int width, int height,                                    Color shadow, Color darkShadow,                                    Color highlight, Color lightHighlight)  {    Color oldColor;    int x2, y2;    oldColor = g.getColor();    x2 = x + width - 1;    y2 = y + height - 1;    try    {      /* To understand this code, it might be helpful to look at the       * image "BasicGraphicsUtils-1.png" that is included with the       * JavaDoc. The file is located in the "doc-files" subdirectory.       *       * (x2, y2) is the coordinate of the most right and bottom pixel       * to be painted.       */      g.setColor(shadow);      g.drawLine(x, y, x2 - 1, y);                     // top, outer      g.drawLine(x, y + 1, x, y2 - 1);                 // left, outer      g.setColor(darkShadow);      g.drawLine(x + 1, y + 1, x2 - 2, y + 1);         // top, inner      g.drawLine(x + 1, y + 2, x + 1, y2 - 2);         // left, inner            g.setColor(highlight);      g.drawLine(x + 1, y2 - 1, x2 - 1, y2 - 1);       // bottom, inner      g.drawLine(x2 - 1, y + 1, x2 - 1, y2 - 2);       // right, inner      g.setColor(lightHighlight);      g.drawLine(x, y2, x2, y2);                       // bottom, outer      g.drawLine(x2, y, x2, y2 - 1);                   // right, outer    }    finally    {      g.setColor(oldColor);    }  }      /**   * Determines the width of the border that gets painted by   * {@link #drawEtchedRect}.   *   * @return an <code>Insets</code> object whose <code>top</code>,   *         <code>left</code>, <code>bottom</code> and   *         <code>right</code> field contain the border width at the   *         respective edge in pixels.   */  public static Insets getEtchedInsets()  {    return new Insets(2, 2, 2, 2);  }  /**   * Draws a rectangle that appears etched into the surface, given   * two colors that are used for drawing.   *   * <p><img src="doc-files/BasicGraphicsUtils-2.png" width="360"   * height="200" alt="[An illustration that shows which pixels   * get painted in what color]" />   *   * @param g the graphics into which the rectangle is drawn.   * @param x the x coordinate of the rectangle.   * @param y the y coordinate of the rectangle.   * @param width the width of the rectangle in pixels.   * @param height the height of the rectangle in pixels.   *   * @param shadow the color that will be used for painting the outer   *        side of the top and left edges, and for the inner side of   *        the bottom and right ones.   *   * @param highlight the color that will be used for painting the   *        inner side of the top and left edges, and for the outer   *        side of the bottom and right ones.   *   * @see #getGrooveInsets()   * @see javax.swing.border.EtchedBorder   */  public static void drawGroove(Graphics g,                                int x, int y, int width, int height,                                Color shadow, Color highlight)  {    /* To understand this, it might be helpful to look at the image     * "BasicGraphicsUtils-2.png" that is included with the JavaDoc,     * and to compare it with "BasicGraphicsUtils-1.png" which shows     * the pixels painted by drawEtchedRect.  These image files are     * located in the "doc-files" subdirectory.     */    drawEtchedRect(g, x, y, width, height,                   /* outer topLeft */     shadow,                   /* inner topLeft */     highlight,                   /* inner bottomRight */ shadow,                   /* outer bottomRight */ highlight);  }  /**   * Determines the width of the border that gets painted by   * {@link #drawGroove}.   *   * @return an <code>Insets</code> object whose <code>top</code>,   *         <code>left</code>, <code>bottom</code> and   *         <code>right</code> field contain the border width at the   *         respective edge in pixels.   */  public static Insets getGrooveInsets()  {    return new Insets(2, 2, 2, 2);  }    /**   * Draws a border that is suitable for buttons of the Basic look and   * feel.   *   * <p><img src="doc-files/BasicGraphicsUtils-3.png" width="500"   * height="300" alt="[An illustration that shows which pixels   * get painted in what color]" />   *   * @param g the graphics into which the rectangle is drawn.   * @param x the x coordinate of the rectangle.   * @param y the y coordinate of the rectangle.   * @param width the width of the rectangle in pixels.   * @param height the height of the rectangle in pixels.   *   * @param isPressed <code>true</code> to draw the button border   *        with a pressed-in appearance; <code>false</code> for   *        normal (unpressed) appearance.   *   * @param isDefault <code>true</code> to draw the border with   *        the appearance it has when hitting the enter key in a   *        dialog will simulate a click to this button;   *        <code>false</code> for normal appearance.   *   * @param shadow the shadow color.   * @param darkShadow a darker variant of the shadow color.   * @param highlight the highlight color.   * @param lightHighlight a brighter variant of the highlight  color.   */  public static void drawBezel(Graphics g,                               int x, int y, int width, int height,                               boolean isPressed, boolean isDefault,                               Color shadow, Color darkShadow,                               Color highlight, Color lightHighlight)  {    Color oldColor = g.getColor();    /* To understand this, it might be helpful to look at the image     * "BasicGraphicsUtils-3.png" that is included with the JavaDoc,     * and to compare it with "BasicGraphicsUtils-1.png" which shows     * the pixels painted by drawEtchedRect.  These image files are     * located in the "doc-files" subdirectory.     */    try    {      if ((isPressed == false) && (isDefault == false))      {        drawEtchedRect(g, x, y, width, height,                       lightHighlight, highlight,                       shadow, darkShadow);      }      if ((isPressed == true) && (isDefault == false))      {        g.setColor(shadow);        g.drawRect(x + 1, y + 1, width - 2, height - 2);      }      if ((isPressed == false) && (isDefault == true))      {        g.setColor(darkShadow);        g.drawRect(x, y, width - 1, height - 1);        drawEtchedRect(g, x + 1, y + 1, width - 2, height - 2,                       lightHighlight, highlight,                       shadow, darkShadow);      }      if ((isPressed == true) && (isDefault == true))      {        g.setColor(darkShadow);        g.drawRect(x, y, width - 1, height - 1);        g.setColor(shadow);        g.drawRect(x + 1, y + 1, width - 3, height - 3);      }    }    finally    {      g.setColor(oldColor);    }  }      /**   * Draws a rectangle that appears lowered into the surface, given   * four colors that are used for drawing.   *   * <p><img src="doc-files/BasicGraphicsUtils-4.png" width="360"   * height="200" alt="[An illustration that shows which pixels   * get painted in what color]" />   *   * <p><strong>Compatibility with the Sun reference   * implementation:</strong> The Sun reference implementation seems   * to ignore the <code>x</code> and <code>y</code> arguments, at   * least in JDK 1.3.1 and 1.4.1_01.  The method always draws the   * rectangular area at location (0, 0). A bug report has been filed   * with Sun; its &#x201c;bug ID&#x201d; is 4880003.  The GNU Classpath   * implementation behaves correctly, thus not replicating this bug.   *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -