001: /*
002: * $Id: TOTDTest.java,v 1.2 2005/07/10 17:26:23 l2fprod Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: */
007: package com.l2fprod.common.demo;
008:
009: import com.l2fprod.common.swing.JTipOfTheDay;
010: import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
011: import com.l2fprod.common.swing.plaf.basic.BasicLookAndFeelAddons;
012: import com.l2fprod.common.swing.plaf.basic.BasicTipOfTheDayUI;
013: import com.l2fprod.common.swing.plaf.windows.WindowsLookAndFeelAddons;
014: import com.l2fprod.common.swing.tips.DefaultTip;
015: import com.l2fprod.common.swing.tips.DefaultTipModel;
016:
017: import java.awt.GridLayout;
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: import javax.swing.ImageIcon;
022: import javax.swing.JButton;
023: import javax.swing.JFrame;
024: import javax.swing.JOptionPane;
025: import javax.swing.JPanel;
026: import javax.swing.JTree;
027: import javax.swing.UIManager;
028:
029: public class TOTDTest extends JPanel {
030:
031: public TOTDTest() {
032: setLayout(new GridLayout(2, 1));
033:
034: try {
035: add(makeAction("Windows Look And Feel", UIManager
036: .getSystemLookAndFeelClassName(),
037: WindowsLookAndFeelAddons.class.getName()));
038: add(makeAction("Other Look And Feel", UIManager
039: .getCrossPlatformLookAndFeelClassName(),
040: BasicLookAndFeelAddons.class.getName()));
041: } catch (Exception e) {
042: }
043: }
044:
045: public static void main(String[] args) throws Exception {
046: LookAndFeelAddons.setTrackingLookAndFeelChanges(false);
047:
048: UIManager.setLookAndFeel(UIManager
049: .getSystemLookAndFeelClassName());
050:
051: JFrame frame = new JFrame("Tip of the Day Testbed");
052: frame.getContentPane().add("Center", new TOTDTest());
053: frame.pack();
054: frame.setLocationRelativeTo(null);
055: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
056: frame.setVisible(true);
057: }
058:
059: static JButton makeAction(String title, final String lnf,
060: final String addon) throws Exception {
061: final JTipOfTheDay.ShowOnStartupChoice fake = new JTipOfTheDay.ShowOnStartupChoice() {
062: private boolean value = true;
063:
064: public boolean isShowingOnStartup() {
065: return value;
066: }
067:
068: public void setShowingOnStartup(boolean showOnStartup) {
069: value = showOnStartup;
070: }
071: };
072:
073: ActionListener action = new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: try {
076: UIManager.setLookAndFeel(lnf);
077: LookAndFeelAddons.setAddon(addon);
078: } catch (Exception ex) {
079: // TODO: handle exception
080: }
081:
082: if (!fake.isShowingOnStartup()) {
083: if (JOptionPane.OK_OPTION == JOptionPane
084: .showConfirmDialog(
085: null,
086: "You previously choose to not show tips on startup.\nDo you want to cancel this choice?",
087: "Question",
088: JOptionPane.YES_NO_OPTION)) {
089: fake.setShowingOnStartup(true);
090: }
091: }
092:
093: DefaultTipModel tips = new DefaultTipModel();
094:
095: // plain text
096: tips
097: .add(new DefaultTip(
098: "tip1",
099: "This is the first tip This is the first tip This is the first tip This is the first tip This is the first tip This is the first tip\nThis is the first tip This is the first tip"));
100:
101: // html text
102: tips.add(new DefaultTip("tip2",
103: "<html>This is an html <b>TIP</b><br><center>"
104: + "<table border=\"1\">"
105: + "<tr><td>1</td><td>entry 1</td></tr>"
106: + "<tr><td>2</td><td>entry 2</td></tr>"
107: + "<tr><td>3</td><td>entry 3</td></tr>"
108: + "</table>"));
109:
110: // a Component
111: tips.add(new DefaultTip("tip3", new JTree()));
112:
113: // an Icon
114: tips.add(new DefaultTip("tip 4", new ImageIcon(
115: BasicTipOfTheDayUI.class
116: .getResource("TipOfTheDay24.gif"))));
117:
118: JTipOfTheDay totd = new JTipOfTheDay(tips);
119: totd.setCurrentTip(0);
120:
121: totd.showDialog(new JFrame("title"), fake);
122: }
123: };
124:
125: JButton button = new JButton(title);
126: button.addActionListener(action);
127: return button;
128: }
129:
130: }
|