0N/A/*
2362N/A * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.java.swing.plaf.motif;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.swing.plaf.basic.BasicTabbedPaneUI;
0N/Aimport java.io.Serializable;
0N/A
0N/A/**
0N/A * A Motif L&F implementation of TabbedPaneUI.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is appropriate
0N/A * for short term storage or RMI between applications running the same
0N/A * version of Swing. A future release of Swing will provide support for
0N/A * long term persistence.
0N/A *
0N/A * @author Amy Fowler
0N/A * @author Philip Milne
0N/A */
0N/Apublic class MotifTabbedPaneUI extends BasicTabbedPaneUI
0N/A{
0N/A
0N/A// Instance variables initialized at installation
0N/A
0N/A protected Color unselectedTabBackground;
0N/A protected Color unselectedTabForeground;
0N/A protected Color unselectedTabShadow;
0N/A protected Color unselectedTabHighlight;
0N/A
0N/A
0N/A// UI creation
0N/A
0N/A public static ComponentUI createUI(JComponent tabbedPane) {
0N/A return new MotifTabbedPaneUI();
0N/A }
0N/A
0N/A
0N/A// UI Installation/De-installation
0N/A
0N/A
0N/A protected void installDefaults() {
0N/A super.installDefaults();
0N/A
0N/A unselectedTabBackground = UIManager.getColor("TabbedPane.unselectedTabBackground");
0N/A unselectedTabForeground = UIManager.getColor("TabbedPane.unselectedTabForeground");
0N/A unselectedTabShadow = UIManager.getColor("TabbedPane.unselectedTabShadow");
0N/A unselectedTabHighlight = UIManager.getColor("TabbedPane.unselectedTabHighlight");
0N/A }
0N/A
0N/A protected void uninstallDefaults() {
0N/A super.uninstallDefaults();
0N/A
0N/A unselectedTabBackground = null;
0N/A unselectedTabForeground = null;
0N/A unselectedTabShadow = null;
0N/A unselectedTabHighlight = null;
0N/A }
0N/A
0N/A// UI Rendering
0N/A
0N/A protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
0N/A int selectedIndex,
0N/A int x, int y, int w, int h) {
0N/A Rectangle selRect = selectedIndex < 0? null :
0N/A getTabBounds(selectedIndex, calcRect);
0N/A g.setColor(lightHighlight);
0N/A
0N/A // Draw unbroken line if tabs are not on TOP, OR
0N/A // selected tab is not visible (SCROLL_TAB_LAYOUT)
0N/A //
0N/A if (tabPlacement != TOP || selectedIndex < 0 ||
0N/A (selRect.x < x || selRect.x > x + w)) {
0N/A g.drawLine(x, y, x+w-2, y);
0N/A } else {
0N/A // Break line to show visual connection to selected tab
0N/A g.drawLine(x, y, selRect.x - 1, y);
0N/A if (selRect.x + selRect.width < x + w - 2) {
0N/A g.drawLine(selRect.x + selRect.width, y,
0N/A x+w-2, y);
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
0N/A int selectedIndex,
0N/A int x, int y, int w, int h) {
0N/A Rectangle selRect = selectedIndex < 0? null :
0N/A getTabBounds(selectedIndex, calcRect);
0N/A g.setColor(shadow);
0N/A
0N/A // Draw unbroken line if tabs are not on BOTTOM, OR
0N/A // selected tab is not visible (SCROLL_TAB_LAYOUT)
0N/A //
0N/A if (tabPlacement != BOTTOM || selectedIndex < 0 ||
0N/A (selRect.x < x || selRect.x > x + w)) {
0N/A g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
0N/A } else {
0N/A // Break line to show visual connection to selected tab
0N/A g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
0N/A if (selRect.x + selRect.width < x + w - 2) {
0N/A g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
0N/A int selectedIndex,
0N/A int x, int y, int w, int h) {
0N/A Rectangle selRect = selectedIndex < 0? null :
0N/A getTabBounds(selectedIndex, calcRect);
0N/A g.setColor(shadow);
0N/A // Draw unbroken line if tabs are not on RIGHT, OR
0N/A // selected tab is not visible (SCROLL_TAB_LAYOUT)
0N/A //
0N/A if (tabPlacement != RIGHT || selectedIndex < 0 ||
0N/A (selRect.y < y || selRect.y > y + h)) {
0N/A g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
0N/A } else {
0N/A // Break line to show visual connection to selected tab
0N/A g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
0N/A if (selRect.y + selRect.height < y + h - 2 ) {
0N/A g.drawLine(x+w-1, selRect.y + selRect.height,
0N/A x+w-1, y+h-2);
0N/A }
0N/A }
0N/A }
0N/A
0N/A protected void paintTabBackground(Graphics g,
0N/A int tabPlacement, int tabIndex,
0N/A int x, int y, int w, int h,
0N/A boolean isSelected ) {
0N/A g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
0N/A switch(tabPlacement) {
0N/A case LEFT:
0N/A g.fillRect(x+1, y+1, w-1, h-2);
0N/A break;
0N/A case RIGHT:
0N/A g.fillRect(x, y+1, w-1, h-2);
0N/A break;
0N/A case BOTTOM:
0N/A g.fillRect(x+1, y, w-2, h-3);
0N/A g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
0N/A g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
0N/A break;
0N/A case TOP:
0N/A default:
0N/A g.fillRect(x+1, y+3, w-2, h-3);
0N/A g.drawLine(x+2, y+2, x+w-3, y+2);
0N/A g.drawLine(x+3, y+1, x+w-4, y+1);
0N/A }
0N/A
0N/A }
0N/A
0N/A protected void paintTabBorder(Graphics g,
0N/A int tabPlacement, int tabIndex,
0N/A int x, int y, int w, int h,
0N/A boolean isSelected) {
0N/A g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
0N/A
0N/A switch(tabPlacement) {
0N/A case LEFT:
0N/A g.drawLine(x, y+2, x, y+h-3);
0N/A g.drawLine(x+1, y+1, x+1, y+2);
0N/A g.drawLine(x+2, y, x+2, y+1);
0N/A g.drawLine(x+3, y, x+w-1, y);
0N/A g.setColor(isSelected? shadow : unselectedTabShadow);
0N/A g.drawLine(x+1, y+h-3, x+1, y+h-2);
0N/A g.drawLine(x+2, y+h-2, x+2, y+h-1);
0N/A g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
0N/A break;
0N/A case RIGHT:
0N/A g.drawLine(x, y, x+w-3, y);
0N/A g.setColor(isSelected? shadow : unselectedTabShadow);
0N/A g.drawLine(x+w-3, y, x+w-3, y+1);
0N/A g.drawLine(x+w-2, y+1, x+w-2, y+2);
0N/A g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
0N/A g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
0N/A g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
0N/A g.drawLine(x, y+h-1, x+w-3, y+h-1);
0N/A break;
0N/A case BOTTOM:
0N/A g.drawLine(x, y, x, y+h-3);
0N/A g.drawLine(x+1, y+h-3, x+1, y+h-2);
0N/A g.drawLine(x+2, y+h-2, x+2, y+h-1);
0N/A g.setColor(isSelected? shadow : unselectedTabShadow);
0N/A g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
0N/A g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
0N/A g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
0N/A g.drawLine(x+w-1, y, x+w-1, y+h-3);
0N/A break;
0N/A case TOP:
0N/A default:
0N/A g.drawLine(x, y+2, x, y+h-1);
0N/A g.drawLine(x+1, y+1, x+1, y+2);
0N/A g.drawLine(x+2, y, x+2, y+1);
0N/A g.drawLine(x+3, y, x+w-4, y);
0N/A g.setColor(isSelected? shadow : unselectedTabShadow);
0N/A g.drawLine(x+w-3, y, x+w-3, y+1);
0N/A g.drawLine(x+w-2, y+1, x+w-2, y+2);
0N/A g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
0N/A }
0N/A
0N/A }
0N/A
0N/A protected void paintFocusIndicator(Graphics g, int tabPlacement,
0N/A Rectangle[] rects, int tabIndex,
0N/A Rectangle iconRect, Rectangle textRect,
0N/A boolean isSelected) {
0N/A Rectangle tabRect = rects[tabIndex];
0N/A if (tabPane.hasFocus() && isSelected) {
0N/A int x, y, w, h;
0N/A g.setColor(focus);
0N/A switch(tabPlacement) {
0N/A case LEFT:
0N/A x = tabRect.x + 3;
0N/A y = tabRect.y + 3;
0N/A w = tabRect.width - 6;
0N/A h = tabRect.height - 7;
0N/A break;
0N/A case RIGHT:
0N/A x = tabRect.x + 2;
0N/A y = tabRect.y + 3;
0N/A w = tabRect.width - 6;
0N/A h = tabRect.height - 7;
0N/A break;
0N/A case BOTTOM:
0N/A x = tabRect.x + 3;
0N/A y = tabRect.y + 2;
0N/A w = tabRect.width - 7;
0N/A h = tabRect.height - 6;
0N/A break;
0N/A case TOP:
0N/A default:
0N/A x = tabRect.x + 3;
0N/A y = tabRect.y + 3;
0N/A w = tabRect.width - 7;
0N/A h = tabRect.height - 6;
0N/A }
0N/A g.drawRect(x, y, w, h);
0N/A }
0N/A }
0N/A
0N/A protected int getTabRunIndent(int tabPlacement, int run) {
0N/A return run*3;
0N/A }
0N/A
0N/A protected int getTabRunOverlay(int tabPlacement) {
0N/A tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
0N/A (int)Math.round((float)maxTabWidth * .10) :
0N/A (int)Math.round((float)maxTabHeight * .22);
0N/A
0N/A // Ensure that runover lay is not more than insets
0N/A // 2 pixel offset is set from insets to each run
0N/A switch(tabPlacement) {
0N/A case LEFT:
0N/A if( tabRunOverlay > tabInsets.right - 2 )
0N/A tabRunOverlay = tabInsets.right - 2 ;
0N/A break;
0N/A case RIGHT:
0N/A if( tabRunOverlay > tabInsets.left - 2 )
0N/A tabRunOverlay = tabInsets.left - 2 ;
0N/A break;
0N/A case TOP:
0N/A if( tabRunOverlay > tabInsets.bottom - 2 )
0N/A tabRunOverlay = tabInsets.bottom - 2 ;
0N/A break;
0N/A case BOTTOM:
0N/A if( tabRunOverlay > tabInsets.top - 2 )
0N/A tabRunOverlay = tabInsets.top - 2 ;
0N/A break;
0N/A
0N/A }
0N/A
0N/A return tabRunOverlay;
0N/A }
0N/A
0N/A}