looks-2.2.0

 - bottom;
          tx = width - right - tw;
          ty = top;
          
          cx = left + left;
          cy = top + top;
          cw = width - left - right - tw - left - right;
          
          ch = height - top - bottom - top - bottom;
          
          break;
        case 3: 
          tw = width - left - right;
          th = PlasticTabbedPaneUI.access$10400(this$0, tabPlacement, PlasticTabbedPaneUI.access$10200(this$0), PlasticTabbedPaneUI.access$10300(this$0));
          
          tx = left;
          ty = height - bottom - th;
          
          cx = left + left;
          cy = top + top;
          cw = width - left - right - left - right;
          
          ch = height - top - bottom - th - top - bottom;
          
          break;
        case 1: 
        default: 
          tw = width - left - right;
          th = PlasticTabbedPaneUI.access$10700(this$0, tabPlacement, PlasticTabbedPaneUI.access$10500(this$0), PlasticTabbedPaneUI.access$10600(this$0));
          
          tx = left;
          ty = top;
          
          cx = tx + left;
          cy = ty + th + top;
          cw = width - left - right - left - right;
          
          ch = height - top - bottom - th - top - bottom;
        }
        for (int i = 0; i < numChildren; i++)
        {
          Component child = PlasticTabbedPaneUI.access$10800(this$0).getComponent(i);
          if ((PlasticTabbedPaneUI.access$1000(this$0) != null) && (child == access$1000this$0).viewport))
          {
            JViewport viewport = (JViewport)child;
            Rectangle viewRect = viewport.getViewRect();
            int vw = tw;
            int vh = th;
            Dimension butSize = access$1000this$0).scrollForwardButton.getPreferredSize();
            switch (tabPlacement)
            {
            case 2: 
            case 4: 
              int totalTabHeight = access$10900this$0)[(tabCount - 1)].y + access$11000this$0)[(tabCount - 1)].height;
              if (totalTabHeight > th)
              {
                vh = th > 2 * height ? th - 2 * height : 0;
                if (totalTabHeight - y <= vh) {
                  vh = totalTabHeight - y;
                }
              }
              break;
            case 1: 
            case 3: 
            default: 
              int totalTabWidth = access$11100this$0)[(tabCount - 1)].x + access$11200this$0)[(tabCount - 1)].width + PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
              if (totalTabWidth > tw)
              {
                vw = tw > 2 * width ? tw - 2 * width : 0;
                if (totalTabWidth - x <= vw) {
                  vw = totalTabWidth - x;
                }
              }
              break;
            }
            child.setBounds(tx, ty, vw, vh);
          }
          else if ((PlasticTabbedPaneUI.access$1000(this$0) != null) && ((child == access$1000this$0).scrollForwardButton) || (child == access$1000this$0).scrollBackwardButton)))
          {
            Component scrollbutton = child;
            Dimension bsize = scrollbutton.getPreferredSize();
            int bx = 0;
            int by = 0;
            int bw = width;
            int bh = height;
            boolean visible = false;
            switch (tabPlacement)
            {
            case 2: 
            case 4: 
              int totalTabHeight = access$11300this$0)[(tabCount - 1)].y + access$11400this$0)[(tabCount - 1)].height + PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
              if (totalTabHeight > th)
              {
                visible = true;
                bx = tabPlacement == 2 ? tx + tw - width : tx;
                
                by = child == access$1000this$0).scrollForwardButton ? height - bottom - height : height - bottom - 2 * height;
              }
              break;
            case 1: 
            case 3: 
            default: 
              int totalTabWidth = access$11500this$0)[(tabCount - 1)].x + access$11600this$0)[(tabCount - 1)].width + PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
              if (totalTabWidth > tw)
              {
                visible = true;
                bx = child == access$1000this$0).scrollForwardButton ? width - left - width : width - left - 2 * width;
                
                by = tabPlacement == 1 ? ty + th - height : ty;
              }
              break;
            }
            child.setVisible(visible);
            if (visible) {
              child.setBounds(bx, by, bw, bh);
            }
          }
          else
          {
            child.setBounds(cx, cy, cw, ch);
          }
        }
        if ((shouldChangeFocus) && 
          (!PlasticTabbedPaneUI.access$11700(this$0))) {
          PlasticTabbedPaneUI.access$11800(this$0).requestFocus();
        }
      }
    }
  }
  
  protected void calculateTabRects(int tabPlacement, int tabCount)
  {
    FontMetrics metrics = PlasticTabbedPaneUI.access$11900(this$0);
    Dimension size = PlasticTabbedPaneUI.access$12000(this$0).getSize();
    Insets insets = PlasticTabbedPaneUI.access$12100(this$0).getInsets();
    Insets tabAreaInsets = this$0.getTabAreaInsets(tabPlacement);
    int fontHeight = metrics.getHeight();
    int selectedIndex = PlasticTabbedPaneUI.access$12200(this$0).getSelectedIndex();
    boolean verticalTabRuns = (tabPlacement == 2) || (tabPlacement == 4);
    boolean leftToRight = PlasticUtils.isLeftToRight(PlasticTabbedPaneUI.access$12300(this$0));
    int x = left;
    int y = top;
    int totalWidth = 0;
    int totalHeight = 0;
    switch (tabPlacement)
    {
    case 2: 
    case 4: 
      PlasticTabbedPaneUI.access$12402(this$0, PlasticTabbedPaneUI.access$12500(this$0, tabPlacement));
      break;
    case 1: 
    case 3: 
    default: 
      PlasticTabbedPaneUI.access$12602(this$0, PlasticTabbedPaneUI.access$12700(this$0, tabPlacement));
    }
    PlasticTabbedPaneUI.access$12802(this$0, 0);
    PlasticTabbedPaneUI.access$12902(this$0, -1);
    if (tabCount == 0) {
      return;
    }
    PlasticTabbedPaneUI.access$13002(this$0, 0);
    PlasticTabbedPaneUI.access$13102(this$0, 1);
    for (int i = 0; i < tabCount; i++)
    {
      Rectangle rect = PlasticTabbedPaneUI.access$13200(this$0)[i];
      if (!verticalTabRuns)
      {
        if (i > 0)
        {
          x = (access$13300this$0)[(i - 1)].x + access$13400this$0)[(i - 1)].width);
        }
        else
        {
          PlasticTabbedPaneUI.access$13500(this$0)[0] = 0;
          PlasticTabbedPaneUI.access$13602(this$0, 0);
          totalHeight += PlasticTabbedPaneUI.access$13700(this$0);
          x = x;
        }
        width = PlasticTabbedPaneUI.access$13800(this$0, tabPlacement, i, metrics);
        totalWidth = x + width + PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
        PlasticTabbedPaneUI.access$13902(this$0, Math.max(PlasticTabbedPaneUI.access$14000(this$0), width));
        
        y = y;
        height = PlasticTabbedPaneUI.access$14100(this$0);
      }
      else
      {
        if (i > 0)
        {
          y = (access$14200this$0)[(i - 1)].y + access$14300this$0)[(i - 1)].height);
        }
        else
        {
          PlasticTabbedPaneUI.access$14400(this$0)[0] = 0;
          PlasticTabbedPaneUI.access$14502(this$0, 0);
          totalWidth = PlasticTabbedPaneUI.access$14600(this$0);
          y = y;
        }
        height = PlasticTabbedPaneUI.access$14700(this$0, tabPlacement, i, fontHeight);
        totalHeight = y + height;
        PlasticTabbedPaneUI.access$14802(this$0, Math.max(PlasticTabbedPaneUI.access$14900(this$0), height));
        
        x = x;
        width = PlasticTabbedPaneUI.access$15000(this$0);
      }
    }
    padSelectedTab(tabPlacement, selectedIndex);
    if ((!leftToRight) && (!verticalTabRuns))
    {
      int rightMargin = width - (right + right);
      for (int i = 0; i < tabCount; i++) {
        access$15100this$0)[i].x = (rightMargin - access$15200this$0)[i].x - access$15300this$0)[i].width);
      }
    }
    access$1000this$0).tabPanel.setPreferredSize(new Dimension(totalWidth, totalHeight));
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.plastic.PlasticTabbedPaneUI.TabbedPaneScrollLayout
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.plastic;

import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

final class PlasticTabbedPaneUI$TabSelectionHandler
  implements ChangeListener
{
  PlasticTabbedPaneUI$TabSelectionHandler(PlasticTabbedPaneUI x0, PlasticTabbedPaneUI.1 x1)
  {
    this(x0);
  }
  
  private final Rectangle rect = new Rectangle();
  private final PlasticTabbedPaneUI this$0;
  
  public void stateChanged(ChangeEvent e)
  {
    JTabbedPane tabPane = (JTabbedPane)e.getSource();
    tabPane.revalidate();
    tabPane.repaint();
    if (tabPane.getTabLayoutPolicy() == 1)
    {
      int index = tabPane.getSelectedIndex();
      if ((index < PlasticTabbedPaneUI.access$800(this$0).length) && (index != -1))
      {
        rect.setBounds(PlasticTabbedPaneUI.access$900(this$0)[index]);
        Point viewPosition = access$1000this$0).viewport.getViewPosition();
        if (rect.x < x) {
          rect.x -= PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
        } else {
          rect.x += PlasticTabbedPaneUI.access$1100(this$0).getTabsOverlay();
        }
        access$1000this$0).tabPanel.scrollRectToVisible(rect);
      }
    }
  }
  
  private PlasticTabbedPaneUI$TabSelectionHandler(PlasticTabbedPaneUI paramPlasticTabbedPaneUI) {}
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.plastic.PlasticTabbedPaneUI.TabSelectionHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.plastic;

import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.JTabbedPane;

final class PlasticTabbedPaneUI$TopEmbeddedRenderer
  extends PlasticTabbedPaneUI.AbstractRenderer
{
  PlasticTabbedPaneUI$TopEmbeddedRenderer(JTabbedPane x0, PlasticTabbedPaneUI.1 x1)
  {
    this(x0);
  }
  
  private PlasticTabbedPaneUI$TopEmbeddedRenderer(JTabbedPane tabPane)
  {
    super(tabPane, null);
  }
  
  protected Insets getTabAreaInsets(Insets insets)
  {
    return EMPTY_INSETS;
  }
  
  protected Insets getContentBorderInsets(Insets defaultInsets)
  {
    return NORTH_INSETS;
  }
  
  protected Insets getTabInsets(int tabIndex, Insets tabInsets)
  {
    return new Insets(top, left + 1, bottom, right);
  }
  
  protected Insets getSelectedTabPadInsets()
  {
    return EMPTY_INSETS;
  }
  
  protected void paintTabBackground(Graphics g, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    g.setColor(selectColor);
    g.fillRect(x, y, w, h);
  }
  
  protected void paintTabBorder(Graphics g, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    g.translate(x, y);
    
    int right = w;
    int bottom = h;
    if (isFirstDisplayedTab(tabIndex, x, tabPane.getBounds().x))
    {
      if (isSelected)
      {
        g.setColor(selectHighlight);
        
        g.fillRect(0, 0, 1, bottom);
        
        g.fillRect(0, 0, right - 1, 1);
        
        g.fillRect(right - 1, 0, 1, bottom);
        g.setColor(shadowColor);
        
        g.fillRect(right - 1, 0, 1, 1);
        
        g.fillRect(right, 1, 1, bottom);
      }
    }
    else if (isSelected)
    {
      g.setColor(selectHighlight);
      
      g.fillRect(1, 1, 1, bottom - 1);
      
      g.fillRect(2, 0, right - 3, 1);
      
      g.fillRect(right - 1, 1, 1, bottom - 1);
      g.setColor(shadowColor);
      
      g.fillRect(0, 1, 1, bottom - 1);
      
      g.fillRect(1, 0, 1, 1);
      
      g.fillRect(right - 1, 0, 1, 1);
      
      g.fillRect(right, 1, 1, bottom);
    }
    else
    {
      g.setColor(shadowColor);
      g.fillRect(0, 0, 1, bottom + 2 - bottom / 2);
    }
    g.translate(-x, -y);
  }
  
  protected void paintContentBorderTopEdge(Graphics g, int x, int y, int w, int h, boolean drawBroken, Rectangle selRect, boolean isContentBorderPainted)
  {
    g.setColor(shadowColor);
    g.fillRect(x, y, w, 1);
  }
  
  protected void paintFocusIndicator(Graphics g, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) {}
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.plastic.PlasticTabbedPaneUI.TopEmbeddedRenderer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.plastic;

import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.JTabbedPane;

final class PlasticTabbedPaneUI$TopRenderer
  extends PlasticTabbedPaneUI.AbstractRenderer
{
  PlasticTabbedPaneUI$TopRenderer(JTabbedPane x0, PlasticTabbedPaneUI.1 x1)
  {
    this(x0);
  }
  
  private PlasticTabbedPaneUI$TopRenderer(JTabbedPane tabPane)
  {
    super(tabPane, null);
  }
  
  protected Insets getTabAreaInsets(Insets defaultInsets)
  {
    return new Insets(top, left + 4, bottom, right);
  }
  
  protected int getTabLabelShiftY(int tabIndex, boolean isSelected)
  {
    return isSelected ? -1 : 0;
  }
  
  protected int getTabRunOverlay(int tabRunOverlay)
  {
    return tabRunOverlay - 2;
  }
  
  protected int getTabRunIndent(int run)
  {
    return 6 * run;
  }
  
  protected Insets getSelectedTabPadInsets()
  {
    return NORTH_INSETS;
  }
  
  protected Insets getTabInsets(int tabIndex, Insets tabInsets)
  {
    return new Insets(top - 1, left - 4, bottom, right - 4);
  }
  
  protected void paintFocusIndicator(Graphics g, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)
  {
    if ((!tabPane.hasFocus()) || (!isSelected)) {
      return;
    }
    Rectangle tabRect = rects[tabIndex];
    int top = y + 1;
    int left = x + 4;
    int height = height - 3;
    int width = width - 9;
    g.setColor(focus);
    g.drawRect(left, top, width, height);
  }
  
  protected void paintTabBackground(Graphics g, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    int sel = isSelected ? 0 : 1;
    g.setColor(selectColor);
    g.fillRect(x, y + sel, w, h / 2);
    g.fillRect(x - 1, y + sel + h / 2, w + 2, h - h / 2);
  }
  
  protected void paintTabBorder(Graphics g, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    g.translate(x - 4, y);
    
    int top = 0;
    int right = w + 6;
    
    g.setColor(selectHighlight);
    
    g.drawLine(1, h - 1, 4, top + 4);
    g.fillRect(5, top + 2, 1, 2);
    g.fillRect(6, top + 1, 1, 1);
    
    g.fillRect(7, top, right - 12, 1);
    
    g.setColor(darkShadow);
    g.drawLine(right, h - 1, right - 3, top + 4);
    g.fillRect(right - 4, top + 2, 1, 2);
    g.fillRect(right - 5, top + 1, 1, 1);
    
    g.translate(-x + 4, -y);
  }
  
  protected void paintContentBorderTopEdge(Graphics g, int x, int y, int w, int h, boolean drawBroken, Rectangle selRect, boolean isContentBorderPainted)
  {
    int right = x + w - 1;
    int top = y;
    g.setColor(selectHighlight);
    if ((drawBroken) && (x >= x) && (x <= x + w))
    {
      g.fillRect(x, top, x - 2 - x, 1);
      if (x + width < x + w - 2) {
        g.fillRect(x + width + 2, top, right - 2 - x - width, 1);
      } else {
        g.fillRect(x + w - 2, top, 1, 1);
      }
    }
    else
    {
      g.fillRect(x, top, w - 1, 1);
    }
  }
  
  protected int getTabsOverlay()
  {
    return 6;
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.looks.plastic.PlasticTabbedPaneUI.TopRenderer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.looks.plastic;

import com.jgoodies.looks.LookUtils;
import com.jgoodies.looks.Options;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicTabbedPaneUI.PropertyChangeHandler;
import javax.swing.plaf.basic.BasicTabbedPaneUI.TabbedPaneLayout;
import javax.swing.plaf.metal.MetalTabbedPaneUI;
import javax.swing.text.View;

public final class PlasticTabbedPaneUI
  extends MetalTabbedPaneUI
{
  private static boolean isTabIconsEnabled = ;
  private Boolean noContentBorder;
  private Boolean embeddedTabs;
  private AbstractRenderer renderer;
  private ScrollableTabSupport tabScroller;
  private final int[] xCropLen;
  private final int[] yCropLen;
  private static final int CROP_SEGMENT = 12;
  
  public static ComponentUI createUI(JComponent tabPane)
  {
    return new PlasticTabbedPaneUI();
  }
  
  public void installUI(JComponent c)
  {
    super.installUI(c);
    embeddedTabs = ((Boolean)c.getClientProperty("jgoodies.embeddedTabs"));
    noContentBorder = ((Boolean)c.getClientProperty("jgoodies.noContentBorder"));
    renderer = createRenderer(tabPane);
  }
  
  public void uninstallUI(JComponent c)
  {
    renderer = null;
    super.uninstallUI(c);
  }
  
  protected void installComponents()
  {
    if ((scrollableTabLayoutEnabled()) && 
      (tabScroller == null))
    {
      tabScroller = new ScrollableTabSupport(tabPane.getTabPlacement());
      tabPane.add(tabScroller.viewport);
    }
  }
  
  protected void uninstallComponents()
  {
    if (scrollableTabLayoutEnabled())
    {
      tabPane.remove(tabScroller.viewport);
      tabPane.remove(tabScroller.scrollForwardButton);
      tabPane.remove(tabScroller.scrollBackwardButton);
      tabScroller = null;
    }
  }
  
  protected void installListeners()
  {
    super.installListeners();
    if ((mouseListener != null) && (LookUtils.IS_JAVA_1_4) && 
      (scrollableTabLayoutEnabled()))
    {
      tabPane.removeMouseListener(mouseListener);
      tabScroller.tabPanel.addMouseListener(mouseListener);
    }
  }
  
  protected void uninstallListeners()
  {
    if ((mouseListener != null) && (LookUtils.IS_JAVA_1_4))
    {
      if (scrollableTabLayoutEnabled()) {
        tabScroller.tabPanel.removeMouseListener(mouseListener);
      } else {
        tabPane.removeMouseListener(mouseListener);
      }
      mouseListener = null;
    }
    super.uninstallListeners();
  }
  
  protected void installKeyboardActions()
  {
    super.installKeyboardActions();
    if (scrollableTabLayoutEnabled())
    {
      Action forwardAction = new ScrollTabsForwardAction(null);
      Action backwardAction = new ScrollTabsBackwardAction(null);
      ActionMap am = SwingUtilities.getUIActionMap(tabPane);
      am.put("scrollTabsForwardAction", forwardAction);
      am.put("scrollTabsBackwardAction", backwardAction);
      tabScroller.scrollForwardButton.setAction(forwardAction);
      tabScroller.scrollBackwardButton.setAction(backwardAction);
    }
  }
  
  private boolean hasNoContentBorder()
  {
    return Boolean.TRUE.equals(noContentBorder);
  }
  
  private boolean hasEmbeddedTabs()
  {
    return Boolean.TRUE.equals(embeddedTabs);
  }
  
  private AbstractRenderer createRenderer(JTabbedPane tabbedPane)
  {
    return hasEmbeddedTabs() ? AbstractRenderer.createEmbeddedRenderer(tabbedPane) : AbstractRenderer.createRenderer(tabPane);
  }
  
  protected PropertyChangeListener createPropertyChangeListener()
  {
    return new MyPropertyChangeHandler(null);
  }
  
  protected ChangeListener createChangeListener()
  {
    return new TabSelectionHandler(null);
  }
  
  private void doLayout()
  {
    tabPane.revalidate();
    tabPane.repaint();
  }
  
  private void tabPlacementChanged()
  {
    renderer = createRenderer(tabPane);
    if (scrollableTabLayoutEnabled()) {
      tabScroller.createButtons();
    }
    doLayout();
  }
  
  private void embeddedTabsPropertyChanged(Boolean newValue)
  {
    embeddedTabs = newValue;
    renderer = createRenderer(tabPane);
    doLayout();
  }
  
  private void noContentBorderPropertyChanged(Boolean newValue)
  {
    noContentBorder = newValue;
    tabPane.repaint();
  }
  
  public void paint(Graphics g, JComponent c)
  {
    int selectedIndex = tabPane.getSelectedIndex();
    int tabPlacement = tabPane.getTabPlacement();
    
    ensureCurrentLayout();
    if (!scrollableTabLayoutEnabled()) {
      paintTabArea(g, tabPlacement, selectedIndex);
    }
    paintContentBorder(g, tabPlacement, selectedIndex);
  }
  
  protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect)
  {
    Rectangle tabRect = rects[tabIndex];
    int selectedIndex = tabPane.getSelectedIndex();
    boolean isSelected = selectedIndex == tabIndex;
    Graphics2D g2 = null;
    Polygon cropShape = null;
    Shape save = null;
    int cropx = 0;
    int cropy = 0;
    if ((scrollableTabLayoutEnabled()) && 
      ((g instanceof Graphics2D)))
    {
      g2 = (Graphics2D)g;
      
      Rectangle viewRect = tabScroller.viewport.getViewRect();
      int cropline;
      switch (tabPlacement)
      {
      case 2: 
      case 4: 
        cropline = y + height;
        if ((y < cropline) && (y + height > cropline))
        {
          cropShape = createCroppedTabClip(tabPlacement, tabRect, cropline);
          
          cropx = x;
          cropy = cropline - 1;
        }
        break;
      case 1: 
      case 3: 
      default: 
        cropline = x + width;
        if ((x < cropline) && (x + width > cropline))
        {
          cropShape = createCroppedTabClip(tabPlacement, tabRect, cropline);
          
          cropx = cropline - 1;
          cropy = y;
        }
        break;
      }
      if (cropShape != null)
      {
        save = g.getClip();
        g2.clip(cropShape);
      }
    }
    paintTabBackground(g, tabPlacement, tabIndex, x, y, width, height, isSelected);
    
    paintTabBorder(g, tabPlacement, tabIndex, x, y, width, height, isSelected);
    
    String title = tabPane.getTitleAt(tabIndex);
    Font font = tabPane.getFont();
    FontMetrics metrics = g.getFontMetrics(font);
    Icon icon = getIconForTab(tabIndex);
    
    layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
    
    paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
    
    paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
    
    paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
    if (cropShape != null)
    {
      paintCroppedTabEdge(g, tabPlacement, tabIndex, isSelected, cropx, cropy);
      
      g.setClip(save);
    }
  }
  
  public PlasticTabbedPaneUI()
  {
    xCropLen = new int[] { 1, 1, 0, 0, 1, 1, 2, 2 };
    
    yCropLen = new int[] { 0, 3, 3, 6, 6, 9, 9, 12 };
  }
  
  private Polygon createCroppedTabClip(int tabPlacement, Rectangle tabRect, int cropline)
  {
    int rlen = 0;
    int start = 0;
    int end = 0;
    int ostart = 0;
    switch (tabPlacement)
    {
    case 2: 
    case 4: 
      rlen = width;
      start = x;
      end = x + width;
      ostart = y;
      break;
    case 1: 
    case 3: 
    default: 
      rlen = height;
      start = y;
      end = y + height;
      ostart = x;
    }
    int rcnt = rlen / 12;
    if (rlen % 12 > 0) {
      rcnt++;
    }
    int npts = 2 + rcnt * 8;
    int[] xp = new int[npts];
    int[] yp = new int[npts];
    int pcnt = 0;
    
    xp[pcnt] = ostart;
    yp[(pcnt++)] = end;
    xp[pcnt] = ostart;
    yp[(pcnt++)] = start;
    for (int i = 0; i < rcnt; i++) {
      for (int j = 0; j < xCropLen.length; j++)
      {
        xp[pcnt] = (cropline - xCropLen[j]);
        yp[pcnt] = (start + i * 12 + yCropLen[j]);
        if (yp[pcnt] >= end)
        {
          yp[pcnt] = end;
          pcnt++;
          break;
        }
        pcnt++;
      }
    }
    if ((tabPlacement == 1) || (tabPlacement == 3)) {
      return new Polygon(xp, yp, pcnt);
    }
    return new Polygon(yp, xp, pcnt);
  }
  
  private void paintCroppedTabEdge(Graphics g, int tabPlacement, int tabIndex, boolean isSelected, int x, int y)
  {
    int xx;
    switch (tabPlacement)
    {
    case 2: 
    case 4: 
      xx = x;
      g.setColor(shadow);
    }
    while (xx <= x + rects[tabIndex].width)
    {
      for (int i = 0; i < xCropLen.length; i += 2) {
        g.drawLine(xx + yCropLen[i], y - xCropLen[i], xx + yCropLen[(i + 1)] - 1, y - xCropLen[(i + 1)]);
      }
      xx += 12; continue;
      
      int yy = y;
      g.setColor(shadow);
      while (yy <= y + rects[tabIndex].height)
      {
        for (int i = 0; i < xCropLen.length; i += 2) {
          g.drawLine(x - xCropLen[i], yy + yCropLen[i], x - xCropLen[(i + 1)], yy + yCropLen[(i + 1)] - 1);
        }
        yy += 12;
      }
    }
  }
  
  private void ensureCurrentLayout()
  {
    if (!tabPane.isValid()) {
      tabPane.validate();
    }
    if (!tabPane.isValid())
    {
      TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();
      layout.calculateLayoutInfo();
    }
  }
  
  public int tabForCoordinate(JTabbedPane pane, int x, int y)
  {
    ensureCurrentLayout();
    Point p = new Point(x, y);
    if (scrollableTabLayoutEnabled())
    {
      translatePointToTabPanel(x, y, p);
      Rectangle viewRect = tabScroller.viewport.getViewRect();
      if (!viewRect.contains(p)) {
        return -1;
      }
    }
    int tabCount = tabPane.getTabCount();
    for (int i = 0; i < tabCount; i++) {
      if (rects[i].contains(x, y)) {
        return i;
      }
    }
    return -1;
  }
  
  protected Rectangle getTabBounds(int tabIndex, Rectangle dest)
  {
    width = rects[tabIndex].width;
    height = rects[tabIndex].height;
    if (scrollableTabLayoutEnabled())
    {
      Point vpp = tabScroller.viewport.getLocation();
      Point viewp = tabScroller.viewport.getViewPosition();
      x = (rects[tabIndex].x + x - x);
      y = (rects[tabIndex].y + y - y);
    }
    else
    {
      x = rects[tabIndex].x;
      y = rects[tabIndex].y;
    }
    return dest;
  }
  
  private int getClosestTab(int x, int y)
  {
    int min = 0;
    int tabCount = Math.min(rects.length, tabPane.getTabCount());
    int max = tabCount;
    int tabPlacement = tabPane.getTabPlacement();
    boolean useX = (tabPlacement == 1) || (tabPlacement == 3);
    int want = useX ? x : y;
    while (min != max)
    {
      int current = (max + min) / 2;
      int maxLoc;
      int minLoc;
      int maxLoc;
      if (useX)
      {
        int minLoc = rects[current].x;
        maxLoc = minLoc + rects[current].width;
      }
      else
      {
        minLoc = rects[current].y;
        maxLoc = minLoc + rects[current].height;
      }
      if (want < minLoc)
      {
        max = current;
        if (min == max) {
          return Math.max(0, current - 1);
        }
      }
      else if (want >= maxLoc)
      {
        min = current;
        if (max - min <= 1) {
          return Math.max(current + 1, tabCount - 1);
        }
      }
      else
      {
        return current;
      }
    }
    return min;
  }
  
  private Point translatePointToTabPanel(int srcx, int srcy, Point dest)
  {
    Point vpp = tabScroller.viewport.getLocation();
    Point viewp = tabScroller.viewport.getViewPosition();
    x = (srcx - x + x);
    y = (srcy - y + y);
    return dest;
  }
  
  protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex)
  {
    int tabCount = tabPane.getTabCount();
    
    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle clipRect = g.getClipBounds();
    for (int i = runCount - 1; i >= 0; i--)
    {
      int start = tabRuns[i];
      int next = tabRuns[(i + 1)];
      int end = next != 0 ? next - 1 : tabCount - 1;
      for (int j = end; j >= start; j--) {
        if ((j != selectedIndex) && (rects[j].intersects(clipRect))) {
          paintTab(g, tabPlacement, rects, j, iconRect, textRect);
        }
      }
    }
    if ((selectedIndex >= 0) && (rects[selectedIndex].intersects(clipRect))) {
      paintTab(g, tabPlacement, rects, selectedIndex, iconRect, textRect);
    }
  }
  
  protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected)
  {
    x = (y = x = y = 0);
    
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
      tabPane.putClientProperty("html", v);
    }
    Rectangle calcRectangle = new Rectangle(tabRect);
    if (isSelected)
    {
      Insets calcInsets = getSelectedTabPadInsets(tabPlacement);
      x += left;
      y += top;
      width -= left + right;
      height -= bottom + top;
    }
    int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
    int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
    if (((tabPlacement == 4) || (tabPlacement == 2)) && (icon != null) && (title != null) && (!title.equals("")))
    {
      SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, 0, 2, 0, 11, calcRectangle, iconRect, textRect, textIconGap);
      
      xNudge += 4;
    }
    else
    {
      SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, 0, 0, 0, 11, calcRectangle, iconRect, textRect, textIconGap);
      
      y += height % 2;
    }
    tabPane.putClientProperty("html", null);
    
    x += xNudge;
    y += yNudge;
    x += xNudge;
    y += yNudge;
  }
  
  protected Icon getIconForTab(int tabIndex)
  {
    String title = tabPane.getTitleAt(tabIndex);
    boolean hasTitle = (title != null) && (title.length() > 0);
    return (!isTabIconsEnabled) && (hasTitle) ? null : super.getIconForTab(tabIndex);
  }
  
  protected LayoutManager createLayoutManager()
  {
    if (tabPane.getTabLayoutPolicy() == 1) {
      return new TabbedPaneScrollLayout(null);
    }
    return new TabbedPaneLayout(null);
  }
  
  private boolean scrollableTabLayoutEnabled()
  {
    return tabPane.getLayout() instanceof TabbedPaneScrollLayout;
  }
  
  protected boolean isTabInFirstRun(int tabIndex)
  {
    return getRunForTab(tabPane.getTabCount(), tabIndex) == 0;
  }
  
  protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex)
  {
    int width = tabPane.getWidth();
    int height = tabPane.getHeight();
    Insets insets = tabPane.getInsets();
    
    int x = left;
    int y = top;
    int w = width - right - left;
    int h = height - top - bottom;
    switch (tabPlacement)
    {
    case 2: 
      x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
      w -= x - left;
      break;
    case 4: 
      w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);
      break;
    case 3: 
      h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
      break;
    case 1: 
    default: 
      y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
      h -= y - top;
    }
    g.setColor(selectColor == null ? tabPane.getBackground() : selectColor);
    
    g.fillRect(x, y, w, h);
    
    Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect);
    boolean drawBroken = (selectedIndex >= 0) && (isTabInFirstRun(selectedIndex));
    boolean isContentBorderPainted = !hasNoContentBorder();
    
    renderer.paintContentBorderTopEdge(g, x, y, w, h, drawBroken, selRect, isContentBorderPainted);
    renderer.paintContentBorderLeftEdge(g, x, y, w, h, drawBroken, selRect, isContentBorderPainted);
    renderer.paintContentBorderBottomEdge(g, x, y, w, h, drawBroken, selRect, isContentBorderPainted);
    renderer.paintContentBorderRightEdge(g, x, y, w, h, drawBroken, selRect, isContentBorderPainted);
  }
  
  protected Insets getContentBorderInsets(int tabPlacement)
  {
    return renderer.getContentBorderInsets(super.getContentBorderInsets(tabPlacement));
  }
  
  protected Insets getTabAreaInsets(int tabPlacement)
  {
    return renderer.getTabAreaInsets(super.getTabAreaInsets(tabPlacement));
  }
  
  protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected)
  {
    return renderer.getTabLabelShiftX(tabIndex, isSelected);
  }
  
  protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected)
  {
    return renderer.getTabLabelShiftY(tabIndex, isSelected);
  }
  
  protected int getTabRunOverlay(int tabPlacement)
  {
    return renderer.getTabRunOverlay(tabRunOverlay);
  }
  
  protected boolean shouldPadTabRun(int tabPlacement, int run)
  {
    return renderer.shouldPadTabRun(run, super.shouldPadTabRun(tabPlacement, run));
  }
  
  protected int getTabRunIndent(int tabPlacement, int run)
  {
    return renderer.getTabRunIndent(run);
  }
  
  protected Insets getTabInsets(int tabPlacement, int tabIndex)
  {
    return renderer.getTabInsets(tabIndex, tabInsets);
  }
  
  protected Insets getSelectedTabPadInsets(int tabPlacement)
  {
    return renderer.getSelectedTabPadInsets();
  }
  
  protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rectangles, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)
  {
    renderer.paintFocusIndicator(g, rectangles, tabIndex, iconRect, textRect, isSelected);
  }
  
  protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    renderer.paintTabBackground(g, tabIndex, x, y, w, h, isSelected);
  }
  
  protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
  {
    renderer.paintTabBorder(g, tabIndex, x, y, w, h, isSelected);
  }
  
  protected boolean shouldRotateTabRuns(int tabPlacement)
  {
    return false;
  }
  
  private final class TabSelectionHandler
    implements ChangeListener
  {
    TabSelectionHandler(PlasticTabbedPaneUI.1 x1)
    {
      this();
    }
    
    private final Rectangle rect = new Rectangle();
    
    public void stateChanged(ChangeEvent e)
    {
      JTabbedPane tabPane = (JTabbedPane)e.getSource();
      tabPane.revalidate();
      tabPane.repaint();
      if (tabPane.getTabLayoutPolicy() == 1)
      {
        int index = tabPane.getSelectedIndex();
        if ((index < rects.length) && (index != -1))
        {
          rect.setBounds(rects[index]);
          Point viewPosition = tabScroller.viewport.getViewPosition();
          if (rect.x < x) {
            rect.x -= renderer.getTabsOverlay();
          } else {
            rect.x += renderer.getTabsOverlay();
          }
          tabScroller.tabPanel.scrollRectToVisible(rect);
        }
      }
    }
    
    private TabSelectionHandler() {}
  }
  
  private final class MyPropertyChangeHandler
    extends BasicTabbedPaneUI.PropertyChangeHandler
  {
    private MyPropertyChangeHandler()
    {
      super();
    }
    
    MyPropertyChangeHandler(PlasticTabbedPaneUI.1 x1)
    {
      this();
    }
    
    public void propertyChange(PropertyChangeEvent e)
    {
      String pName = e.getPropertyName();
      if (null == pName) {
        return;
      }
      super.propertyChange(e);
      if (pName.equals("tabPlacement"))
      {
        PlasticTabbedPaneUI.this.tabPlacementChanged();
        return;
      }
      if (pName.equals("jgoodies.embeddedTabs"))
      {
        PlasticTabbedPaneUI.this.embeddedTabsPropertyChanged((Boolean)e.getNewValue());
        return;
      }
      if (pName.equals("jgoodies.noContentBorder"))
      {
        PlasticTabbedPaneUI.this.noContentBorderPropertyChanged((Boolean)e.getNewValue());
        return;
      }
    }
  }
  
  private class TabbedPaneLayout
    extends BasicTabbedPaneUI.TabbedPaneLayout
  {
    private TabbedPaneLayout()
    {
      super();
    }
    
    TabbedPaneLayout(PlasticTabbedPaneUI.1 x1)
    {
      this();
    }
    
    protected void calculateTabRects(int tabPlacement, int tabCount)
    {
      FontMetrics metrics = getFontMetrics();
      Dimension size = tabPane.getSize();
      Insets insets = tabPane.getInsets();
      Insets theTabAreaInsets = getTabAreaInsets(tabPlacement);
      int fontHeight = metrics.getHeight();
      int selectedIndex = tabPane.getSelectedIndex();
      
      boolean verticalTabRuns = (tabPlacement == 2) || (tabPlacement == 4);
      boolean leftToRight = PlasticUtils.isLeftToRight(tabPane);
      int x;
      int y;
      int returnAt;
      switch (tabPlacement)
      {
      case 2: 
        maxTabWidth = calculateMaxTabWidth(tabPlacement);
        x = left + left;
        y = top + top;
        returnAt = height - (bottom + bottom);
        break;
      case 4: 
        maxTabWidth = calculateMaxTabWidth(tabPlacement);
        x = width - right - right - maxTabWidth;
        y = top + top;
        returnAt = height - (bottom + bottom);
        break;
      case 3: 
        maxTabHeight = calculateMaxTabHeight(tabPlacement);
        x = left + left;
        y = height - bottom - bottom - maxTabHeight;
        returnAt = width - (right + right);
        break;
      case 1: 
      default: 
        maxTabHeight = calculateMaxTabHeight(tabPlacement);
        x = left + left;
        y = top + top;
        returnAt = width - (right + right);
      }
      int theTabRunOverlay = getTabRunOverlay(tabPlacement);
      
      runCount = 0;
      selectedRun = -1;
      
      int tabInRun = -1;
      
      int runReturnAt = returnAt;
      if (tabCount == 0) {
        return;
      }
      for (int i = 0; i < tabCount; i++)
      {
        Rectangle rect = rects[i];
        tabInRun++;
        if (!verticalTabRuns)
        {
          if (i > 0)
          {
            x = (rects[(i - 1)].x + rects[(i - 1)].width);
          }
          else
          {
            tabRuns[0] = 0;
            runCount = 1;
            maxTabWidth = 0;
            x = x;
          }
          width = calculateTabWidth(tabPlacement, i, metrics);
          maxTabWidth = Math.max(maxTabWidth, width);
          if ((tabInRun != 0) && (x + width > runReturnAt))
          {
            if (runCount > tabRuns.length - 1) {
              expandTabRunsArray();
            }
            tabInRun = 0;
            tabRuns[runCount] = i;
            PlasticTabbedPaneUI.access$4608(PlasticTabbedPaneUI.this);
            x = x;
            runReturnAt -= 2 * getTabRunIndent(tabPlacement, runCount);
          }
          y = y;
          height = maxTabHeight;
        }
        else
        {
          if (i > 0)
          {
            y = (rects[(i - 1)].y + rects[(i - 1)].height);
          }
          else
          {
            tabRuns[0] = 0;
            runCount = 1;
            maxTabHeight = 0;
            y = y;
          }
          height = calculateTabHeight(tabPlacement, i, fontHeight);
          maxTabHeight = Math.max(maxTabHeight, height);
          if ((tabInRun != 0) && (y + height > runReturnAt))
          {
            if (runCount > tabRuns.length - 1) {
              expandTabRunsArray();
            }
            tabRuns[runCount] = i;
            PlasticTabbedPaneUI.access$6208(PlasticTabbedPaneUI.this);
            y = y;
            tabInRun = 0;
            runReturnAt -= 2 * getTabRunIndent(tabPlacement, runCount);
   
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd