/*
 * Copyright (c) 2009 Kathryn Huxtable and Kenneth Orr.
 *
 * This file is part of the SeaGlass Pluggable Look and Feel.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * $Id$
 */
package com.seaglasslookandfeel.painter;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;

public final class MenuBarMenuPainter extends AbstractRegionPainter {
    public static enum Which {
        BACKGROUND_DISABLED, BACKGROUND_ENABLED, BACKGROUND_SELECTED,
    };

    private Which        state;
    private PaintContext ctx;

    private Rectangle2D  rect   = new Rectangle2D.Float(0, 0, 0, 0);

    private Color        color1 = decodeColor("nimbusBase", -0.010750473f, -0.04875779f, -0.007843137f, 0);

    public MenuBarMenuPainter(Which state) {
        super();
        this.state = state;
        this.ctx = new PaintContext(new Insets(0, 0, 0, 0), new Dimension(100, 30), false,
            AbstractRegionPainter.PaintContext.CacheMode.NO_CACHING, 1.0, 1.0);
    }

    @Override
    protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
        switch (state) {
        case BACKGROUND_SELECTED:
            paintBackgroundSelected(g);
            break;
        }
    }

    @Override
    protected final PaintContext getPaintContext() {
        return ctx;
    }

    private void paintBackgroundSelected(Graphics2D g) {
        rect = decodeRect1();
        g.setPaint(color1);
        g.fill(rect);

    }

    private Rectangle2D decodeRect1() {
        rect.setRect(decodeX(1.0f), // x
            decodeY(1.0f), // y
            decodeX(2.0f) - decodeX(1.0f), // width
            decodeY(2.0f) - decodeY(1.0f)); // height
        return rect;
    }
}

@@ -835,16 +835,39 @@
 Insets;%0A
+import java.awt.Shape;%0A
 import j
@@ -1199,16 +1199,25 @@
  rect   
+         
 = new Re
@@ -1275,89 +1275,37 @@
     
-c
+backgroundC
 olor
-1
  = 
-decodeColor(%22nimbusBase%22, -0.010750473f, -0.04875779f, -0.007843137f, 0)
+Color.WHITE
 ;%0A%0A 
@@ -1789,16 +1789,31 @@
 lected(g
+, width, height
 );%0A     
@@ -1990,16 +1990,39 @@
 hics2D g
+, int width, int height
 ) %7B%0A    
@@ -2025,20 +2025,23 @@
         
-rect
+Shape s
  = decod
@@ -2041,22 +2041,40 @@
 = decode
-Rect1(
+Background(width, height
 );%0A     
@@ -2091,14 +2091,23 @@
 int(
-c
+backgroundC
 olor
-1
 );%0A 
@@ -2120,20 +2120,17 @@
  g.fill(
-rect
+s
 );%0A%0A    
@@ -2148,214 +2148,98 @@
 ate 
-Rectangle2D decodeRect1() %7B%0A        rect.setRect(decodeX(1.0f), // x%0A            decodeY(1.0f), // y%0A            decodeX(2.0f) - decodeX(1.0f), // width%0A            decodeY(2.0f) - decodeY(1.0f)); //
+Shape decodeBackground(int width, int height) %7B%0A        rect.setRect(0, 0, width,
  height
+);
 %0A   

Make selected menu bar menu white.