001 /* 002 * $Id: BasicLoginPanelUI.java,v 1.4 2006/02/21 18:36:08 rbair Exp $ 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 package org.jdesktop.swingx.plaf.basic; 022 import java.awt.Font; 023 import java.awt.GradientPaint; 024 import java.awt.Graphics2D; 025 import java.awt.Image; 026 import java.awt.RenderingHints; 027 import java.awt.geom.GeneralPath; 028 import java.awt.image.BufferedImage; 029 import javax.swing.JComponent; 030 import javax.swing.UIManager; 031 import javax.swing.plaf.ComponentUI; 032 import org.jdesktop.swingx.JXLoginDialog; 033 import org.jdesktop.swingx.JXLoginPanel; 034 import org.jdesktop.swingx.plaf.LoginPanelUI; 035 /** 036 * Base implementation of the <code>JXLoginPanel</code> UI. 037 * 038 * @author rbair 039 */ 040 public class BasicLoginPanelUI extends LoginPanelUI { 041 private JXLoginPanel dlg; 042 043 /** Creates a new instance of BasicLoginDialogUI */ 044 public BasicLoginPanelUI(JXLoginPanel dlg) { 045 this.dlg = dlg; 046 } 047 048 public static ComponentUI createUI(JComponent c) { 049 return new BasicLoginPanelUI((JXLoginPanel)c); 050 } 051 052 public Image getBanner() { 053 int w = 400; 054 int h = 60; 055 float loginStringX = w * .05f; 056 float loginStringY = h * .75f; 057 058 BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 059 Graphics2D g2 = img.createGraphics(); 060 Font font = UIManager.getFont("JXLoginPanel.banner.font"); 061 g2.setFont(font); 062 Graphics2D originalGraphics = g2; 063 if(!dlg.getComponentOrientation().isLeftToRight()) { 064 originalGraphics = (Graphics2D)g2.create(); 065 g2.scale(-1, 1); 066 g2.translate(-w, 0); 067 loginStringX = w - (((float)font.getStringBounds(dlg.getBannerText(), 068 originalGraphics.getFontRenderContext()).getWidth()) + w * .05f); 069 } 070 071 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 072 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 073 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 074 g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 075 076 //draw a big square 077 g2.setColor(UIManager.getColor("JXLoginPanel.banner.darkBackground")); 078 g2.fillRect(0, 0, w, h); 079 080 //create the curve shape 081 GeneralPath curveShape = new GeneralPath(GeneralPath.WIND_NON_ZERO); 082 curveShape.moveTo(0, h * .6f); 083 curveShape.curveTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f); 084 curveShape.lineTo(w, h); 085 curveShape.lineTo(0, h); 086 curveShape.lineTo(0, h * .8f); 087 curveShape.closePath(); 088 089 //draw into the buffer a gradient (bottom to top), and the text "Login" 090 GradientPaint gp = new GradientPaint(0, h, UIManager.getColor("JXLoginPanel.banner.darkBackground"), 091 0, 0, UIManager.getColor("JXLoginPanel.banner.lightBackground")); 092 g2.setPaint(gp); 093 g2.fill(curveShape); 094 095 originalGraphics.setColor(UIManager.getColor("JXLoginPanel.banner.foreground")); 096 originalGraphics.drawString(dlg.getBannerText(), loginStringX, loginStringY); 097 return img; 098 } 099 }