New popup menu for FunctionArea

This commit is contained in:
Marcel Kronfeld 2010-08-13 15:27:03 +00:00
parent e708eebd93
commit 453520096f
2 changed files with 133 additions and 125 deletions

View File

@ -167,39 +167,38 @@ public class FunctionArea extends DArea implements Serializable {
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
// do nothing // do nothing
} else { } else {
JPopupMenu GraphMenu = new JPopupMenu(); JPopupMenu graphPopupMenu = new JPopupMenu();
m_x = e.getX(); m_x = e.getX();
m_y = e.getY(); m_y = e.getY();
// The first info element // General entries
JMenuItem Info = new JMenuItem("Graph Info: " String togGTTName = (isShowGraphToolTips() ? "Deactivate":"Activate") + " graph tool tips";
+ getGraphInfo(e.getX(), e.getY())); addMenuItem(graphPopupMenu, togGTTName, new ActionListener() {
Info.addActionListener(new ActionListener() {
//
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
DPoint temp = FunctionArea.this.getDMeasures() setShowGraphToolTips(!isShowGraphToolTips());
.getDPoint(FunctionArea.this.m_x,
FunctionArea.this.m_y);
DPointIcon icon1 = new DPointIcon() {
public DBorder getDBorder() {
return new DBorder(4, 4, 4, 4);
}
public void paint(Graphics g) {
g.drawLine(-2, 0, 2, 0);
g.drawLine(0, 0, 0, 4);
}
};
temp.setIcon(icon1);
FunctionArea.this.addDElement(temp);
} }
}); });
GraphMenu.add(Info);
String togLName = (isShowLegend() ? "Hide" : "Show" ) + " legend";
addMenuItem(graphPopupMenu, togLName, new ActionListener() {
public void actionPerformed(ActionEvent ee) {
toggleLegend();
}
});
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
addMenuItem(graphPopupMenu, "Recolor all graphs", new ActionListener() {
public void actionPerformed(ActionEvent ee) {
recolorAllGraphsByIndex();
}
});
}
if (m_RefPointListener != null) { if (m_RefPointListener != null) {
DPoint temp = getDMeasures().getDPoint(m_x, m_y); DPoint temp = getDMeasures().getDPoint(m_x, m_y);
JMenuItem refPoint = new JMenuItem("Reference Point:(" addMenuItem(graphPopupMenu, "Select Reference Point:("+ temp.x + "/" + temp.y + ")",
+ temp.x + "/" + temp.y + ")"); new ActionListener() {
refPoint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
DPoint temp = getDMeasures() DPoint temp = getDMeasures()
.getDPoint(m_x, m_y); .getDPoint(m_x, m_y);
@ -209,34 +208,29 @@ public class FunctionArea extends DArea implements Serializable {
m_RefPointListener.refPointGiven(point); m_RefPointListener.refPointGiven(point);
} }
}); });
GraphMenu.add(refPoint);
} }
// darn this point is an empty copy !! // darn this point is an empty copy !!
DPoint point = getNearestDPoint(e.getX(), e.getY()); DPoint point = getNearestDPoint(e.getX(), e.getY());
if (point != null) { if (point != null) {
JMenuItem InfoXY = new JMenuItem("(" + point.x + "/" // the point info element
+ point.y + ")"); addMenuItem(graphPopupMenu, "Nearest point: (" + point.x + "/"+ point.y + ")", new ActionListener() {
Info.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ee) {}
}, false);
addMenuItem(graphPopupMenu, " Remove point", new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
removePoint(FunctionArea.this.m_x,
FunctionArea.this.m_y);
} }
}); });
GraphMenu.add(InfoXY);
if (point.getIcon() instanceof InterfaceSelectablePointIcon) { if (point.getIcon() instanceof InterfaceSelectablePointIcon) {
m_CurrentPointIcon = point.getIcon(); m_CurrentPointIcon = point.getIcon();
if (((InterfaceSelectablePointIcon) m_CurrentPointIcon) if (((InterfaceSelectablePointIcon) m_CurrentPointIcon).getSelectionListener() != null) {
.getSelectionListener() != null) { AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) m_CurrentPointIcon).getEAIndividual();
JMenuItem select; String selectTitle = indy.isMarked() ? " Deselect individual" : " Select individual";
AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) m_CurrentPointIcon) addMenuItem(graphPopupMenu, selectTitle, new ActionListener() {
.getEAIndividual();
if (indy.isMarked())
select = new JMenuItem(
"Deselect individual");
else
select = new JMenuItem("Select individual");
select.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
((InterfaceSelectablePointIcon) m_CurrentPointIcon) ((InterfaceSelectablePointIcon) m_CurrentPointIcon)
.getSelectionListener() .getSelectionListener()
@ -245,82 +239,90 @@ public class FunctionArea extends DArea implements Serializable {
.getEAIndividual()); .getEAIndividual());
} }
}); });
GraphMenu.add(select);
} }
} }
if (point.getIcon() instanceof InterfaceDPointWithContent) { if (point.getIcon() instanceof InterfaceDPointWithContent) {
m_CurrentPointIcon = point.getIcon(); m_CurrentPointIcon = point.getIcon();
JMenuItem drawIndy = new JMenuItem( addMenuItem(graphPopupMenu, " Show individual", new ActionListener() {
"Show individual");
drawIndy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
((InterfaceDPointWithContent) m_CurrentPointIcon) ((InterfaceDPointWithContent) m_CurrentPointIcon)
.showIndividual(); .showIndividual();
} }
}); });
GraphMenu.add(drawIndy);
} }
} }
if (FunctionArea.this.m_PointSetContainer.size() > 0) { // there is at least one graph if (FunctionArea.this.m_PointSetContainer.size() > 0) { // there is at least one graph
String togGTTName = (isShowGraphToolTips() ? "Deactivate":"Activate") + " graph tool tips"; // The graph info element
JMenuItem togGraphToolTips = new JMenuItem(togGTTName); // int gIndex = getNearestGraphIndex(e.getX(), e.getY());
togGraphToolTips.addActionListener(new ActionListener() { addMenuItem(graphPopupMenu, "Graph Info: "+getGraphInfo(e.getX(), e.getY()),
new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
setShowGraphToolTips(!isShowGraphToolTips()); DPoint temp = FunctionArea.this.getDMeasures().getDPoint(FunctionArea.this.m_x, FunctionArea.this.m_y);
DPointIcon icon1 = new DPointIcon() {
public DBorder getDBorder() {
return new DBorder(4, 4, 4, 4);
} }
}); public void paint(Graphics g) {
GraphMenu.add(togGraphToolTips); g.drawLine(-2, 0, 2, 0);
g.drawLine(0, 0, 0, 4);
String togLName = (isShowLegend() ? "Hide" : "Show" ) + " legend";
JMenuItem togLegend = new JMenuItem(togLName);
togLegend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
toggleLegend();
} }
}); };
GraphMenu.add(togLegend); temp.setIcon(icon1);
FunctionArea.this.addDElement(temp);
}
}, false);
JMenuItem removeGraph = new JMenuItem("Remove graph"); addMenuItem(graphPopupMenu, " Remove graph", new ActionListener() {
removeGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
clearGraph(FunctionArea.this.m_x, clearGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y); FunctionArea.this.m_y);
} }
}); });
GraphMenu.add(removeGraph);
JMenuItem changecolorGraph = new JMenuItem("Change graph color"); addMenuItem(graphPopupMenu, " Change graph color", new ActionListener() {
changecolorGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
changeColorGraph(FunctionArea.this.m_x, changeColorGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y); FunctionArea.this.m_y);
} }
}); });
GraphMenu.add(changecolorGraph); }
graphPopupMenu.show(FunctionArea.this, e.getX(), e.getY());
}
}
});
}
JMenuItem changeAllColors = new JMenuItem("Recolor all graphs"); /**
changeAllColors.addActionListener(new ActionListener() { * Create an enabled menu item with given title and listener, add it to the menu and return it.
public void actionPerformed(ActionEvent ee) { *
recolorAllGraphsByIndex(); * @param menu
* @param title
* @param aListener
* @return
*/
private JMenuItem addMenuItem(JPopupMenu menu, String title, ActionListener aListener) {
return addMenuItem(menu, title, aListener, true);
} }
});
GraphMenu.add(changeAllColors);
JMenuItem removePoint = new JMenuItem("Remove point"); /**
removePoint.addActionListener(new ActionListener() { * Create a menu item with given title and listener, add it to the menu and return it. It may be
public void actionPerformed(ActionEvent ee) { * enabled or disabled.
removePoint(FunctionArea.this.m_x, *
FunctionArea.this.m_y); * @param menu
} * @param title
}); * @param aListener
GraphMenu.add(removePoint); * @param enabled
} * @return
GraphMenu.show(FunctionArea.this, e.getX(), e.getY()); */
} private JMenuItem addMenuItem(JPopupMenu menu, String title, ActionListener aListener, boolean enabled) {
} JMenuItem item = new JMenuItem(title);
}); // if (bgColor!=null) item.setForeground(bgColor);
item.addActionListener(aListener);
item.setEnabled(enabled);
menu.add(item);
return item;
} }
/** /**
@ -372,6 +374,7 @@ public class FunctionArea extends DArea implements Serializable {
index++; index++;
} }
} }
updateLegend();
} }
/** /**
@ -728,6 +731,11 @@ public class FunctionArea extends DArea implements Serializable {
return "none"; return "none";
} }
public Color getGraphColor(int graphIndex) {
if (graphIndex>=0) return m_PointSetContainer.get(graphIndex).getColor();
else return null;
}
/** /**
* *
* @param GraphLabel * @param GraphLabel

View File

@ -25,7 +25,7 @@ import eva2.tools.chart2d.SlimRect;
* GraphPointSets as used in FunctionArea. Painting is done in FunctionArea. As * GraphPointSets as used in FunctionArea. Painting is done in FunctionArea. As
* an alternative, an own frame could be created. * an alternative, an own frame could be created.
* *
* @author mkron * @author mkron, draeger
* *
*/ */
public class GraphPointSetLegend { public class GraphPointSetLegend {