/**
   * Applies properties from a theme to tabbed panel and all the titled tabs.
   *
   * @param theme theme to apply
   */
  private void applyTheme(TabbedPanelTitledTabTheme theme) {
    // Remove the previous theme. If we hadn't added the DefaultTheme the
    // first time we wouldn't have any theme to remove and thus we would
    // have had to implement a flag or theme reference to tell us if we
    // needed to remove a theme or not.
    tabbedPanel.getProperties().removeSuperObject(activeTheme.getTabbedPanelProperties());
    titledTabProperties.removeSuperObject(activeTheme.getTitledTabProperties());

    // Adding a super object means that any properties that are set in the
    // super
    // object will be used instead of the same properties in the default
    // properties. Note that if you have explicitly set a property, for
    // example setTabAreaOrientation in the properties for the tabbed
    // panel, then that property will not be affected by the super object
    // i.e. it will still return the same value after adding the super
    // object.
    tabbedPanel.getProperties().addSuperObject(theme.getTabbedPanelProperties());
    titledTabProperties.addSuperObject(theme.getTitledTabProperties());

    activeTheme = theme;
  }
  /** Constructor */
  private SimpleTabbedPanelExample() {
    frame.setSize(600, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(createMenuBar());
    frame.getContentPane().add(tabbedPanel, BorderLayout.CENTER);

    // Set the "close all tabs" button as a tab area component
    tabbedPanel.setTabAreaComponents(new JComponent[] {createCloseAllTabsButton(tabbedPanel)});

    // Create 6 titled tabs and add them to the tabbed panel
    for (int i = 0; i < 6; i++) tabbedPanel.addTab(createTab());

    // Apply the default theme
    tabbedPanel.getProperties().addSuperObject(themes[0].getTabbedPanelProperties());
    titledTabProperties.addSuperObject(themes[0].getTitledTabProperties());
    activeTheme = themes[0];

    frame.setVisible(true);
  }
  protected void paintPolygon(Component c, Graphics2D g, Polygon polygon, int width, int height) {
    TabbedPanel tp = TabbedUtils.getParentTabbedPanel(c);
    if (tp != null) {
      Direction d = tp.getProperties().getTabAreaOrientation();

      int i = 0;

      Color c1 = topLeftColor.getColor();
      Color c2 = bottomRightColor.getColor();

      if (d == Direction.UP) {
        g.setColor(c1);
        while (i < (roundCorners ? 3 : 1)) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c2);
        while (i < polygon.npoints - 1) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c1);
        GraphicsUtil.drawOptimizedLine(
            g, polygon.xpoints[i], polygon.ypoints[i], polygon.xpoints[0], polygon.ypoints[0]);

      } else if (d == Direction.RIGHT) {
        g.setColor(c2);
        while (i < polygon.npoints - (open ? 2 : roundCorners ? 3 : 2)) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c1);
        for (int k = i - 1; k < polygon.npoints - 2; k++) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }
        GraphicsUtil.drawOptimizedLine(
            g, polygon.xpoints[i], polygon.ypoints[i], polygon.xpoints[0], polygon.ypoints[0]);

      } else if (d == Direction.DOWN) {
        g.setColor(c2);
        while (i < (roundCorners ? 5 : 2)) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c1);
        while (i < polygon.npoints - 1) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        GraphicsUtil.drawOptimizedLine(
            g, polygon.xpoints[i], polygon.ypoints[i], polygon.xpoints[0], polygon.ypoints[0]);
      } else {
        g.setColor(c1);
        while (i < (roundCorners ? 3 : 1)) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c2);
        while (i < polygon.npoints - 1) {
          GraphicsUtil.drawOptimizedLine(
              g,
              polygon.xpoints[i],
              polygon.ypoints[i],
              polygon.xpoints[i + 1],
              polygon.ypoints[i + 1]);
          i++;
        }

        g.setColor(c1);

        GraphicsUtil.drawOptimizedLine(
            g, polygon.xpoints[i], polygon.ypoints[i], polygon.xpoints[0], polygon.ypoints[0]);
      }
    }
  }
 private void removeTabbedPanel(TabbedPanel tabbedPanel) {
   if (applied) {
     tabbedPanel.getProperties().removeSuperObject(tabbedPanelProperties);
     applied = false;
   }
 }
 private void applyTabbedPanel(TabbedPanel tabbedPanel) {
   if (!applied) {
     tabbedPanel.getProperties().addSuperObject(tabbedPanelProperties);
     applied = true;
   }
 }