KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > tips > TipsOverlay


1 package org.antlr.works.tips;
2
3 import org.antlr.xjlib.appkit.frame.XJFrameInterface;
4 import org.antlr.works.tooltip.ToolTipList;
5 import org.antlr.works.tooltip.ToolTipListDelegate;
6 import org.antlr.works.utils.OverlayObject;
7
8 import javax.swing.*;
9 import java.awt.*;
10 import java.util.Iterator JavaDoc;
11 import java.util.List JavaDoc;
12 /*
13
14 [The "BSD licence"]
15 Copyright (c) 2005 Jean Bovet
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions
20 are met:
21
22 1. Redistributions of source code must retain the above copyright
23 notice, this list of conditions and the following disclaimer.
24 2. Redistributions in binary form must reproduce the above copyright
25 notice, this list of conditions and the following disclaimer in the
26 documentation and/or other materials provided with the distribution.
27 3. The name of the author may not be used to endorse or promote products
28 derived from this software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
34 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 */

42
43 public class TipsOverlay extends OverlayObject implements ToolTipListDelegate {
44
45     protected ToolTipList toolTip;
46     protected Point location;
47
48     public TipsOverlay(XJFrameInterface parentFrame, JComponent parentComponent) {
49         super(parentFrame, parentComponent);
50     }
51
52     public void setTips(List<String JavaDoc> tips) {
53         toolTip.clear();
54         for(Iterator JavaDoc<String JavaDoc> iter = tips.iterator(); iter.hasNext();) {
55             toolTip.addLine(iter.next());
56         }
57         toolTip.selectFirstLine();
58     }
59
60     public void setLocation(Point location) {
61         this.location = location;
62         resize();
63     }
64
65     public JComponent overlayCreateInterface() {
66         JPanel panel = new JPanel(new BorderLayout());
67
68         toolTip = new ToolTipList(this);
69         panel.add(toolTip, BorderLayout.CENTER);
70
71         return panel;
72     }
73
74     public void resize() {
75         toolTip.resize();
76         if(location != null)
77             content.setBounds(location.x, location.y, toolTip.getWidth(), toolTip.getHeight());
78     }
79
80     public boolean overlayWillDisplay() {
81         return true;
82     }
83
84     public void toolTipListHide() {
85         hide();
86     }
87 }
88
89
Popular Tags