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

📄 compieretabbedpaneui.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		int right = w - 1;

		// ** Paint Highlight **
		g.setColor( isSelected ? selectHighlight : highlight );
		// Paint slant
		g.drawLine( 1, 6, 6, 1 );
		// Paint top
		g.drawLine( 6, 1, right, 1 );
		// Paint left
		g.drawLine( 1, 6, 1, bottom );
		//  Paint right
		if (!isSelected)
			g.drawLine(right-1, 0, right-1, bottom );

		// ** Paint Border **
		g.setColor( darkShadow );
		// Paint slant
		g.drawLine( 1, 5, 6, 0 );
		// Paint top
		g.drawLine( 6, 0, right, 0 );
		// Paint left
		g.drawLine( 0, 6, 0, bottom );
		// Paint bottom
		g.drawLine( 0, bottom, right, bottom );
		//  Paint right
		if (!isSelected)
			g.drawLine(right, 0, right, bottom );
		//
		g.translate( -x, -y );
	}   //  paintLeftTabBorder


	/**
	 *  Paint Border of Right Tab.
	 *  Does not fill triangle
	 *
	 *  @param tabIndex index
	 *  @param g graphics
	 *  @param x x
	 *  @param y y
	 *  @param w width
	 *  @param h height
	 *  @param btm bottom
	 *  @param rght right
	 *  @param isSelected selected
	 */
	protected void paintRightTabBorder (int tabIndex, Graphics g,
		int x, int y, int w, int h, int btm, int rght, boolean isSelected)
	{
		int tabCount = tabPane.getTabCount();
		int currentRun = getRunForTab( tabCount, tabIndex );
		int lastIndex = lastTabInRun( tabCount, currentRun );
		int firstIndex = tabRuns[ currentRun ];

		g.translate( x, y );

		int bottom = h - 1;
		int right = w - 1;

		// ** Paint Highlight **
		g.setColor( isSelected ? selectHighlight : highlight );
		// Paint slant
		g.drawLine (right-6, 1, right-1, 6 );
		// Paint top
		g.drawLine (0, 1, right - 6, 1 );
		// Paint right
		g.drawLine (right-1, 6, right-1, bottom-1);
		// Paint left
		if (!isSelected)
			g.drawLine (0, 1, 0, bottom-1);

		// ** Paint Border **
		g.setColor( darkShadow );
		// Paint slant
		g.drawLine (right - 6, 0, right, 6 );
		// Paint top
		g.drawLine (0, 0, right - 6, 0 );
		// Paint right
		g.drawLine (right, 6, right, bottom );
		// Paint bottom
		g.drawLine( 0, bottom, right, bottom );

		g.translate( -x, -y );
	}   //  paintRightTabBorder


	/*************************************************************************/

	/**
	 *  Calculate Tab Width.
	 *  We may have to overwrite to adjust width for TabHirarchyLevel
	 *  @param tabPlacement tab placement
	 *  @param tabIndex tab index
	 *  @param metrics metcics
	 *  @return tab width
	 */
	protected int calculateTabWidth (int tabPlacement, int tabIndex, FontMetrics metrics)
	{
		boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM);
		//  HTML
		if (getTextViewForTab(tabIndex) != null)
			calculate = false;
		//  No spaces in title
		String title = tabPane.getTitleAt(tabIndex);
		int pos = title.indexOf(" ");
		if (calculate && pos == -1)
			calculate = false;
		if (!calculate)
			return super.calculateTabWidth (tabPlacement, tabIndex, metrics);
		//
		Icon icon = getIconForTab(tabIndex);
		Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
		int width = tabInsets.left + tabInsets.right + 3;

		if (icon != null)
			width += icon.getIconWidth() + textIconGap;

		String firstLine = title.substring(0, pos);
		String secondLine = title.substring(pos+1);
		width += Math.max(SwingUtilities.computeStringWidth (metrics, firstLine),
			SwingUtilities.computeStringWidth (metrics, secondLine));
		return width;
	}   //  calculateTabWidth

	/**
	 * Calculate TabHeight
	 * @param tabPlacement tab placement
	 * @param tabIndex tab index
	 * @param fontHeight font height
	 * @return tab height
	 */
	protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight)
	{
		boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM);
		//  HTML
		if (getTextViewForTab(tabIndex) != null)
			calculate = false;
		//  No spaces in title
		String title = tabPane.getTitleAt(tabIndex);
		int pos = title.indexOf(" ");
		if (calculate && pos == -1)
			calculate = false;
		if (!calculate)
			return super.calculateTabHeight (tabPlacement, tabIndex, fontHeight);
		//
		int height = fontHeight * 2;
		Icon icon = getIconForTab(tabIndex);
		Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
		if (icon != null)
			height = Math.max(height, icon.getIconHeight());
		height += tabInsets.top + tabInsets.bottom + 2;
		return height;
	}

	/**
	 *  Layout Label
	 *  @param tabPlacement tab placement
	 *  @param metrics fint metrics
	 *  @param tabIndex tab index
	 *  @param title title
	 *  @param icon icon
	 *  @param tabRect tab bounds
	 *  @param iconRect icon bounds
	 *  @param textRect text bounds
	 *  @param isSelected selected
	 */
	protected void layoutLabel(int tabPlacement,
		FontMetrics metrics, int tabIndex, String title, Icon icon,
		Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected)
	{
		boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM);
		//  HTML
		if (getTextViewForTab(tabIndex) != null)
			calculate = false;
		if (!calculate)
		{
			super.layoutLabel (tabPlacement, metrics, tabIndex, title, icon,
				tabRect, iconRect, textRect, isSelected);
		//	System.out.println("1.tabRect=" + tabRect + " - textRect=" + textRect + " - " + title);
			return;
		}
		//
		textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
		SwingUtilities.layoutCompoundLabel((JComponent) tabPane,
			metrics, title, icon,
			SwingUtilities.TOP,     //  vert
			SwingUtilities.LEFT,    //  horiz
			SwingUtilities.CENTER,      //  vert Text
			SwingUtilities.TRAILING,    //  horiz Text
			tabRect,
			iconRect,
			textRect,
			textIconGap);
		tabPane.putClientProperty("html", null);
		int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
		int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
		//  positioned top left - add gap
		Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
		xNudge += tabInsets.left;
		yNudge += tabInsets.top + 1;
		iconRect.x += xNudge;
		iconRect.y += yNudge;
		textRect.x += xNudge;
		textRect.y += yNudge;
	//	System.out.println("2.tabRect=" + tabRect + " - textRect=" + textRect + " - " + title);
	}

	/**
	 * Paint Tab
	 * @param g graphics
	 * @param tabPlacement tab placement
	 * @param font font
	 * @param metrics font metrics
	 * @param tabIndex tab index
	 * @param title title
	 * @param textRect text bounds
	 * @param isSelected selected
	 */
	protected void paintText (Graphics g, int tabPlacement,
		Font font, FontMetrics metrics, int tabIndex,
		String title, Rectangle textRect, boolean isSelected)
	{
		boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM);
		//  HTML
		if (getTextViewForTab(tabIndex) != null)
			calculate = false;
		if (!calculate)
		{
			super.paintText (g, tabPlacement, font, metrics, tabIndex,
				title, textRect, isSelected);
			return;
		}

	//	System.out.println("3.textRect " + textRect + " - " + title);
		String firstLine = title;
		String secondLine = null;
		int pos = title.indexOf(' ');
		if (pos != -1)
		{
			firstLine = title.substring(0, pos);
			secondLine = title.substring(pos+1);
		}

		g.setFont(font);
		int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
		if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex))
		{
			Color c = tabPane.getForegroundAt(tabIndex);
			if (!isSelected)
			{
				if (c.equals(Color.black))
					c = Color.darkGray;
				else
					c = c.brighter();
			}
			g.setColor(c);
			//  first line
			BasicGraphicsUtils.drawStringUnderlineCharAt
				(g, firstLine, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
			//  secondLine
			if (secondLine != null)
				BasicGraphicsUtils.drawStringUnderlineCharAt
					(g, secondLine, mnemIndex-firstLine.length(),
					textRect.x, textRect.y + metrics.getAscent() + metrics.getHeight());
		}
		else
		{   // tab disabled
			g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
			BasicGraphicsUtils.drawStringUnderlineCharAt
				(g, firstLine, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
			//  secondLine
			if (secondLine != null)
				BasicGraphicsUtils.drawStringUnderlineCharAt
					(g, secondLine, mnemIndex-firstLine.length(),
					textRect.x, textRect.y + metrics.getAscent() + metrics.getHeight());
			//
			g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
			BasicGraphicsUtils.drawStringUnderlineCharAt
				(g, firstLine, mnemIndex, textRect.x -1, textRect.y + metrics.getAscent() -1);
			//  secondLine
			if (secondLine != null)
				BasicGraphicsUtils.drawStringUnderlineCharAt
					(g, secondLine, mnemIndex-firstLine.length(),
					textRect.x -1, textRect.y + metrics.getAscent() + metrics.getHeight() -1);
		}
	}   //  paintText

	/*************************************************************************/

	/**
	 *  Create Layout Manager to size & position tabs
	 *  @return Layout Manager
	 */
	protected LayoutManager createLayoutManager()
	{
		return new TabbedPaneLayout();
	}   //  createLayoutManager

	/**
	 *  Layout Manager to overwrite TabRect size
	 */
	public class TabbedPaneLayout extends MetalTabbedPaneUI.TabbedPaneLayout
	{
		/**
		 *  Calculate Tab Rectangle Size
		 *  @param tabPlacement tab placement
		 *  @param tabCount no of tabs
		 */
		protected void calculateTabRects(int tabPlacement, int tabCount)
		{
			super.calculateTabRects(tabPlacement, tabCount);
			if (tabPlacement == TOP || tabPlacement == BOTTOM)
				return;
		//	System.out.println("calculateTabRects " + tabCount);
			int tabHeight = calculateMaxTabHeight(tabPlacement);
			for (int i = 0; i < rects.length; i++)
			{
				int level = 0;
				Component comp = tabPane.getComponentAt(i);
				if (comp instanceof JComponent)
				{
					JComponent jc = (JComponent)comp;
					try
					{
						Integer ll = (Integer)jc.getClientProperty(CompierePLAF.TABLEVEL);
						if (ll != null)
							level = ll.intValue();
					}
					catch (Exception e)
					{
						System.err.println("CompiereTabbedPaneUI - ClientProperty: " + e.getMessage());
					}
				}
				if (level != 0)
				{
					if (tabPlacement == LEFT)
						rects[i].x += level * 5;
					rects[i].width -= level * 5;
				}
				//  Height
				rects[i].height = tabHeight;
				if (i > 0)
					rects[i].y = rects[i-1].y + tabHeight; //   rects[i-1].height;
			}   //   for all rects
		}   //  calculate TabRects

	}   //  TabbedPaneLayout

}   //  CompiereTabbedPaneUI

⌨️ 快捷键说明

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