001/* 002 * $Id: WindowsStatusBarUI.java 3472 2009-08-27 13:12:42Z kleopatra $ 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 022package org.jdesktop.swingx.plaf.windows; 023 024import java.awt.Graphics2D; 025import java.awt.Insets; 026import java.awt.image.BufferedImage; 027import java.util.logging.Level; 028import java.util.logging.Logger; 029 030import javax.imageio.ImageIO; 031import javax.swing.JComponent; 032import javax.swing.plaf.ComponentUI; 033 034import org.jdesktop.swingx.JXStatusBar; 035import org.jdesktop.swingx.plaf.UIManagerExt; 036import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI; 037 038/** 039 * @author rbair 040 */ 041public class WindowsStatusBarUI extends BasicStatusBarUI { 042 private static final Logger log = Logger.getLogger(WindowsStatusBarUI.class.getName()); 043 private BufferedImage leftImage; 044 private BufferedImage middleImage; 045 private BufferedImage rightImage; 046 047 048 /** Creates a new instance of WindowsStatusBarUI */ 049 public WindowsStatusBarUI() { 050 //SwingX #827: must create these here or size is incorrect 051 //TODO need to determine a better way to handle these images 052 try { 053 leftImage = ImageIO.read(WindowsStatusBarUI.class.getResource(UIManagerExt.getString("StatusBar.leftImage"))); 054 middleImage = ImageIO.read(WindowsStatusBarUI.class.getResource(UIManagerExt.getString("StatusBar.middleImage"))); 055 rightImage = ImageIO.read(WindowsStatusBarUI.class.getResource(UIManagerExt.getString("StatusBar.rightImage"))); 056 } catch (Exception e) { 057 // log the message in case of init failure 058 log.log(Level.FINE, e.getLocalizedMessage(), e); 059 } 060 } 061 062 /** 063 * Returns an instance of the UI delegate for the specified component. 064 * Each subclass must provide its own static <code>createUI</code> 065 * method that returns an instance of that UI delegate subclass. 066 * If the UI delegate subclass is stateless, it may return an instance 067 * that is shared by multiple components. If the UI delegate is 068 * stateful, then it should return a new instance per component. 069 * The default implementation of this method throws an error, as it 070 * should never be invoked. 071 */ 072 public static ComponentUI createUI(JComponent c) { 073 return new WindowsStatusBarUI(); 074 } 075 076 @Override protected void paintBackground(Graphics2D g, JXStatusBar statusBar) { 077 if (leftImage == null || middleImage == null || rightImage == null) { 078 log.severe("Failed to initialize necessary assets. Set logging to FINE to see more details."); 079 return; 080 } 081 //if bidi, reverse the image painting order 082 //TODO need to handle vertical stretching better 083 g.drawImage(leftImage, 0, 0, leftImage.getWidth(), statusBar.getHeight(), null); 084 085 if (statusBar.isResizeHandleEnabled()) { 086 g.drawImage(middleImage, leftImage.getWidth(), 0, statusBar.getWidth() - leftImage.getWidth() - rightImage.getWidth(), statusBar.getHeight(), null); 087 g.drawImage(rightImage, statusBar.getWidth() - rightImage.getWidth(), 0, rightImage.getWidth(), statusBar.getHeight(), null); 088 } else { 089 g.drawImage(middleImage, leftImage.getWidth(), 0, statusBar.getWidth() - leftImage.getWidth(), statusBar.getHeight(), null); 090 } 091 } 092 093 @Override protected Insets getSeparatorInsets(Insets insets) { 094 if (insets == null) { 095 insets = new Insets(0, 0, 0, 0); 096 } 097 insets.top = 1; 098 insets.left = 4; 099 insets.bottom = 0; 100 insets.right = 4; 101 return insets; 102 } 103}