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

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: WindowsTipOfTheDayUI.java,v 1.3 2005/10/10 18:02:24 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.windows;
  22. import java.awt.BorderLayout;
  23. import java.awt.Color;
  24. import java.awt.Component;
  25. import java.awt.Dimension;
  26. import java.awt.Font;
  27. import java.awt.Graphics;
  28. import java.awt.Insets;
  29. import javax.swing.BorderFactory;
  30. import javax.swing.JComponent;
  31. import javax.swing.JDialog;
  32. import javax.swing.JLabel;
  33. import javax.swing.JPanel;
  34. import javax.swing.UIManager;
  35. import javax.swing.border.Border;
  36. import javax.swing.border.CompoundBorder;
  37. import javax.swing.plaf.ComponentUI;
  38. import org.jdesktop.swingx.JXTipOfTheDay;
  39. import org.jdesktop.swingx.JXTipOfTheDay.ShowOnStartupChoice;
  40. import org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI;
  41. /**
  42.  * Windows implementation of the TipOfTheDayUI.
  43.  * 
  44.  * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
  45.  */
  46. public class WindowsTipOfTheDayUI extends BasicTipOfTheDayUI {
  47.   public static ComponentUI createUI(JComponent c) {
  48.     return new WindowsTipOfTheDayUI((JXTipOfTheDay)c);
  49.   }
  50.   
  51.   public WindowsTipOfTheDayUI(JXTipOfTheDay tipPane) {
  52.     super(tipPane);
  53.   }
  54.   
  55.   @Override
  56.   public JDialog createDialog(Component parentComponent,
  57.     final ShowOnStartupChoice choice) {
  58.     return createDialog(parentComponent, choice, false);
  59.   }
  60.   protected void installComponents() {
  61.     tipPane.setLayout(new BorderLayout());
  62.     // tip icon
  63.     JLabel tipIcon = new JLabel();
  64.     tipIcon.setPreferredSize(new Dimension(60, 100));
  65.     tipIcon.setIcon(UIManager.getIcon("TipOfTheDay.icon"));
  66.     tipIcon.setHorizontalAlignment(JLabel.CENTER);
  67.     tipIcon.setVerticalAlignment(JLabel.TOP);
  68.     tipIcon.setBorder(BorderFactory.createEmptyBorder(24, 0, 0, 0));
  69.     tipPane.add("West", tipIcon);
  70.     
  71.     // tip area
  72.     JPanel rightPane = new JPanel(new BorderLayout());
  73.     JLabel didYouKnow = new JLabel(UIManager
  74.       .getString("TipOfTheDay.didYouKnowText"));
  75.     didYouKnow.setPreferredSize(new Dimension(50, 32));
  76.     didYouKnow.setOpaque(true);
  77.     didYouKnow.setBackground(UIManager.getColor("TextArea.background"));
  78.     didYouKnow.setBorder(new CompoundBorder(BorderFactory.createMatteBorder(0,
  79.       0, 2, 0, tipPane.getBackground()), BorderFactory.createEmptyBorder(4, 4,
  80.       4, 4)));
  81.     didYouKnow.setFont(tipPane.getFont().deriveFont(Font.BOLD, 15));    
  82.     rightPane.add("North", didYouKnow);
  83.     
  84.     tipArea = new JPanel(new BorderLayout());
  85.     tipArea.setOpaque(true);
  86.     tipArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
  87.     tipArea.setBackground(UIManager.getColor("TextArea.background"));
  88.     rightPane.add("Center", tipArea);
  89.     
  90.     tipPane.add("Center", rightPane);
  91.   }
  92.   
  93.   public static class TipAreaBorder implements Border {
  94.     public Insets getBorderInsets(Component c) {
  95.       return new Insets(2, 2, 2, 2);
  96.     }
  97.     public boolean isBorderOpaque() {
  98.       return false;
  99.     }
  100.     public void paintBorder(Component c, Graphics g, int x, int y, int width,
  101.       int height) {
  102.       g.setColor(UIManager.getColor("TipOfTheDay.background"));
  103.       g.drawLine(x, y, x + width - 1, y);
  104.       g.drawLine(x, y, x, y + height - 1);
  105.   
  106.       g.setColor(Color.black);
  107.       g.drawLine(x + 1, y + 1, x + width - 3, y + 1);
  108.       g.drawLine(x + 1, y + 1, x + 1, y + height - 3);
  109.   
  110.       g.setColor(Color.white);
  111.       g.drawLine(x, y + height - 1, x + width, y + height - 1);
  112.       g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
  113.     }
  114.   }
  115. }