📄 compieretabbedpaneui.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.plaf;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.plaf.basic.*;
import javax.swing.text.*;
/**
* Same implementation detail as in CompierePanelUI.
* Additional handling of dwawing tabs.
* @see CompierePanelUI
*
* @author Jorg Janke
* @version $Id: CompiereTabbedPaneUI.java,v 1.12 2002/09/17 02:25:43 jjanke Exp $
*/
public class CompiereTabbedPaneUI extends MetalTabbedPaneUI
{
/**
* Static Create UI
* @param c Component
* @return Compiere TabbedPaneUI
*/
public static ComponentUI createUI(JComponent c)
{
return new CompiereTabbedPaneUI();
} // createUI
/**
* Install Defaults
*/
protected void installDefaults()
{
super.installDefaults();
tabPane.setOpaque(false);
} // installDefaults
/*************************************************************************/
/**
* Update -
* This method is invoked by <code>JComponent</code> when the specified
* component is being painted.
*
* By default this method will fill the specified component with
* its background color (if its <code>opaque</code> property is
* <code>true</code>) and then immediately call <code>paint</code>.
*
* @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted
*
* @see #paint
* @see javax.swing.JComponent#paintComponent
*/
public void update (Graphics g, JComponent c)
{
/**
System.out.println (c.getClass().getName() + " ** " + c.isOpaque());
Container container = c.getParent();
while (container != null)
{
System.out.println (" - " + container.getClass() + " ** " + container.isOpaque() );
container = container.getParent();
}
*/
// System.out.println("Tab: Bounds=" + c.getBounds() + " - " + c.getClass().getName());
if (c.isOpaque())
CompierePanelUI.updateIt (g, c); // tabAreaBackground
paint (g, c);
} // update
/**
* Paint it
* @param g graphics
* @param c component
*/
public void paint( Graphics g, JComponent c )
{
int tabPlacement = tabPane.getTabPlacement();
Insets insets = c.getInsets();
Dimension size = c.getSize();
if ( tabPane.isOpaque() )
{
g.setColor(c.getBackground());
/** @todo Printing of area behind Tabs */
switch (tabPlacement)
{
case LEFT:
g.fillRect( insets.left, insets.top,
calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ),
size.height - insets.bottom - insets.top );
break;
case BOTTOM:
int totalTabHeight = calculateTabAreaHeight( tabPlacement, runCount, maxTabHeight );
g.fillRect( insets.left, size.height - insets.bottom - totalTabHeight,
size.width - insets.left - insets.right,
totalTabHeight );
break;
case RIGHT:
int totalTabWidth = calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth );
g.fillRect( size.width - insets.right - totalTabWidth,
insets.top, totalTabWidth,
size.height - insets.top - insets.bottom );
break;
case TOP:
default:
g.fillRect( insets.left, insets.top,
size.width - insets.right - insets.left,
calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) );
paintHighlightBelowTab();
}
}
/**/
super.paint( g, c );
} // paint
/*************************************************************************/
/**
* Paint the actual Tab Background.
* Called from Basic.PaintTab (<- Basic.paintTabArea <- Basic.paint)
* <p>
* Based on MetalTabbedPaneUI.paintTabBackground:
* Differences:
* - Color based on primary Background of Tab
* - Selected Tab is painted
* <pre>
* selected not sel
* top ////////// ////////// (lighter)
* ++++++++++ (flat/darker)
*
* bottom ////////// (flat/lighter)
* ++++++++++ ++++++++++ (darker)
*
* sides ////////// (flat/ligher)
* ++++++++++ (flat/darker)
* </pre>
* @param g graphics
* @param tabPlacement tab placement
* @param tabIndex tab index
* @param x x
* @param y y
* @param w width
* @param h height
* @param isSelected selected
*/
protected void paintTabBackground (Graphics g, int tabPlacement,
int tabIndex, int x, int y, int w, int h, boolean isSelected)
{
Graphics2D g2D = (Graphics2D)g;
// Get Background color of Tab
Component comp = tabPane.getComponentAt(tabIndex);
// System.out.println("Tab " + tabIndex + " Comp=" + comp.getName() + " " + comp.getClass().getName() + " x=" + x + ", y=" + y + ", w=" +w + ", h=" + h);
g2D.setPaint(comp.getBackground());
CompiereColor bg = null;
if (comp instanceof JPanel)
{
JPanel jp = (JPanel)comp;
try
{
bg = (CompiereColor)jp.getClientProperty(CompierePLAF.BACKGROUND);
}
catch (Exception e)
{
System.err.println("CompiereTabbedPaneUI - ClientProperty: " + e.getMessage());
}
}
if (bg == null) // No Background
{
if (CompiereUtils.isLeftToRight(tabPane))
{
switch (tabPlacement)
{
case LEFT:
g2D.fillRect( x + 5, y + 1, w - 5, h - 1);
g2D.fillRect( x + 2, y + 4, 3, h - 4 );
break;
case BOTTOM:
g2D.fillRect( x + 2, y, w - 2, h - 4 );
g2D.fillRect( x + 5, y + (h - 1) - 3, w - 5, 3 );
break;
case RIGHT:
g2D.fillRect( x + 1, y + 1, w - 5, h - 1);
g2D.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 );
break;
case TOP:
default:
g2D.fillRect( x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 );
g2D.fillRect( x + 2, y + 5, 2, h - 5 );
}
}
else
{
switch (tabPlacement)
{
case LEFT:
g2D.fillRect( x + 5, y + 1, w - 5, h - 1);
g2D.fillRect( x + 2, y + 4, 3, h - 4 );
break;
case BOTTOM:
g2D.fillRect( x, y, w - 5, h - 1 );
g2D.fillRect( x + (w - 1) - 4, y, 4, h - 5);
g2D.fillRect( x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
g2D.fillRect( x + 1, y + 1, w - 5, h - 1);
g2D.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 );
break;
case TOP:
default:
g2D.fillRect( x, y + 2, (w - 1) - 3, (h - 1) - 1 );
g2D.fillRect( x + (w - 1) - 3, y + 4, 3, h - 4 );
}
}
}
else // we have a background
{
if (CompiereUtils.isLeftToRight(tabPane))
{
switch (tabPlacement)
{
case LEFT:
bg.paintRect (g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect (g2D, tabPane, x + 2, y + 4, 3, h - 4 );
break;
case BOTTOM:
bg.paintRect (g2D, tabPane, x + 2, y, w - 2, h - 4 );
bg.paintRect (g2D, tabPane, x + 5, y + (h - 1) - 3, w - 5, 3 );
break;
case RIGHT:
// bg.paintRect (g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
bg.paintRect (g2D, tabPane, x, y + 2, w - 4, h - 2); // changed
bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5 );
break;
case TOP:
default:
bg.paintRect (g2D, tabPane, x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 );
bg.paintRect (g2D, tabPane, x + 2, y + 5, 2, h - 5 );
}
}
else
{
switch (tabPlacement)
{
case LEFT:
bg.paintRect (g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect (g2D, tabPane, x + 2, y + 4, 3, h - 4 );
break;
case BOTTOM:
bg.paintRect (g2D, tabPane, x, y, w - 5, h - 1 );
bg.paintRect (g2D, tabPane, x + (w - 1) - 4, y, 4, h - 5);
bg.paintRect (g2D, tabPane, x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
bg.paintRect (g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5 );
break;
case TOP:
default:
bg.paintRect (g2D, tabPane, x, y + 2, (w - 1) - 3, (h - 1) - 1 );
bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 4, 3, h - 4 );
}
}
}
// Upper Part - not when selected and R/L/B
if (!(isSelected && (tabPlacement == RIGHT || tabPlacement == LEFT || tabPlacement == BOTTOM)))
{
Shape top = new Rectangle (x, y, w, h/2); // upper half
if (tabPlacement == TOP || tabPlacement == LEFT)
top = new Polygon ( // top left triangle
new int[] {x+6, x+w, x+w, x, x },
new int[] {y, y, y+(h/2), y+(h/2), y+6 }, 5);
else if (tabPlacement == RIGHT)
top = new Polygon ( // top right triangle
new int[] {x, x+w-6, x+w, x+w, x },
new int[] {y, y, y+6, y+(h/2), y+(h/2) }, 5);
// lighter
GradientPaint paint = new GradientPaint (
x, y, CompiereUtils.COL_1TOP,
x, y+(h/2), CompiereUtils.COL_1END);
g2D.setPaint(paint);
g2D.fill(top);
}
// Lower part - not when selected and T/R/L
if (!(isSelected && (tabPlacement == TOP || tabPlacement == RIGHT || tabPlacement == LEFT)))
{
Shape end = new Rectangle (x, y+(h/2), w, h/2); // lower half
if (tabPlacement == BOTTOM)
end = new Polygon ( // bottom left triangle
new int[] {x, x+w, x+w, x+6, x },
new int[] {y+(h/2), y+(h/2), y+h, y+h, y+h-6 }, 5);
// darker
GradientPaint paint = new GradientPaint (
x, y+(h/2), CompiereUtils.COL_2TOP,
x, y+h, CompiereUtils.COL_2END);
g2D.setPaint(paint);
g2D.fill(end);
}
} // paintTabBackground
/*************************************************************************/
/**
* Paint Content Border (overwriting BasicTabbedPanelUI)
* Uses Color from actual Tab (not from TabbedPane)
* @param g graphics
* @param tabPlacement tab placement
* @param selectedIndex index
*/
protected void paintContentBorder (Graphics g, int tabPlacement, int selectedIndex)
{
// System.out.println("TabContentBorder " );
int width = tabPane.getWidth();
int height = tabPane.getHeight();
Insets insets = tabPane.getInsets();
int x = insets.left;
int y = insets.top;
int w = width - insets.right - insets.left;
int h = height - insets.top - insets.bottom;
switch (tabPlacement)
{
case LEFT:
x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
w -= (x - insets.left);
break;
case RIGHT:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -