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

📄 shapedgradienttheme.java

📁 修正了jdk1.6中对托盘事件产生异常的bug.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (C) 2004 NNL Technology AB
 * Visit www.infonode.net for information about InfoNode(R) 
 * products and how to contact NNL Technology AB.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
 * MA 02111-1307, USA.
 */

// $Id: ShapedGradientTheme.java,v 1.14 2005/12/04 13:46:05 jesper Exp $
package net.infonode.tabbedpanel.theme;

import net.infonode.gui.HighlightPainter;
import net.infonode.gui.InsetsUtil;
import net.infonode.gui.colorprovider.*;
import net.infonode.gui.componentpainter.GradientComponentPainter;
import net.infonode.tabbedpanel.Tab;
import net.infonode.tabbedpanel.TabbedPanelProperties;
import net.infonode.tabbedpanel.TabbedUtils;
import net.infonode.tabbedpanel.border.OpenContentBorder;
import net.infonode.tabbedpanel.internal.SlopedTabLineBorder;
import net.infonode.tabbedpanel.titledtab.TitledTabBorderSizePolicy;
import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
import net.infonode.tabbedpanel.titledtab.TitledTabStateProperties;

import javax.swing.border.Border;
import java.awt.*;

/**
 * A theme with tabs with rounded edges, gradient backgrounds and support for
 * slopes on left/right side of tab.
 *
 * @author $Author: jesper $
 * @version $Revision: 1.14 $
 * @since ITP 1.2.0
 */
public class ShapedGradientTheme extends TabbedPanelTitledTabTheme {
  private static final int CORNER_INSET = 3;

  private ColorProvider highlightColor;
  private ColorProvider lineColor;
  private ColorProvider controlColor;
  private ColorProvider darkControlColor;
  private ColorProvider alternateHighlight;
  private int leftSlopeHeight;
  private int rightSlopeHeight;

  private static class TabBorder extends SlopedTabLineBorder {
    private boolean bottomLeftRounded;
    private boolean isNormal;
    private boolean hasLeftSlope;
    private int raised;
    private int cornerInset;

    TabBorder(ColorProvider lineColor, ColorProvider highlightColor,
              float leftSlope, float rightSlope, int leftHeight, int rightHeight,
              boolean bottomLeftRounded, boolean topLeftRounded, boolean topRightRounded,
              boolean bottomRightRounded, boolean isNormal, boolean highlightBottomLeftRounded, int raised) {
      super(lineColor, highlightColor, false, leftSlope, rightSlope, leftHeight,
            rightHeight, isNormal ? false : bottomLeftRounded, topLeftRounded, topRightRounded, bottomRightRounded);

      this.bottomLeftRounded = bottomLeftRounded;
      this.isNormal = isNormal;
      this.raised = raised;
      hasLeftSlope = leftSlope > 0;

      cornerInset = highlightBottomLeftRounded ? CORNER_INSET : 0;
    }

    protected Polygon createPolygon(Component c, int width, int height) {
      Polygon p = super.createPolygon(c, width, height);
      if (isNormal) {
        int leftX = width / 2;
        boolean first = isFirst(c);
        for (int i = 0; i < p.npoints; i++) {
          if (p.xpoints[i] < leftX)
            p.xpoints[i] = p.xpoints[i] + raised + (first ? 0 : cornerInset);
          else
            p.xpoints[i] = p.xpoints[i] - raised - cornerInset;
        }
      }

      return p;
    }

    protected Insets getShapedBorderInsets(Component c) {
      Insets i = super.getShapedBorderInsets(c);

      Insets addInsets = new Insets(0, 0, 0, 1 + raised);
      //Insets addInsets = new Insets(0, raised, 0, raised);
      if (isNormal && !isFirst(c))
        addInsets.left = addInsets.left + cornerInset;
      if (!isNormal)
        addInsets.right = addInsets.right - cornerInset;

      return InsetsUtil.add(i, addInsets);
    }

    private boolean isFirst(Component c) {
      if (!hasLeftSlope) {
        Tab tab = TabbedUtils.getParentTab(c);
        if (tab != null && tab.getTabbedPanel() != null) {
          return tab.getTabbedPanel().getTabAt(0) == tab;
        }
      }

      return false;
    }

    protected boolean isBottomLeftRounded(Component c) {
      return isFirst(c) ? false : bottomLeftRounded;
    }
  }

  private TabbedPanelProperties tabbedPanelProperties = new TabbedPanelProperties();
  private TitledTabProperties titledTabProperties = new TitledTabProperties();

  /**
   * Creates a default theme with sloped border on the right side of the tab
   * and with colors based on the active look and feel
   */
  public ShapedGradientTheme() {
    this(0f, 0.5f);
  }

  /**
   * Creates a theme with the given slopes on the left and right side of the tab
   * and with colors based on the active look and feel
   *
   * @param leftSlope  leaning of left slope defined as left slope width divided by left slope height
   * @param rightSlope leaning of right slope defined as right slope width divided by right slope height
   */
  public ShapedGradientTheme(float leftSlope, float rightSlope) {
    this(leftSlope,
         rightSlope,
         UIManagerColorProvider.TABBED_PANE_DARK_SHADOW,
         UIManagerColorProvider.TABBED_PANE_HIGHLIGHT);
  }

  /**
   * Creates a theme with the given slopes on the left and right side of the tab
   * and with the given colors
   *
   * @param leftSlope      leaning of left slope defined as left slope width divided
   *                       by left slope height
   * @param rightSlope     leaning of right slope defined as right slope width divided
   *                       by right slope height
   * @param lineColor      color provider for the lines
   * @param highlightColor color provider for the highlighting, null for no highlighting
   */
  public ShapedGradientTheme(float leftSlope, float rightSlope, ColorProvider lineColor, ColorProvider highlightColor) {
    this(leftSlope, rightSlope, 25, lineColor, highlightColor);
  }

  /**
   * Creates a theme with the given slopes on the left and right side of
   * the tab and with the given colors
   *
   * @param leftSlope      leaning of left slope defined as left slope width divided
   *                       by left slope height
   * @param rightSlope     leaning of right slope defined as right slope width divided
   *                       by right slope height
   * @param slopeHeight    slope height in pixels, used when estimating slope width
   * @param lineColor      color provider for the lines
   * @param highlightColor color provider for the highlighting, null for no highlighting
   */
  public ShapedGradientTheme(float leftSlope,
                             float rightSlope,
                             int slopeHeight,
                             ColorProvider lineColor,
                             ColorProvider highlightColor) {
    this.leftSlopeHeight = slopeHeight;
    this.rightSlopeHeight = slopeHeight;
    this.highlightColor = highlightColor;
    this.lineColor = lineColor;
    this.controlColor = UIManagerColorProvider.CONTROL_COLOR;
    darkControlColor = UIManagerColorProvider.TABBED_PANE_BACKGROUND;
    alternateHighlight = highlightColor != null ?
                         new ColorBlender(highlightColor, controlColor, 0.3f) :
                         (ColorProvider) new ColorMultiplier(controlColor, 1.2);

    GradientComponentPainter blendedComponentPainter = new GradientComponentPainter(alternateHighlight,
                                                                                    alternateHighlight,
                                                                                    controlColor,
                                                                                    controlColor);

    int leftSlopeWidth = (int) (leftSlope * leftSlopeHeight);

⌨️ 快捷键说明

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