001/*
002 * $Id: WindowsTipOfTheDayUI.java 3927 2011-02-22 16:34:11Z 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 */
021package org.jdesktop.swingx.plaf.windows;
022
023import java.awt.BorderLayout;
024import java.awt.Color;
025import java.awt.Component;
026import java.awt.Dimension;
027import java.awt.Font;
028import java.awt.Graphics;
029import java.awt.Insets;
030
031import javax.swing.BorderFactory;
032import javax.swing.JComponent;
033import javax.swing.JDialog;
034import javax.swing.JLabel;
035import javax.swing.JPanel;
036import javax.swing.UIManager;
037import javax.swing.border.Border;
038import javax.swing.border.CompoundBorder;
039import javax.swing.plaf.ComponentUI;
040
041import org.jdesktop.swingx.JXTipOfTheDay;
042import org.jdesktop.swingx.JXTipOfTheDay.ShowOnStartupChoice;
043import org.jdesktop.swingx.plaf.UIManagerExt;
044import org.jdesktop.swingx.plaf.basic.BasicTipOfTheDayUI;
045
046/**
047 * Windows implementation of the TipOfTheDayUI.
048 * 
049 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
050 */
051public class WindowsTipOfTheDayUI extends BasicTipOfTheDayUI {
052
053  public static ComponentUI createUI(JComponent c) {
054    return new WindowsTipOfTheDayUI((JXTipOfTheDay)c);
055  }
056  
057  public WindowsTipOfTheDayUI(JXTipOfTheDay tipPane) {
058    super(tipPane);
059  }
060  
061  @Override
062  public JDialog createDialog(Component parentComponent,
063    final ShowOnStartupChoice choice) {
064    return createDialog(parentComponent, choice, false);
065  }
066
067  @Override
068protected void installComponents() {
069    tipPane.setLayout(new BorderLayout());
070
071    // tip icon
072    JLabel tipIcon = new JLabel();
073    tipIcon.setPreferredSize(new Dimension(60, 100));
074    tipIcon.setIcon(UIManager.getIcon("TipOfTheDay.icon"));
075    tipIcon.setHorizontalAlignment(JLabel.CENTER);
076    tipIcon.setVerticalAlignment(JLabel.TOP);
077    tipIcon.setBorder(BorderFactory.createEmptyBorder(24, 0, 0, 0));
078    tipPane.add("West", tipIcon);
079    
080    // tip area
081    JPanel rightPane = new JPanel(new BorderLayout());
082    JLabel didYouKnow = new JLabel(UIManagerExt
083      .getString("TipOfTheDay.didYouKnowText", tipPane.getLocale()));
084    didYouKnow.setPreferredSize(new Dimension(50, 32));
085    didYouKnow.setOpaque(true);
086    didYouKnow.setBackground(UIManager.getColor("TextArea.background"));
087    didYouKnow.setBorder(new CompoundBorder(BorderFactory.createMatteBorder(0,
088      0, 2, 0, tipPane.getBackground()), BorderFactory.createEmptyBorder(4, 4,
089      4, 4)));
090    didYouKnow.setFont(tipPane.getFont().deriveFont(Font.BOLD, 15));    
091    rightPane.add("North", didYouKnow);
092    
093    tipArea = new JPanel(new BorderLayout());
094    tipArea.setOpaque(true);
095    tipArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
096    tipArea.setBackground(UIManager.getColor("TextArea.background"));
097    rightPane.add("Center", tipArea);
098    
099    tipPane.add("Center", rightPane);
100  }
101  
102  public static class TipAreaBorder implements Border {
103    @Override
104    public Insets getBorderInsets(Component c) {
105      return new Insets(2, 2, 2, 2);
106    }
107    @Override
108    public boolean isBorderOpaque() {
109      return false;
110    }
111    @Override
112    public void paintBorder(Component c, Graphics g, int x, int y, int width,
113      int height) {
114      g.setColor(UIManager.getColor("TipOfTheDay.background"));
115      g.drawLine(x, y, x + width - 1, y);
116      g.drawLine(x, y, x, y + height - 1);
117  
118      g.setColor(Color.black);
119      g.drawLine(x + 1, y + 1, x + width - 3, y + 1);
120      g.drawLine(x + 1, y + 1, x + 1, y + height - 3);
121  
122      g.setColor(Color.white);
123      g.drawLine(x, y + height - 1, x + width, y + height - 1);
124      g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
125    }
126  }
127
128}