Minor extension to (de-)activate graph tool tip info strings.

This commit is contained in:
Marcel Kronfeld 2010-08-04 14:10:03 +00:00
parent 8c8ca11924
commit 3f5b844101
2 changed files with 64 additions and 17 deletions

View File

@ -80,6 +80,11 @@ public class FunctionArea extends DArea implements Serializable {
*/ */
private boolean notifyNegLog = true; private boolean notifyNegLog = true;
/**
* Indicate whether graphs should be annotated with tool tips if pointed to with the mouse.
*/
private boolean doShowGraphToolTips = true;
/** /**
* *
*/ */
@ -114,25 +119,29 @@ public class FunctionArea extends DArea implements Serializable {
@Override @Override
public String getToolTipText(MouseEvent event) { public String getToolTipText(MouseEvent event) {
int gIndex = getNearestGraphIndex(event.getX(), event.getY()); if (isShowGraphToolTips()) {
if (gIndex >= 0) { int gIndex = getNearestGraphIndex(event.getX(), event.getY());
StringBuffer sb = new StringBuffer(super.getToolTipText()); if (gIndex >= 0) {
sb.append(gIndex); StringBuffer sb = new StringBuffer(super.getToolTipText());
sb.append(": "); sb.append(gIndex);
sb.append(getGraphInfo(gIndex)); sb.append(": ");
return sb.toString(); sb.append(getGraphInfo(gIndex));
return sb.toString();
} else return null;
} else return null; } else return null;
} }
@Override @Override
public Point getToolTipLocation(MouseEvent event) { public Point getToolTipLocation(MouseEvent event) {
int gIndex = getNearestGraphIndex(event.getX(), event.getY()); if (isShowGraphToolTips()) {
if (gIndex >= 0) { int gIndex = getNearestGraphIndex(event.getX(), event.getY());
DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex))).getMedPoint(); if (gIndex >= 0) {
Point pt2 = getDMeasures().getPoint(pt.x, pt.y); DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex))).getMedPoint();
pt2.x+=(5*(gIndex%7)); // slight shift depending on index - easier distinction of very close graphs Point pt2 = getDMeasures().getPoint(pt.x, pt.y);
pt2.y-=(10+(gIndex%3)*5); pt2.x+=(5*(gIndex%7)); // slight shift depending on index - easier distinction of very close graphs
return pt2; pt2.y-=(10+(gIndex%3)*5);
return pt2;
} else return null;
} else return null; } else return null;
} }
@ -255,7 +264,17 @@ public class FunctionArea extends DArea implements Serializable {
} }
if (FunctionArea.this.m_PointSetContainer.size() > 0) { if (FunctionArea.this.m_PointSetContainer.size() > 0) {
JMenuItem togLegend = new JMenuItem("Toggle legend"); String togGTTName = (isShowGraphToolTips() ? "Deactivate":"Activate") + " graph tool tips";
JMenuItem togGraphToolTips = new JMenuItem(togGTTName);
togGraphToolTips.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
setShowGraphToolTips(!isShowGraphToolTips());
}
});
GraphMenu.add(togGraphToolTips);
String togLName = (isShowLegend() ? "Hide" : "Show" ) + " legend";
JMenuItem togLegend = new JMenuItem(togLName);
togLegend.addActionListener(new ActionListener() { togLegend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
toggleLegend(); toggleLegend();
@ -1035,12 +1054,16 @@ public class FunctionArea extends DArea implements Serializable {
repaint(); repaint();
} }
public boolean isShowLegend() {
return m_legend;
}
/** /**
* Shows the legend or switches it off. * Shows the legend or switches it off.
* *
* @param on * @param on
*/ */
public void showLegend(boolean on) { public void setShowLegend(boolean on) {
m_legend = on; m_legend = on;
if (!on) if (!on)
legendBox = null; legendBox = null;
@ -1112,4 +1135,12 @@ public class FunctionArea extends DArea implements Serializable {
public String getInfoString(int j) { public String getInfoString(int j) {
return getGraphPointSet(j).getInfoString(); return getGraphPointSet(j).getInfoString();
} }
public void setShowGraphToolTips(boolean doShowGraphToolTips) {
this.doShowGraphToolTips = doShowGraphToolTips;
}
public boolean isShowGraphToolTips() {
return doShowGraphToolTips;
}
} }

View File

@ -245,6 +245,22 @@ public class Plot implements PlotInterface, Serializable {
m_Frame.setVisible(true); m_Frame.setVisible(true);
} }
/**
* Indicate whether the graphs are annotated by tool tip info strings.
* @return true if the graphs are annotated by tool tip info strings
*/
public boolean isShowGraphToolTips() {
return m_PlotArea.isShowGraphToolTips();
}
/**
* Toggle whether the graphs should be annotated by tool tip info strings.
* @param doShowGraphToolTips true if the graphs should be annotated by tool tip info strings
*/
public void setShowGraphToolTips(boolean doShowGraphToolTips) {
m_PlotArea.setShowGraphToolTips(doShowGraphToolTips);
}
/** /**
* Draw a population to the Plot instance. Each individual is annotated with * Draw a population to the Plot instance. Each individual is annotated with
* the given prefix and its fitness. * the given prefix and its fitness.