metaltabbedpaneui.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,119 行 · 第 1/3 页

JAVA
1,119
字号
      {        g.setColor(darkShadow);      }    // Slant.    g.drawLine(1, 5, 6, 0);    // Top.    g.drawLine(6, 0, right, 0);    // Bottom.    int lastIndex = lastTabInRun(tabCount, currentRun);    if (tabIndex == lastIndex)      {        g.drawLine(0, bottom, right, bottom);      }    // Left.    if (isOcean)      {        if (tabPane.getSelectedIndex() == tabIndex - 1)          {            g.drawLine(0, 5, 0, bottom);            g.setColor(oceanSelectedBorder);            g.drawLine(0, 0, 0, 5);          }        else if (isSelected)          {            g.drawLine(0, 5, 0, bottom);            if (tabIndex != 0)              {                g.setColor(darkShadow);                g.drawLine(0, 0, 0, 5);              }          }        else if (tabIndex != firstIndex)          {            g.drawLine(0, 0, 0, bottom);          }        else          {            g.drawLine(0, 6, 0, bottom);          }      }    else      {        if (tabIndex != firstIndex)          {            g.drawLine(0, 0, 0, bottom);          }        else          {            g.drawLine(0, 6, 0, bottom);          }      }    g.translate(-x, -y);  }    /**   * Paints the border for a tab assuming that the tab position is at the right   * ({@link #RIGHT}).   *    * @param tabIndex  the tab index.   * @param g  the graphics device.   * @param x  the x-coordinate for the tab's bounding rectangle.   * @param y  the y-coordinate for the tab's bounding rectangle.   * @param w  the width for the tab's bounding rectangle.   * @param h  the height for the tab's bounding rectangle.   * @param btm  ???   * @param rght  ???   * @param isSelected  indicates whether the tab is selected.   */  protected void paintRightTabBorder(int tabIndex, Graphics g, int x, int y,      int w, int h, int btm, int rght, boolean isSelected)  {    g.translate(x, y);    int bottom = h - 1;    int right = w - 1;    int tabCount = tabPane.getTabCount();    int currentRun = getRunForTab(tabCount, tabIndex);    int firstIndex = tabRuns[currentRun];    // Paint part of the above tab.    if (tabIndex != firstIndex)      {        Color c;        if (tabPane.getSelectedIndex() == tabIndex - 1)          c = UIManager.getColor("TabbedPane.tabAreaBackground");        else          c = UIManager.getColor("TabbedPane.unselectedBackground");        g.fillRect(right - 5, 0, 5, 3);        g.fillRect(right - 2, 3, 2, 2);      }    // Paint highlight.    g.setColor(isSelected ? selectHighlight : highlight);    // Slant.    g.drawLine(right - 6, 1, right - 1, 6);    // Top.    g.drawLine(0, 1, right - 6, 1);    // Left.    if (! isSelected)      {        g.drawLine(0, 1, 0, bottom);      }    // Paint border.    boolean isOcean = MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme;    Color oceanSelectedBorder =      UIManager.getColor("TabbedPane.borderHightlightColor");    if (isOcean && isSelected)      {        g.setColor(oceanSelectedBorder);      }    else      {        g.setColor(darkShadow);      }    // Bottom.    int lastIndex = lastTabInRun(tabCount, currentRun);    if (tabIndex == lastIndex)      {        g.drawLine(0, bottom, right, bottom);      }    // Slant.    if (isOcean && tabPane.getSelectedIndex() == tabIndex - 1)      {        g.setColor(oceanSelectedBorder);      }    g.drawLine(right - 6, 0, right, 6);    // Top.    g.drawLine(0, 0, right - 6, 0);    // Right.    if (isOcean && isSelected)      {        g.drawLine(right, 6, right, bottom);        if (tabIndex != firstIndex)          {            g.setColor(darkShadow);            g.drawLine(right, 0, right, 5);          }      }    else if (isOcean && tabPane.getSelectedIndex() == tabIndex - 1)      {        g.setColor(oceanSelectedBorder);        g.drawLine(right, 0, right, 6);        g.setColor(darkShadow);        g.drawLine(right, 6, right, bottom);      }    else if (tabIndex != firstIndex)      {        g.drawLine(right, 0, right, bottom);      }    else      {        g.drawLine(right, 6, right, bottom);      }    g.translate(-x, -y);  }    /**   * Paints the border for a tab assuming that the tab position is at the bottom   * ({@link #BOTTOM}).   *    * @param tabIndex  the tab index.   * @param g  the graphics device.   * @param x  the x-coordinate for the tab's bounding rectangle.   * @param y  the y-coordinate for the tab's bounding rectangle.   * @param w  the width for the tab's bounding rectangle.   * @param h  the height for the tab's bounding rectangle.   * @param btm  ???   * @param rght  ???   * @param isSelected  indicates whether the tab is selected.   */  protected void paintBottomTabBorder(int tabIndex, Graphics g, int x, int y,      int w, int h, int btm, int rght, boolean isSelected)  {    int bottom = h - 1;    int right = w - 1;    int tabCount = tabPane.getTabCount();    int currentRun = getRunForTab(tabCount, tabIndex);    // Paint gap if necessary.    if (shouldFillGap(currentRun, tabIndex, x, y))      {        g.translate(x, y);        g.setColor(getColorForGap(currentRun, x, y));        g.fillRect(1, bottom - 4, 3, 5);        g.fillRect(4, bottom - 1, 2, 2);        g.translate(-x, -y);      }    g.translate(x, y);    // Paint border.    boolean isOcean = MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme;    Color oceanSelectedBorder =      UIManager.getColor("TabbedPane.borderHightlightColor");    if (isOcean && isSelected)      {        g.setColor(oceanSelectedBorder);      }    else      {        g.setColor(darkShadow);      }    // Slant.    g.drawLine(1, bottom - 5, 6, bottom);    // Bottom.    g.drawLine(6, bottom, right, bottom);    // Right.    int lastIndex = lastTabInRun(tabCount, currentRun);    if (tabIndex == lastIndex)      {        g.drawLine(right, 0, right, bottom);      }    // Left.    if (isOcean && isSelected)      {        g.drawLine(0, 0, 0, bottom - 5);        if ((currentRun == 0 && tabIndex != 0)            || (currentRun > 0 && tabIndex != tabRuns[currentRun - 1]))          {            g.setColor(darkShadow);            g.drawLine(0, bottom - 5, 0, bottom);          }      }    else      {        if (isOcean && tabIndex == tabPane.getSelectedIndex()+ 1)          {            g.setColor(oceanSelectedBorder);          }        if (tabIndex != tabRuns[runCount- 1])          {            g.drawLine(0, 0, 0, bottom);          }        else          {            g.drawLine(0, 0, 0, bottom - 6);          }      }    // Paint highlight.    g.setColor(isSelected ? selectHighlight : highlight);    // Slant.    g.drawLine(1, bottom - 6, 6, bottom - 1);    // Left.    g.drawLine(1, 0, 1, bottom - 6);    int firstIndex = tabRuns[currentRun];    if (tabIndex == firstIndex && tabIndex != tabRuns[runCount - 1])      {        if (tabPane.getSelectedIndex() == tabRuns[currentRun + 1])          {            g.setColor(selectHighlight);          }        else          {            g.setColor(highlight);          }        g.drawLine(1, bottom - 4, 1, bottom);      }    g.translate(-x, -y);  }  /**   * Paints the background for a tab.   *    * @param g  the graphics device.   * @param tabPlacement  the tab placement ({@link #TOP}, {@link #LEFT},    *        {@link #BOTTOM} or {@link #RIGHT}).   * @param tabIndex  the index of the tab to draw the border for.   * @param x  the x-coordinate for the tab's bounding rectangle.   * @param y  the y-coordinate for the tab's bounding rectangle.   * @param w  the width for the tab's bounding rectangle.   * @param h  the height for the tab's bounding rectangle.   * @param isSelected  indicates whether or not the tab is selected.   */  protected void paintTabBackground(Graphics g, int tabPlacement,      int tabIndex, int x, int y, int w, int h, boolean isSelected)  {    if (isSelected)      g.setColor(selectColor);    else      g.setColor(tabPane.getBackgroundAt(tabIndex));    switch (tabPlacement)    {      case LEFT:        g.fillRect(x + 5, y + 1, w - 5, h - 1);        g.fillRect(x + 2, y + 4, 3, h - 4);        break;      case BOTTOM:        g.fillRect(x + 2, y, w - 2, h - 3);        g.fillRect(x + 5, y + h - 4, w - 5, 3);        break;      case RIGHT:        g.fillRect(x, y + 1, w - 4, h - 1);        g.fillRect(x + w - 4, y + 5, 3, h - 5);        break;      case TOP:      default:        g.fillRect(x + 4, y + 2, w - 4, h - 2);        g.fillRect(x + 2, y + 5, 2, h - 5);    }  }    /**   * Returns <code>true</code> if the tabs in the specified run should be    * padded to make the run fill the width/height of the {@link JTabbedPane}.   *    * @param tabPlacement  the tab placement for the {@link JTabbedPane} (one of   *        {@link #TOP}, {@link #BOTTOM}, {@link #LEFT} and {@link #RIGHT}).   * @param run  the run index.   *    * @return A boolean.   */  protected boolean shouldPadTabRun(int tabPlacement, int run)  {    // as far as I can tell, all runs should be padded except the last run    // (which is drawn at the very top for tabPlacement == TOP)    return run < this.runCount - 1;  }  /**   * Installs the defaults for this UI. This method calls super.installDefaults   * and then loads the Metal specific defaults for TabbedPane.   */  protected void installDefaults()  {    super.installDefaults();    selectColor = UIManager.getColor("TabbedPane.selected");    selectHighlight = UIManager.getColor("TabbedPane.selectHighlight");    tabAreaBackground = UIManager.getColor("TabbedPane.tabAreaBackground");    minTabWidth = 0;  }    /**   * Returns the color for the gap.   *    * @param currentRun - The current run to return the color for   * @param x - The x position of the current run   * @param y - The y position of the current run   *    * @return the color for the gap in the current run.   */  protected Color getColorForGap(int currentRun, int x, int y)  {    int index = tabForCoordinate(tabPane, x, y);    int selected = tabPane.getSelectedIndex();    if (selected == index)      return selectColor;    return tabAreaBackground;  }    /**   * Returns true if the gap should be filled in.   *    * @param currentRun - The current run   * @param tabIndex - The current tab   * @param x - The x position of the tab   * @param y - The y position of the tab   *    * @return true if the gap at the current run should be filled    */  protected boolean shouldFillGap(int currentRun, int tabIndex, int x, int y)  {    // As far as I can tell, the gap is never filled in.    return false;  }

⌨️ 快捷键说明

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