001 /**
002 * Copyright (c) 2008-2009, Piet Blok
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without
006 * modification, are permitted provided that the following conditions
007 * are met:
008 *
009 * * Redistributions of source code must retain the above copyright
010 * notice, this list of conditions and the following disclaimer.
011 * * Redistributions in binary form must reproduce the above
012 * copyright notice, this list of conditions and the following
013 * disclaimer in the documentation and/or other materials provided
014 * with the distribution.
015 * * Neither the name of the copyright holder nor the names of the
016 * contributors may be used to endorse or promote products derived
017 * from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
022 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
023 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 */
031
032 package org.pbjar.jxlayer.demo;
033
034 import java.awt.BorderLayout;
035 import java.awt.Graphics;
036 import java.awt.GridLayout;
037
038 import javax.swing.JFrame;
039 import javax.swing.JPanel;
040 import javax.swing.JTextPane;
041 import javax.swing.JToolTip;
042 import javax.swing.SwingUtilities;
043 import javax.swing.border.BevelBorder;
044 import javax.swing.border.CompoundBorder;
045
046 import org.jdesktop.jxlayer.JXLayer;
047 import org.pbjar.jxlayer.plaf.ext.TransformUI;
048
049 /**
050 * Demonstrates the use of transformations in a tool tip.
051 * <p>
052 * Run a web start demo: <a
053 * href="http://www.pbjar.org/blogs/jxlayer/version_2/ZoomedTooltipDemo.jnlp">
054 * <IMG style="CLEAR: right" alt="Web Start zoomed tooltip demo"
055 * src="http://javadesktop.org/javanet_images/webstart.small2.gif"
056 * align="middle" border="1" /> </a>
057 * </p>
058 */
059 public class ToolTipDemo extends JTextPane {
060
061 private static final long serialVersionUID = 1L;
062
063 public static void main(String[] args) {
064 TransformUI.prepareForJTextComponent();
065 SwingUtilities.invokeLater(new Runnable() {
066
067 @Override
068 public void run() {
069 JFrame frame = new JFrame("Test tool tip");
070 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
071 JPanel content = new JPanel(new GridLayout(0, 3));
072 for (int index = 0; index < 9; index++) {
073 JTextPane textPane = new ToolTipDemo();
074 textPane.setBorder(new CompoundBorder(new BevelBorder(
075 BevelBorder.RAISED), new BevelBorder(
076 BevelBorder.LOWERED)));
077 textPane.setContentType("text/html");
078 textPane
079 .setText("<html><h1><font size='2'>TEST "
080 + (index + 1)
081 + "</font></h1><font size='1'>A tool tip text</font></html>");
082
083 content.add(textPane);
084 }
085 frame.add(content);
086 frame.pack();
087 frame.setLocationRelativeTo(null);
088 frame.setVisible(true);
089
090 }
091 });
092 }
093
094 {
095 // Set the tool tip text to a non empty string.
096 this.setToolTipText("Trigger");
097 }
098
099 @Override
100 public JToolTip createToolTip() {
101 return new JToolTip() {
102
103 private static final long serialVersionUID = 1L;
104
105 {
106 this.removeAll();
107 this.setLayout(new BorderLayout());
108 JTextPane tipPane = new JTextPane();
109 tipPane.setContentType(ToolTipDemo.this.getContentType());
110 tipPane.setDocument(ToolTipDemo.this.getDocument());
111 JXLayer<?> layer = TransformUtils
112 .createTransformJXLayer(tipPane, 4.0);
113 this.add(layer, BorderLayout.CENTER);
114 this.setPreferredSize(layer.getPreferredSize());
115
116 this.setComponent(ToolTipDemo.this);
117 }
118
119 @Override
120 protected void paintComponent(Graphics g) {
121 // do nothing;
122 }
123 };
124 }
125
126 }