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

📄 basicborders.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Paints the RadioButtonBorder 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)    {      AbstractButton button = null;      ButtonModel bmodel = null;      boolean lowered = false;      boolean focused = false;      if (c instanceof AbstractButton)      {        button = (AbstractButton) c;        bmodel = button.getModel();      }      if (bmodel != null)      {        lowered = button.isSelected()          || (/* mouse inside */ bmodel.isArmed() && bmodel.isPressed());        focused = button.hasFocus() && button.isFocusPainted();              }      if (lowered)        BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,                                            shadow, darkShadow,                                            highlight, lightHighlight);      else        BasicGraphicsUtils.drawBezel(g, x, y, width, height,                                     /* isPressed */ false,                                     /* isPefault */ focused,                                     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;    }  }  /**   * A one-pixel thick border for rollover buttons, for example in   * tool bars.   *   * @since 1.4   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class RolloverButtonBorder    extends ButtonBorder  {    /**     * Determined using the <code>serialver</code> tool     * of Sun JDK 1.4.1_01 on GNU/Linux 2.4.20 for x86.     */    static final long serialVersionUID = 1976364864896996846L;    /**     * Constructs a new border for drawing a roll-over button     * 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 RolloverButtonBorder(Color shadow, Color darkShadow,                                Color highlight, Color lightHighlight)    {      super(shadow, darkShadow, highlight, lightHighlight);    }    /**     * Paints the border around a rollover button.  If <code>c</code>     * is not an {@link javax.swing.AbstractButton} whose model     * returns <code>true</code> for {@link     * javax.swing.ButtonModel#isRollver}, nothing gets painted at     * all.     *     * @param c the button 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.     */    public void paintBorder(Component c, Graphics  g,                            int x, int y, int width, int height)    {      ButtonModel bmodel = null;      boolean drawPressed;      Color oldColor = g.getColor();      int x2, y2;      if (c instanceof AbstractButton)        bmodel = ((AbstractButton) c).getModel();      /* Draw nothing if c is not a rollover button. */      if ((bmodel == null) || !bmodel.isRollover())        return;      /* Draw nothing if the mouse is pressed, but outside the button. */      if (bmodel.isPressed() && !bmodel.isArmed())        return;      drawPressed = bmodel.isSelected() || bmodel.isPressed();      x2 = x + width - 1;      y2 = y + height - 1;      try      {        g.setColor(drawPressed ? shadow : lightHighlight);        g.drawLine(x, y, x2 - 1, y);     // top edge        g.drawLine(x, y + 1, x, y2 - 1); // left edge        g.setColor(drawPressed ? lightHighlight : shadow);        g.drawLine(x, y2, x2, y2);       // bottom edge        g.drawLine(x2, y, x2, y2 - 1);   // right edge      }      finally      {        g.setColor(oldColor);      }    }  }  /**   * A border for JSplitPanes in the Basic look and feel. The divider   * in the middle of the JSplitPane has its own border class, of which   * an instance can be obtained with {@link #getSplitPaneDividerBorder()}.   *   * <p><img src="doc-files/BasicBorders.SplitPaneBorder-1.png" width="520"   * height="200" alt="[A screen shot for JSplitPane.HORIZONTAL_SPLIT]" />   *   * <p><img src="doc-files/BasicBorders.SplitPaneBorder-2.png" width="520"   * height="200" alt="[A screen shot for JSplitPane.VERTICAL_SPLIT]" />   *   * <p>In contrast to the other borders of the Basic look and feel,   * this class is not serializable. While this might be unintended,   * GNU Classpath follows the specification in order to be fully   * compatible with the Sun reference implementation.   *   * <p>In the Sun JDK, the bottom edge of the divider also gets   * painted if the orientation of the enclosed JSplitPane is   * <code>JSplitPane.VERTICAL_SPLIT</code> (at least in versions   * 1.3.1 and 1.4.1).  GNU Classpath does not replicate this bug. A   * report has been filed with Sun (bug ID 4885629).   *   * <p>Note that the bottom left pixel of the border has a different   * color depending on the orientation of the enclosed JSplitPane.   * Although this is visually inconsistent, Classpath replicates the   * appearance of the Sun reference implementation. A bug report has   * been filed with Sun (review ID 188774).   *   * @see {@link #getSplitPaneBorder()}   * @see {@link #getSplitPaneDividerBorder()}   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class SplitPaneBorder    implements Border, UIResource  {    /**     * Indicates that the top edge shall be not be painted     * by {@link #paintRect(java.awt.Graphics, int, int, int, int, int)}.     */    private static final int SUPPRESS_TOP = 1;    /**     * Indicates that the left edge shall be not be painted     * by {@link #paintRect(java.awt.Graphics, int, int, int, int, int)}.     */    private static final int SUPPRESS_LEFT = 2;    /**     * Indicates that the bottom edge shall be not be painted     * by {@link #paintRect(java.awt.Graphics, int, int, int, int, int)}.     */    private static final int SUPPRESS_BOTTOM = 4;    /**     * Indicates that the right edge shall be not be painted     * by {@link #paintRect(java.awt.Graphics, int, int, int, int, int)}.     */    private static final int SUPPRESS_RIGHT = 8;    /**     * The color for drawing the bottom and right edges of the border.     */    protected Color highlight;    /**     * The color for drawing the top and left edges of the border.     */    protected Color shadow;    /**     * Constructs a new border for drawing a JSplitPane in the Basic     * look and feel.  The divider in the middle of the JSplitPane has     * its own border class, <code>SplitPaneDividerBorder</code>.     *     * @param shadow the shadow color.     * @param highlight the highlight color.     */    public SplitPaneBorder(Color highlight, Color shadow)    {      /* These colors usually come from the UIDefaults of the current       * look and feel. Use fallback values if the colors are not       * supplied.  The API specification is silent about what       * behavior is expected for null colors, so users should not       * rely on this fallback (which is why it is not documented in       * the above Javadoc).       */      this.shadow = (shadow != null) ? shadow : Color.black;      this.highlight = (highlight != null) ? highlight : Color.white;    }    /**     * Paints the border around a <code>JSplitPane</code>.     *     * <p><img src="doc-files/BasicBorders.SplitPaneBorder-1.png" width="520"     * height="200" alt="[A screen shot for JSplitPane.HORIZONTAL_SPLIT]" />     *     * <p><img src="doc-files/BasicBorders.SplitPaneBorder-2.png" width="520"     * height="200" alt="[A screen shot for JSplitPane.VERTICAL_SPLIT]" />     *     * @param c the <code>JSplitPane</code> 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.     */    public void paintBorder(Component c, Graphics  g,                            int x, int y, int width, int height)    {      JSplitPane splitPane;      Component content;      if (!(c instanceof JSplitPane))        return;      splitPane = (JSplitPane) c;      switch (splitPane.getOrientation())      {      case JSplitPane.HORIZONTAL_SPLIT:        if ((content = splitPane.getLeftComponent()) != null)          paintRect(g, SUPPRESS_RIGHT, true, x, y, content.getBounds());        if ((content = splitPane.getRightComponent()) != null)          paintRect(g, SUPPRESS_LEFT, true, x, y, content.getBounds());        break;      case JSplitPane.VERTICAL_SPLIT:        if ((content = splitPane.getTopComponent()) != null)          paintRect(g, SUPPRESS_BOTTOM, false, x, y, content.getBounds());        if ((content = splitPane.getBottomComponent()) != null)          paintRect(g, SUPPRESS_TOP, false, x, y, content.getBounds());        break;      }    }    /**     * Paints a border around a child of a <code>JSplitPane</code>,     * omitting some of the edges.     *     * @param g the graphics for painting.     *     * @param suppress a bit mask indicating the set of suppressed     *        edges, for example <code>SUPPRESS_TOP | SUPPRESS_RIGHT</code>.     *     * @param x the x coordinate of the SplitPaneBorder.     *     * @param y the y coordinate of the SplitPaneBorder.     *     * @param shadeBottomLeftPixel <code>true</code> to paint the     *        bottom left pixel in the shadow color,     *        <code>false</code> for the highlight color. The Basic     *        look and feel uses the highlight color for the bottom     *        left pixel of the border of a JSplitPane whose     *        orientation is VERTICAL_SPLIT, and the shadow color     *        otherwise. While this might be a strange distinction,     *        Classpath tries to look identical to the reference     *        implementation. A bug report has been filed with Sun;     *        its review ID is 188774. We currently replicate the     *        Sun behavior.     *     * @param rect the bounds of the child of JSplitPane whose     *        border is to be painted.     */    private void paintRect(Graphics g, int suppress,                           boolean shadeBottomLeftPixel,

⌨️ 快捷键说明

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