2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import java.applet.Applet;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.FontMetrics;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.LayoutManager;
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseListener;
33 import java.awt.event.MouseMotionListener;
34 import java.util.StringTokenizer;
36 import awt2swing.Canvas;
37 import awt2swing.Frame;
39 public class Tooltip // extends Canvas implements MouseListener,
40 // MouseMotionListener
44 public void setVisible(boolean b) { } // temporary only
50 private String lastTip = "";
52 private boolean setPosition = false;
54 protected Component owner;
56 private Container mainContainer;
58 private LayoutManager mainLayout;
60 private boolean shown;
62 private final int VERTICAL_OFFSET = 20;
64 private final int HORIZONTAL_ENLARGE = 10;
72 public Tooltip(String tip, Component owner)
75 //owner.addMouseListener(this);
76 //owner.addMouseMotionListener(this);
77 //setBackground(new Color(255, 255, 220));
79 java.net.URL url = getClass().getResource("/images/link.gif");
82 linkImage = java.awt.Toolkit.getDefaultToolkit().getImage(url);
86 // public void PaintComponent(Graphics g)
88 // int w = getSize().width;
89 // int h = getSize().height;
91 // g.drawRect(0, 0, w - 1, h - 1);
93 // for (int i = 0; i < tip.length; i++)
96 // lindex = tip[i].indexOf("%LINK%");
101 // g.drawString(tip[i].substring(0, lindex), 3, (i + 1) * fontHeight
103 // x += fm.stringWidth(tip[i].substring(0, lindex) + 3);
105 // g.drawImage(linkImage, x, i * fontHeight + 1, this);
106 // if (lindex + 6 < tip[i].length())
108 // g.drawString(tip[i].substring(lindex + 6),
109 // x + linkImage.getWidth(this), (i + 1) * fontHeight - 3);
114 // g.drawString(tip[i], 3, (i + 1) * fontHeight - 3);
119 synchronized void setTip(String tip)
121 System.err.println("Tooltip: " + tip);
128 // if (lastTip.equals(tip))
134 // setPosition = true;
136 // fm = getFontMetrics(owner.getFont());
137 // fontHeight = fm.getHeight();
139 // int longestLine = 0;
140 // StringTokenizer st = new StringTokenizer(tip, "\n");
141 // this.tip = new String[st.countTokens()];
143 // while (st.hasMoreElements())
145 // this.tip[index] = st.nextToken();
146 // if (fm.stringWidth(this.tip[index]) > longestLine)
148 // longestLine = fm.stringWidth(this.tip[index]);
153 // setSize(longestLine + HORIZONTAL_ENLARGE, fontHeight * this.tip.length);
159 void setTipLocation(MouseEvent evt)
161 // if (mainContainer == null || owner == null)
166 // (owner.getLocationOnScreen().x - mainContainer.getLocationOnScreen().x)
168 // (owner.getLocationOnScreen().y
169 // - mainContainer.getLocationOnScreen().y + VERTICAL_OFFSET)
172 // // correction, whole tool tip must be visible
173 // if (mainContainer.getSize().width < (getLocation().x + getSize().width))
175 // setLocation(mainContainer.getSize().width - getSize().width,
180 private void removeToolTip()
184 // mainContainer.remove(0);
185 // mainContainer.setLayout(mainLayout);
186 // mainContainer.validate();
191 private void findMainContainer()
193 Container parent = owner.getParent();
196 if ((parent instanceof Applet) || (parent instanceof Frame))
198 mainContainer = parent;
203 parent = parent.getParent();
206 mainLayout = mainContainer.getLayout();
209 public void mouseEntered(MouseEvent me)
214 public void mouseExited(MouseEvent me)
219 public void mousePressed(MouseEvent me)
224 public void mouseReleased(MouseEvent me)
228 public void mouseClicked(MouseEvent me)
232 public void mouseMoved(MouseEvent me)
236 // findMainContainer();
237 // mainContainer.setLayout(null);
238 // mainContainer.add(this, 0);
239 // mainContainer.validate();
243 else if (setPosition)
246 // setPosition = false;
250 public void mouseDragged(MouseEvent me)