From dbb25e87648a66b5c0231c10b88b106c08c4c807 Mon Sep 17 00:00:00 2001 From: Marcel Kronfeld Date: Wed, 12 May 2010 15:32:35 +0000 Subject: [PATCH] Allow for nice tool tips in the plot window, so that the user at least known what hes pointing at. --- src/eva2/gui/FunctionArea.java | 45 +++++++++++++++++++++++++-- src/eva2/gui/GraphPointSet.java | 13 +++++++- src/eva2/gui/GraphPointSetLegend.java | 25 +++++++++++---- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/eva2/gui/FunctionArea.java b/src/eva2/gui/FunctionArea.java index 746c7849..bf639ba5 100644 --- a/src/eva2/gui/FunctionArea.java +++ b/src/eva2/gui/FunctionArea.java @@ -16,6 +16,7 @@ package eva2.gui; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; +import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; @@ -83,13 +84,15 @@ public class FunctionArea extends DArea implements Serializable { * */ public FunctionArea() { + super(); + setToolTipText("Graph Info "); } /** * */ public FunctionArea(String xname, String yname) { - super(); + this(); setPreferredSize(new Dimension(600, 500)); setVisibleRectangle(1, 1, 100000, 1000); setAutoFocus(true); @@ -109,6 +112,30 @@ public class FunctionArea extends DArea implements Serializable { notifyNegLog = true; } + @Override + public String getToolTipText(MouseEvent event) { + int gIndex = getNearestGraphIndex(event.getX(), event.getY()); + if (gIndex >= 0) { + StringBuffer sb = new StringBuffer(super.getToolTipText()); + sb.append(gIndex); + sb.append(": "); + sb.append(getGraphInfo(gIndex)); + return sb.toString(); + } else return null; + } + + @Override + public Point getToolTipLocation(MouseEvent event) { + int gIndex = getNearestGraphIndex(event.getX(), event.getY()); + if (gIndex >= 0) { + DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex))).getMedPoint(); + Point pt2 = getDMeasures().getPoint(pt.x, pt.y); + pt2.x+=(5*(gIndex%7)); // slight shift depending on index - easier distinction of very close graphs + pt2.y-=(10+(gIndex%3)*5); + return pt2; + } else return null; + } + /** * */ @@ -641,6 +668,18 @@ public class FunctionArea extends DArea implements Serializable { return "none"; } + public String getGraphInfo(int graphIndex) { + String ret = ""; + if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0)) + return ret; + + if (graphIndex >= 0 && (graphIndex pointSetContainer) { - legendEntries = new TreeSet>(comperator); + public GraphPointSetLegend(List pointSetContainer, boolean appendIndex) { + legendEntries = new TreeSet>(comparator); for (int i = 0; i < pointSetContainer.size(); i++) { GraphPointSet pointset = pointSetContainer.get(i); - legendEntries.add(new Pair(pointset.getInfoString(), - pointset.getColor())); + String entryStr; + if (appendIndex) entryStr = i + ": " + pointset.getInfoString(); + else entryStr = pointset.getInfoString(); + legendEntries.add(new Pair(entryStr,pointset.getColor())); } } + + /** + * A constructor without enumeration. + * + * @param pointSetContainer the set of point sets to be shown. + */ + public GraphPointSetLegend(List pointSetContainer) { + this(pointSetContainer, false); + } /** * Add the legend labels to a container.