Allow for nice tool tips in the plot window, so that the user at least known what hes pointing at.

This commit is contained in:
Marcel Kronfeld 2010-05-12 15:32:35 +00:00
parent 95a9f99162
commit dbb25e8764
3 changed files with 73 additions and 10 deletions

View File

@ -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 <m_PointSetContainer.size()))
return ((GraphPointSet) (m_PointSetContainer.get(graphIndex)))
.getInfoString();
else
return "none";
}
/**
*
* @param GraphLabel
@ -1002,7 +1041,7 @@ public class FunctionArea extends DArea implements Serializable {
if (!on)
legendBox = null;
else
legendBox = new GraphPointSetLegend(m_PointSetContainer);
legendBox = new GraphPointSetLegend(m_PointSetContainer, true);
repaint();
}
@ -1055,7 +1094,7 @@ public class FunctionArea extends DArea implements Serializable {
*
*/
public void updateLegend() {
GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer);
GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer, true);
setLegend(lb);
}

View File

@ -477,7 +477,7 @@ public class GraphPointSet {
}
/**
* Causes the PointSet to interupt the connected painting at the current
* Causes the PointSet to interrupt the connected painting at the current
* position.
*/
public void jump() {
@ -568,4 +568,15 @@ public class GraphPointSet {
m_Stroke = stroke;
// setStroke(new BasicStroke( m_Stroke ));
}
/**
* Retrieve the median point of this point set.
*
* @return the median point of this point set or null if it is empty
*/
public DPoint getMedPoint() {
if (m_ConnectedPointSet==null) return null;
int medX = m_ConnectedPointSet.getSize()/2;
return m_ConnectedPointSet.getDPoint(medX);
}
}

View File

@ -51,21 +51,34 @@ public class GraphPointSetLegend {
}
private static final PairComp comperator = new PairComp();
private static final PairComp comparator = new PairComp();
/**
* A constructor which may enumerate the point sets.
*
* @param pointSetContainer
* @param pointSetContainer the set of point sets to be shown.
* @param appendIndex if true, the string entries are enumerated according to the index
*/
public GraphPointSetLegend(List<GraphPointSet> pointSetContainer) {
legendEntries = new TreeSet<Pair<String, Color>>(comperator);
public GraphPointSetLegend(List<GraphPointSet> pointSetContainer, boolean appendIndex) {
legendEntries = new TreeSet<Pair<String, Color>>(comparator);
for (int i = 0; i < pointSetContainer.size(); i++) {
GraphPointSet pointset = pointSetContainer.get(i);
legendEntries.add(new Pair<String, Color>(pointset.getInfoString(),
pointset.getColor()));
String entryStr;
if (appendIndex) entryStr = i + ": " + pointset.getInfoString();
else entryStr = pointset.getInfoString();
legendEntries.add(new Pair<String, Color>(entryStr,pointset.getColor()));
}
}
/**
* A constructor without enumeration.
*
* @param pointSetContainer the set of point sets to be shown.
*/
public GraphPointSetLegend(List<GraphPointSet> pointSetContainer) {
this(pointSetContainer, false);
}
/**
* Add the legend labels to a container.
*