001 /* 002 * $Id: MetalStatusBarUI.java 2405 2007-11-09 14:26:13Z rah003 $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021 022 package org.jdesktop.swingx.plaf.metal; 023 024 import java.awt.Color; 025 import java.awt.GradientPaint; 026 import java.awt.Graphics2D; 027 import java.util.List; 028 import javax.swing.JComponent; 029 import javax.swing.UIManager; 030 import javax.swing.plaf.ComponentUI; 031 import org.jdesktop.swingx.JXStatusBar; 032 import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI; 033 034 /** 035 * 036 * @author rbair 037 */ 038 public class MetalStatusBarUI extends BasicStatusBarUI { 039 040 /** Creates a new instance of BasicStatusBarUI */ 041 public MetalStatusBarUI() { 042 } 043 044 /** 045 * Returns an instance of the UI delegate for the specified component. 046 * Each subclass must provide its own static <code>createUI</code> 047 * method that returns an instance of that UI delegate subclass. 048 * If the UI delegate subclass is stateless, it may return an instance 049 * that is shared by multiple components. If the UI delegate is 050 * stateful, then it should return a new instance per component. 051 * The default implementation of this method throws an error, as it 052 * should never be invoked. 053 */ 054 public static ComponentUI createUI(JComponent c) { 055 return new MetalStatusBarUI(); 056 } 057 058 @Override 059 protected void paintBackground(Graphics2D g, JXStatusBar bar) { 060 int w = bar.getWidth(); //TODO deal with insets 061 int h = bar.getHeight(); //TODO deal with insets 062 063 //This list is comprised of floats and Colors, which together 064 //constitute the gradient. 065 List<?> gradient = (List<?>) UIManager.get("MenuBar.gradient"); 066 067 if (gradient != null && w > 0 && 0 < h) { 068 float ratio1 = ((Number)gradient.get(0)).floatValue(); 069 float ratio2 = ((Number)gradient.get(1)).floatValue(); 070 Color c1 = (Color)gradient.get(2); 071 Color c2 = (Color)gradient.get(3); 072 Color c3 = (Color)gradient.get(4); 073 int mid = (int)(ratio1 * h); 074 int mid2 = (int)(ratio2 * h); 075 if (mid > 0) { 076 g.setPaint(new GradientPaint((float)0, (float)0, c1, (float)0, 077 (float)mid, c2)); 078 g.fillRect(0, 0, w, mid); 079 } 080 if (mid2 > 0) { 081 g.setColor(c2); 082 g.fillRect(0, mid, w, mid2); 083 } 084 if (mid > 0) { 085 g.setPaint(new GradientPaint((float)0, (float)mid + mid2, c2, 086 (float)0, (float)mid * 2 + mid2, c1)); 087 g.fillRect(0, mid + mid2, w, mid); 088 } 089 if (h - mid * 2 - mid2 > 0) { 090 g.setPaint(new GradientPaint((float)0, (float)mid * 2 + mid2, c1, 091 (float)0, (float)h, c3)); 092 g.fillRect(0, mid * 2 + mid2, w, h - mid * 2 - mid2); 093 } 094 } 095 } 096 }