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

📄 basicborders.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                           int x, int y,                           Rectangle rect)    {      if (rect == null)        return;      /* On each edge, the border exceeds the enclosed child by one       * pixel. See the image "BasicBorders.SplitPaneBorder-1.png" in       * the directory "doc-files".       */      x += rect.x - 1;      y += rect.y - 1;      int right = x + rect.width + 1;      int bottom = y + rect.height + 1;            Color oldColor = g.getColor();      try      {        g.setColor(shadow);        if ((suppress & SUPPRESS_TOP) == 0)          g.drawLine(x, y, right, y);        if ((suppress & SUPPRESS_LEFT) == 0)          g.drawLine(x, y, x, bottom);        else          g.drawLine(x, bottom, x, bottom); // one pixel        g.setColor(highlight);        if ((suppress & SUPPRESS_BOTTOM) == 0)          g.drawLine(x + (shadeBottomLeftPixel ? 1 : 0), bottom, right, bottom);        else if (!shadeBottomLeftPixel)          g.drawLine(x, bottom, x, bottom); // one pixel        if ((suppress & SUPPRESS_RIGHT) == 0)          g.drawLine(right, y, right, bottom);      }      finally      {        g.setColor(oldColor);      }    }        /**     * Measures the width of this border.     *     * @param c the component whose border is to be measured, usually     *        an instance of {@link javax.swing.JSplitPane}.     *     * @return an Insets object whose <code>left</code>,     *         <code>right</code>, <code>top</code> and     *         <code>bottom</code> fields indicate the width of the     *         border at the respective edge.     */    public Insets getBorderInsets(Component c)    {      return new Insets(1, 1, 1, 1);    }    /**     * Determines whether this border fills every pixel in its area     * when painting.     *     * @return <code>false</code> because this border does not     *         paint over the pixels where the divider joins     *         the border.     */    public boolean isBorderOpaque()    {      /* Strangely, the Sun implementation (tested with JDK 1.3.1 and       * 1.4.1_01) seems to always return true. It could be a bug,       * but without knowing the details of their implementation, it is       * hard to decide.       */      return false;    }  }  /**   * A border for the divider inside a JSplitPane.   *   * <p><img src="doc-files/BasicBorders.SplitPaneDividerBorder-1.png"   * width="520" height="200" alt="[A screen shot of this border]" />   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  private static class SplitPaneDividerBorder    implements Border, UIResource, Serializable  {    /**     * The highlight color, which is drawn on the left or top edge     * depending on the orientation of the JSplitPanel.     */    protected Color highlight;    /**     * The highlight color, which is drawn on the right or bottom edge     * depending on the orientation of the JSplitPanel.     */    protected Color shadow;    /**     * Constructs a new border for drawing the divider of a JSplitPane     * in the Basic look and feel.  The outer parts of the JSplitPane have     * their own border class, <code>SplitPaneBorder</code>.     *     * @param shadow the shadow color.     * @param highlight the highlight color.     */    public SplitPaneDividerBorder(Color highlight, Color shadow)    {      this.highlight = (highlight != null) ? highlight : Color.white;      this.shadow = (shadow != null) ? shadow : Color.black;    }    /**     * Paints the border around the divider of a <code>JSplitPane</code>.     *     * <p><img src="doc-files/BasicBorders.SplitPaneDividerBorder-1.png"     * width="520" height="200" alt="[A picture that shows which pixels     * get painted in what color]" />     *     * @param c the <code>JSplitPane</code> whose divider&#x2019;s border     *        is to be painted.     * @param g the graphics for painting.     * @param x the horizontal position for painting the border.     * @param y the vertical position for painting the border.     * @param width the width of the available area for painting the border.     * @param height the height of the available area for painting the border.     */    public void paintBorder(Component c, Graphics  g,                            int x, int y, int width, int height)    {      Color oldColor, dcol;      int x2, y2;      JSplitPane sp;      sp = getSplitPane(c);      if (sp == null)        return;      x2 = x + width - 1;      y2 = y + height - 1;      oldColor = g.getColor();      dcol = c.getBackground();      try      {        switch (sp.getOrientation())        {        case JSplitPane.HORIZONTAL_SPLIT:          g.setColor(dcol);          g.drawLine(x + 1, y, x2 - 1, y);          g.drawLine(x + 1, y2, x2 - 1, y2);          g.setColor(sp.getLeftComponent() != null ? highlight : dcol);          g.drawLine(x, y, x, y2);          g.setColor(sp.getRightComponent() != null ? shadow : dcol);          g.drawLine(x2, y, x2, y2);          break;        case JSplitPane.VERTICAL_SPLIT:          g.setColor(dcol);          g.drawLine(x, y + 1, x, y2 - 1);          g.drawLine(x2, y + 1, x2, y2 - 1);          g.setColor(sp.getTopComponent() != null ? highlight : dcol);          g.drawLine(x, y, x2, y);          g.setColor(sp.getBottomComponent() != null ? shadow : dcol);          g.drawLine(x, y2, x2, y2);          break;        }      }      finally      {        g.setColor(oldColor);      }    }    /**     * Measures the width of this border.     *     * @param c the component whose border is to be measured, usually     *        an instance of {@link javax.swing.JSplitPane}.     *     * @return an Insets object whose <code>left</code>,     *         <code>right</code>, <code>top</code> and     *         <code>bottom</code> fields indicate the width of the     *         border at the respective edge.     */    public Insets getBorderInsets(Component c)    {      return new Insets(1, 1, 1, 1);    }    /**     * Determines whether this border fills every pixel in its area     * when painting.     *     * @return <code>true</code> if both highlight and shadow     *         color are fully opaque.     */    public boolean isBorderOpaque()    {      return (highlight.getAlpha() == 255) && (shadow.getAlpha() == 255);    }        /**     * Determines the JSplitPane whose divider is being painted.     *     * @param c an instance of BasicSplitPaneDivider.     *     * @return a <code>JSplitPane</code>, or <code>null</code> if     *         <code>c</code> is not an instance of {@link     *         javax.swing.plaf.basic.BasicSplitPaneDivider}.     */    private JSplitPane getSplitPane(Component c)    {      if (c instanceof BasicSplitPaneDivider)        return (((BasicSplitPaneDivider) c).getBasicSplitPaneUI())          .getSplitPane();      else        return null;    }  }  /**   * A border for toggle buttons in the Basic look and feel.   *   * <p><img src="doc-files/BasicBorders.ToggleButtonBorder-1.png"   * width="270" height="135" alt="[A screen shot of this border]" />   *   * <p>The Sun implementation always seems to draw exactly   * the same border, irrespective of the state of the button.   * This is rather surprising, but GNU Classpath emulates the   * observable behavior.   *   * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class ToggleButtonBorder    extends ButtonBorder  {    /**     * Determined using the <code>serialver</code> tool     * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.     */    static final long serialVersionUID = -3528666548001058394L;        /**     * Constructs a new border for drawing a JToggleButton in     * the Basic look and feel.     *     * @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 ToggleButtonBorder(Color shadow, Color darkShadow,                              Color highlight, Color lightHighlight)    {      /* The superclass ButtonBorder substitutes null arguments       * with fallback colors.       */      super(shadow, darkShadow, highlight, lightHighlight);    }    /**     * Paints the ToggleButtonBorder around a given component.     *     * <p>The Sun implementation always seems to draw exactly     * the same border, irrespective of the state of the button.     * This is rather surprising, but GNU Classpath emulates the     * observable behavior.     *     * @param c the component whose border is to be painted.     * @param g the graphics for painting.     * @param x the horizontal position for painting the border.     * @param y the vertical position for painting the border.     * @param width the width of the available area for painting the border.     * @param height the height of the available area for painting the border.     *     * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel     */    public void paintBorder(Component c, Graphics  g,                            int x, int y, int width, int height)    {      /* The author of this code tried various variants for setting       * the state of the enclosed JToggleButton, but it seems that       * the drawn border is always identical. Weird, because this       * means that the user does not see whether the JToggleButton       * is selected or not.       */      BasicGraphicsUtils.drawBezel(g, x, y, width, height,                                   /* pressed */ false,                                    /* default */ false,                                   shadow, darkShadow,                                   highlight, lightHighlight);    }    /**     * Measures the width of this border.     *     * @param c the component whose border is to be measured.     *     * @return an Insets object whose <code>left</code>,     *         <code>right</code>, <code>top</code> and     *         <code>bottom</code> fields indicate the width of the     *         border at the respective edge.     *     * @see #getBorderInsets(java.awt.Component, java.awt.Insets)      */    public Insets getBorderInsets(Component c)    {      /* There is no obvious reason for overriding this method, but we       * try to have exactly the same API as the Sun reference       * implementation.       */      return getBorderInsets(c, null);    }        /**     * Measures the width of this border, storing the results into a     * pre-existing Insets object.     *     * @param insets an Insets object for holding the result values.     *        After invoking this method, the <code>left</code>,     *        <code>right</code>, <code>top</code> and     *        <code>bottom</code> fields indicate the width of the     *        border at the respective edge.     *     * @return the same object that was passed for <code>insets</code>.     *     * @see #getBorderInsets()     */    public Insets getBorderInsets(Component c, Insets insets)    {      /* The exact amount has been determined using a test program       * that was run on the Apple/Sun JDK 1.3.1 on MacOS X, and the       * Sun JDK 1.4.1_01 on GNU/Linux for x86. Both gave [2,2,2,2].       */      if (insets == null)        return new Insets(2, 2, 2, 2);      insets.left = insets.right = insets.top = insets.bottom = 2;      return insets;    }  }}

⌨️ 快捷键说明

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