BasicTaskPaneContainerUI.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: BasicTaskPaneContainerUI.java,v 1.4 2005/10/10 18:02:53 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx.plaf.basic;
  22. import java.awt.Color;
  23. import java.awt.GradientPaint;
  24. import java.awt.Graphics;
  25. import java.awt.Graphics2D;
  26. import java.awt.Paint;
  27. import javax.swing.BorderFactory;
  28. import javax.swing.JComponent;
  29. import javax.swing.UIManager;
  30. import javax.swing.plaf.ColorUIResource;
  31. import javax.swing.plaf.ComponentUI;
  32. import org.jdesktop.swingx.JXTaskPaneContainer;
  33. import org.jdesktop.swingx.VerticalLayout;
  34. import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
  35. /**
  36.  * Base implementation of the <code>JXTaskPaneContainer</code> UI.
  37.  * 
  38.  * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
  39.  */
  40. public class BasicTaskPaneContainerUI extends TaskPaneContainerUI {
  41.   public static ComponentUI createUI(JComponent c) {
  42.     return new BasicTaskPaneContainerUI();
  43.   }
  44.   protected JXTaskPaneContainer taskPane;
  45.   protected boolean useGradient;
  46.   protected Color gradientStart;
  47.   protected Color gradientEnd;
  48.   public void installUI(JComponent c) {
  49.     super.installUI(c);
  50.     taskPane = (JXTaskPaneContainer)c;
  51.     taskPane.setLayout(new VerticalLayout(14));
  52.     taskPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
  53.     taskPane.setOpaque(true);
  54.     if (taskPane.getBackground() == null
  55.       || taskPane.getBackground() instanceof ColorUIResource) {
  56.       taskPane
  57.         .setBackground(UIManager.getColor("TaskPaneContainer.background"));
  58.     }
  59.     
  60.     useGradient = UIManager.getBoolean("TaskPaneContainer.useGradient");
  61.     if (useGradient) {
  62.       gradientStart = UIManager
  63.       .getColor("TaskPaneContainer.backgroundGradientStart");
  64.       gradientEnd = UIManager
  65.       .getColor("TaskPaneContainer.backgroundGradientEnd");
  66.     }
  67.   }
  68.   @Override
  69.   public void paint(Graphics g, JComponent c) {
  70.     Graphics2D g2d = (Graphics2D)g;
  71.     if (useGradient) {
  72.       Paint old = g2d.getPaint();
  73.       GradientPaint gradient = new GradientPaint(0, 0, gradientStart, 0, c
  74.         .getHeight(), gradientEnd);
  75.       g2d.setPaint(gradient);
  76.       g.fillRect(0, 0, c.getWidth(), c.getHeight());      
  77.       g2d.setPaint(old);
  78.     }
  79.   }
  80. }