X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FTooltip.java;h=0bbe98bc81a0e5b3ad758bdbfc3274dbcd0762fe;hb=12e7f97678ce85b0238f987d5f4eaf18512a0b94;hp=90f2e97263d148b64f34e1a8226f631a2a9f777b;hpb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;p=jalview.git diff --git a/src/jalview/appletgui/Tooltip.java b/src/jalview/appletgui/Tooltip.java index 90f2e97..0bbe98b 100755 --- a/src/jalview/appletgui/Tooltip.java +++ b/src/jalview/appletgui/Tooltip.java @@ -1,22 +1,21 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) + * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package jalview.appletgui; import java.applet.*; @@ -25,21 +24,25 @@ import java.util.*; import java.awt.*; import java.awt.event.*; -public class Tooltip - extends Canvas implements MouseListener, - MouseMotionListener +public class Tooltip extends Canvas implements MouseListener, + MouseMotionListener { private String[] tip; + private String lastTip = ""; + private boolean setPosition = false; + protected Component owner; private Container mainContainer; + private LayoutManager mainLayout; private boolean shown; private final int VERTICAL_OFFSET = 20; + private final int HORIZONTAL_ENLARGE = 10; int fontHeight = 0; @@ -77,15 +80,15 @@ public class Tooltip { if (lindex > 0) { - g.drawString(tip[i].substring(0, lindex), 3, (i + 1) * fontHeight - 3); + g.drawString(tip[i].substring(0, lindex), 3, (i + 1) * fontHeight + - 3); x += fm.stringWidth(tip[i].substring(0, lindex) + 3); } g.drawImage(linkImage, x, i * fontHeight + 1, this); if (lindex + 6 < tip[i].length()) { - g.drawString(tip[i].substring(lindex + 6), - x + linkImage.getWidth(this), - (i + 1) * fontHeight - 3); + g.drawString(tip[i].substring(lindex + 6), x + + linkImage.getWidth(this), (i + 1) * fontHeight - 3); } } else @@ -128,8 +131,7 @@ public class Tooltip index++; } - setSize(longestLine + HORIZONTAL_ENLARGE, - fontHeight * this.tip.length); + setSize(longestLine + HORIZONTAL_ENLARGE, fontHeight * this.tip.length); repaint(); @@ -137,17 +139,21 @@ public class Tooltip void setTipLocation(MouseEvent evt) { - setLocation( (owner.getLocationOnScreen().x - - mainContainer.getLocationOnScreen().x) + evt.getX(), - (owner.getLocationOnScreen().y - - mainContainer.getLocationOnScreen().y - + VERTICAL_OFFSET) + evt.getY()); + if (mainContainer == null || owner == null) + { + return; + } + setLocation((owner.getLocationOnScreen().x - mainContainer + .getLocationOnScreen().x) + + evt.getX(), (owner.getLocationOnScreen().y + - mainContainer.getLocationOnScreen().y + VERTICAL_OFFSET) + + evt.getY()); // correction, whole tool tip must be visible if (mainContainer.getSize().width < (getLocation().x + getSize().width)) { setLocation(mainContainer.getSize().width - getSize().width, - getLocation().y); + getLocation().y); } } @@ -167,7 +173,7 @@ public class Tooltip Container parent = owner.getParent(); while (true) { - if ( (parent instanceof Applet) || (parent instanceof Frame)) + if ((parent instanceof Applet) || (parent instanceof Frame)) { mainContainer = parent; break; @@ -196,10 +202,12 @@ public class Tooltip } public void mouseReleased(MouseEvent me) - {} + { + } public void mouseClicked(MouseEvent me) - {} + { + } public void mouseMoved(MouseEvent me) { @@ -220,5 +228,6 @@ public class Tooltip } public void mouseDragged(MouseEvent me) - {} + { + } }