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

📄 basicborders.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @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)    {      return getBorderInsets(c, null);    }    /**     * Measures the width of this border, storing the results into a     * pre-existing Insets object.     *     * @param c the component whose border is to be measured.     *        If <code>c</code> is an instance of {@link     *        javax.swing.text.JTextComponent}, its margin is     *        added to the border size.     *     * @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)    {      if (insets == null)        insets = new Insets(2, 2, 2, 2);      else        insets.top = insets.left = insets.bottom = insets.right = 2;      if (c instanceof JTextComponent)      {        Insets margin = ((JTextComponent) c).getMargin();        insets.top += margin.top;        insets.left += margin.left;        insets.bottom += margin.bottom;        insets.right += margin.right;      }      return insets;    }  }      /**   * An invisible, but spacing border whose margin is determined   * by calling the <code>getMargin()</code> method of the enclosed   * component.  If the enclosed component has no such method,   * this border will not occupy any space.   *   * <p><img src="doc-files/BasicBorders.MarginBorder-1.png" width="325"   * height="200" alt="[An illustration that shows how MarginBorder   * determines its borders]" />   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class MarginBorder    extends AbstractBorder    implements Serializable, UIResource  {    /**     * Determined using the <code>serialver</code> tool     * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.     */    static final long serialVersionUID = -3035848353448896090L;            /**     * Constructs a new MarginBorder.     */    public MarginBorder()    {    }            /**     * 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)    {      return getBorderInsets(c, new Insets(0, 0, 0, 0));    }            /**     * Determines the insets of this border by calling the     * <code>getMargin()</code> method of the enclosed component.  The     * resulting margin will be stored into the the <code>left</code>,     * <code>right</code>, <code>top</code> and <code>bottom</code>     * fields of the passed <code>insets</code> parameter.     *     * <p>Unfortunately, <code>getMargin()</code> is not a method of     * {@link javax.swing.JComponent} or some other common superclass     * of things with margins. While reflection could be used to     * determine the existence of this method, this would be slow on     * many virtual machines. Therefore, the current implementation     * knows about {@link javax.swing.AbstractButton#getMargin()},     * {@link javax.swing.JPopupMenu#getMargin()}, {@link     * javax.swing.JToolBar#getMargin()}, and {@link     * javax.swing.text.JTextComponent}. If <code>c</code> is an     * instance of a known class, the respective     * <code>getMargin()</code> method is called to determine the     * correct margin. Otherwise, a zero-width margin is returned.     *     * @param c the component whose border is to be measured.     *     * @return the same object that was passed for <code>insets</code>,     *         but with changed fields.     */    public Insets getBorderInsets(Component c, Insets insets)    {      Insets margin = null;      /* This is terrible object-oriented design. See the above Javadoc       * for an excuse.       */      if (c instanceof AbstractButton)        margin = ((AbstractButton) c).getMargin();      else if (c instanceof JPopupMenu)        margin = ((JPopupMenu) c).getMargin();      else if (c instanceof JToolBar)        margin = ((JToolBar) c).getMargin();      else if (c instanceof JTextComponent)        margin = ((JTextComponent) c).getMargin();            if (margin == null)        insets.top = insets.left = insets.bottom = insets.right = 0;      else      {        insets.top = margin.top;        insets.left = margin.left;        insets.bottom = margin.bottom;        insets.right = margin.right;      }      return insets;    }  }    /**   * A border for drawing a separator line below JMenuBar.   *   * <p><img src="doc-files/BasicBorders.MenuBarBorder-1.png" width="500"   * height="140" alt="[A screen shot of a JMenuBar with this border]" />   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class MenuBarBorder    extends AbstractBorder    implements UIResource  {    /**     * Determined using the <code>serialver</code> tool     * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.     */    static final long serialVersionUID = -6909056571935227506L;            /**     * The shadow color, which is used for the upper line of the     * two-pixel thick bottom edge.     */    private Color shadow;    /**     * The highlight color, which is used for the lower line of the     * two-pixel thick bottom edge.     */    private Color highlight;    /**     * Constructs a new MenuBarBorder for drawing a JMenuBar in     * the Basic look and feel.     *     * <p><img src="doc-files/BasicBorders.MenuBarBorder-1.png" width="500"     * height="140" alt="[A screen shot of a JMenuBar with this     * border]" />     *     * @param shadow the shadow color, which is used for the upper     *        line of the two-pixel thick bottom edge.     *     * @param highlight the shadow color, which is used for the lower     *        line of the two-pixel thick bottom edge.     */    public MenuBarBorder(Color shadow, Color highlight)    {      /* 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.gray;      this.highlight = (highlight != null) ? highlight : Color.white;    }    /**     * Paints the MenuBarBorder around a given component.     *     * @param c the component whose border is to be painted, usually     *        an instance of {@link javax.swing.JMenuBar}.     *     * @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;      /* To understand this code, it might be helpful to look at the       * image "BasicBorders.MenuBarBorder-1.png" that is included       * with the JavaDoc. It is located in the "doc-files"       * subdirectory.       */      oldColor = g.getColor();      y = y + height - 2;      try      {        g.setColor(shadow);        g.drawLine(x, y, x + width - 2, y);        g.drawLine(x, y + 1, x, y + 1);        g.drawLine(x + width - 2, y + 1, x + width - 2, y + 1);        g.setColor(highlight);        g.drawLine(x + 1, y + 1, x + width - 3, y + 1);        g.drawLine(x + width - 1, y, x + width - 1, y + 1);              }      finally      {        g.setColor(oldColor);      }    }    /**     * 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 [0,0,2,0],       * which was expected from looking at the screen shot.       */      if (insets == null)        return new Insets(0, 0, 2, 0);      insets.left = insets.right = insets.top = 0;      insets.bottom = 2;      return insets;    }  }  /**   * A border for drawing radio buttons in the Basic look and feel.   *   * <p><img src="doc-files/BasicBorders.RadioButtonBorder-1.png" width="300"   * height="135" alt="[A screen shot of this border]" />   *   * <p>Note about the screen shot: Normally, the   * <code>borderPainted</code> property is <code>false</code> for   * JRadioButtons. For this screen shot, it has been set to   * <code>true</code> so the borders get drawn. Also, a   * concretization of the Basic look and would typically provide   * icons for the various states of radio buttons.   *   * <p>Note that the focus rectangle is invisible If the radio button   * is currently selected. While it might be debatable whether this   * makes a lot of sense, this behavior can be observed in the Sun   * reference implementation (in JDK 1.3.1 and 1.4.1). The Classpath   * implementation tries to exactly replicate the JDK appearance.   *   * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel   *   * @author Sascha Brawer (brawer@dandelis.ch)   */  public static class RadioButtonBorder    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 = 1596945751743747369L;    /**     * Constructs a new border for drawing a JRadioButton 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 RadioButtonBorder(Color shadow, Color darkShadow,                             Color highlight, Color lightHighlight)    {      /* The superclass ButtonBorder substitutes null arguments       * with fallback colors.       */      super(shadow, darkShadow, highlight, lightHighlight);    }

⌨️ 快捷键说明

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