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