When adding a WindowListener to EvA's GUI, the JFrame now gets a name so that the listener can identify this frame more easily. The name is simply the class name of EvAClient.

This commit is contained in:
Andreas Dräger
2010-09-21 16:02:40 +00:00
parent 631be1307c
commit 61d409ce4c
2 changed files with 203 additions and 140 deletions

View File

@@ -325,8 +325,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
* @param l * @param l
*/ */
public void addWindowListener(WindowListener l) { public void addWindowListener(WindowListener l) {
if (m_Frame!=null) m_Frame.addWindowListener(l); if (m_Frame != null) {
else System.err.println("Error, no JFrame existent in " + this.getClass().getSimpleName()); m_Frame.setName(getClass().getSimpleName());
m_Frame.addWindowListener(l);
} else {
System.err.println("Error, no JFrame existent in "
+ this.getClass().getSimpleName());
}
} }
/** /**
@@ -335,8 +340,12 @@ public class EvAClient implements RemoteStateListener, Serializable {
* @param l * @param l
*/ */
public void removeWindowListener(WindowListener l) { public void removeWindowListener(WindowListener l) {
if (m_Frame!=null) m_Frame.removeWindowListener(l); if (m_Frame != null) {
else System.err.println("Error, no JFrame existent in " + this.getClass().getSimpleName()); m_Frame.removeWindowListener(l);
} else {
System.err.println("Error, no JFrame existent in "
+ this.getClass().getSimpleName());
}
} }
/** /**

View File

@@ -79,14 +79,15 @@ 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. * Indicate whether graphs should be annotated with tool tips if pointed to
* with the mouse.
*/ */
private boolean doShowGraphToolTips = true; private boolean doShowGraphToolTips = true;
/** /**
* Indicate whether graph legend entries should show their unique number. * Indicate whether graph legend entries should show their unique number.
*/ */
private boolean appendIndexInLegend = true; private boolean appendIndexInLegend = true;
@@ -124,6 +125,7 @@ public class FunctionArea extends DArea implements Serializable {
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see javax.swing.JComponent#getToolTipText(java.awt.event.MouseEvent) * @see javax.swing.JComponent#getToolTipText(java.awt.event.MouseEvent)
*/ */
@Override @Override
@@ -136,12 +138,15 @@ public class FunctionArea extends DArea implements Serializable {
sb.append(": "); sb.append(": ");
sb.append(getGraphInfo(gIndex)); sb.append(getGraphInfo(gIndex));
return sb.toString(); return sb.toString();
} else return null; } else
} else return null; return null;
} else
return null;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
*
* @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent) * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
*/ */
@Override @Override
@@ -149,13 +154,18 @@ public class FunctionArea extends DArea implements Serializable {
if (isShowGraphToolTips()) { if (isShowGraphToolTips()) {
int gIndex = getNearestGraphIndex(event.getX(), event.getY()); int gIndex = getNearestGraphIndex(event.getX(), event.getY());
if (gIndex >= 0) { if (gIndex >= 0) {
DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex))).getMedPoint(); DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex)))
.getMedPoint();
Point pt2 = getDMeasures().getPoint(pt.x, pt.y); 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.x += (5 * (gIndex % 7)); // slight shift depending on index
pt2.y-=(10+(gIndex%3)*5); // - easier distinction of very
// close graphs
pt2.y -= (10 + (gIndex % 3) * 5);
return pt2; return pt2;
} else return null; } else
} else return null; return null;
} else
return null;
} }
/** /**
@@ -185,14 +195,18 @@ public class FunctionArea extends DArea implements Serializable {
m_y = e.getY(); m_y = e.getY();
// General entries // General entries
String togGTTName = (isShowGraphToolTips() ? "Deactivate":"Activate") + " graph tool tips"; String togGTTName = (isShowGraphToolTips() ? "Deactivate"
addMenuItem(graphPopupMenu, togGTTName, new ActionListener() { : "Activate")
public void actionPerformed(ActionEvent ee) { + " graph tool tips";
setShowGraphToolTips(!isShowGraphToolTips()); addMenuItem(graphPopupMenu, togGTTName,
} new ActionListener() {
}); public void actionPerformed(ActionEvent ee) {
setShowGraphToolTips(!isShowGraphToolTips());
String togLName = (isShowLegend() ? "Hide" : "Show" ) + " legend"; }
});
String togLName = (isShowLegend() ? "Hide" : "Show")
+ " legend";
addMenuItem(graphPopupMenu, togLName, new ActionListener() { addMenuItem(graphPopupMenu, togLName, new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
toggleLegend(); toggleLegend();
@@ -200,128 +214,156 @@ public class FunctionArea extends DArea implements Serializable {
}); });
if (FunctionArea.this.m_PointSetContainer.size() > 0) { if (FunctionArea.this.m_PointSetContainer.size() > 0) {
addMenuItem(graphPopupMenu, "Recolor all graphs", new ActionListener() { addMenuItem(graphPopupMenu, "Recolor all graphs",
new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
recolorAllGraphsByIndex(); 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);
addMenuItem(graphPopupMenu, "Select Reference Point:("+ temp.x + "/" + temp.y + ")", addMenuItem(graphPopupMenu, "Select Reference Point:("
+ temp.x + "/" + temp.y + ")",
new ActionListener() { new ActionListener() {
public void actionPerformed(ActionEvent ee) { public void actionPerformed(ActionEvent ee) {
DPoint temp = getDMeasures() DPoint temp = getDMeasures().getDPoint(
.getDPoint(m_x, m_y); m_x, m_y);
double[] point = new double[2]; double[] point = new double[2];
point[0] = temp.x; point[0] = temp.x;
point[1] = temp.y; point[1] = temp.y;
m_RefPointListener.refPointGiven(point); m_RefPointListener.refPointGiven(point);
} }
}); });
} }
// 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) {
// the point info element // the point info element
addMenuItem(graphPopupMenu, "Nearest point: (" + point.x + "/"+ point.y + ")", new ActionListener() { addMenuItem(graphPopupMenu, "Nearest point: ("
public void actionPerformed(ActionEvent ee) {} + point.x + "/" + point.y + ")",
}, false); new ActionListener() {
public void actionPerformed(ActionEvent ee) {
}
}, false);
addMenuItem(graphPopupMenu, " Remove point", new ActionListener() { addMenuItem(graphPopupMenu, " Remove point",
public void actionPerformed(ActionEvent ee) { new ActionListener() {
removePoint(FunctionArea.this.m_x, public void actionPerformed(ActionEvent ee) {
FunctionArea.this.m_y); removePoint(FunctionArea.this.m_x,
} FunctionArea.this.m_y);
}); }
});
if (point.getIcon() instanceof InterfaceSelectablePointIcon) { if (point.getIcon() instanceof InterfaceSelectablePointIcon) {
m_CurrentPointIcon = point.getIcon(); m_CurrentPointIcon = point.getIcon();
if (((InterfaceSelectablePointIcon) m_CurrentPointIcon).getSelectionListener() != null) { if (((InterfaceSelectablePointIcon) m_CurrentPointIcon)
AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) m_CurrentPointIcon).getEAIndividual(); .getSelectionListener() != null) {
String selectTitle = indy.isMarked() ? " Deselect individual" : " Select individual"; AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) m_CurrentPointIcon)
addMenuItem(graphPopupMenu, selectTitle, new ActionListener() { .getEAIndividual();
public void actionPerformed(ActionEvent ee) { String selectTitle = indy.isMarked() ? " Deselect individual"
((InterfaceSelectablePointIcon) m_CurrentPointIcon) : " Select individual";
.getSelectionListener() addMenuItem(graphPopupMenu, selectTitle,
.individualSelected( new ActionListener() {
public void actionPerformed(
ActionEvent ee) {
((InterfaceSelectablePointIcon) m_CurrentPointIcon) ((InterfaceSelectablePointIcon) m_CurrentPointIcon)
.getEAIndividual()); .getSelectionListener()
} .individualSelected(
}); ((InterfaceSelectablePointIcon) m_CurrentPointIcon)
.getEAIndividual());
}
});
} }
} }
if (point.getIcon() instanceof InterfaceDPointWithContent) { if (point.getIcon() instanceof InterfaceDPointWithContent) {
m_CurrentPointIcon = point.getIcon(); m_CurrentPointIcon = point.getIcon();
addMenuItem(graphPopupMenu, " Show individual", new ActionListener() { addMenuItem(graphPopupMenu, " Show individual",
public void actionPerformed(ActionEvent ee) { new ActionListener() {
((InterfaceDPointWithContent) m_CurrentPointIcon) public void actionPerformed(
.showIndividual(); ActionEvent ee) {
} ((InterfaceDPointWithContent) m_CurrentPointIcon)
}); .showIndividual();
}
});
} }
} }
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
// The graph info element // The graph info element
// int gIndex = getNearestGraphIndex(e.getX(), e.getY()); // int gIndex = getNearestGraphIndex(e.getX(),
addMenuItem(graphPopupMenu, "Graph Info: "+getGraphInfo(e.getX(), e.getY()), // e.getY());
new ActionListener() { addMenuItem(graphPopupMenu, "Graph Info: "
public void actionPerformed(ActionEvent ee) { + getGraphInfo(e.getX(), e.getY()),
DPoint temp = FunctionArea.this.getDMeasures().getDPoint(FunctionArea.this.m_x, FunctionArea.this.m_y); new ActionListener() {
DPointIcon icon1 = new DPointIcon() { public void actionPerformed(ActionEvent ee) {
public DBorder getDBorder() { DPoint temp = FunctionArea.this
return new DBorder(4, 4, 4, 4); .getDMeasures().getDPoint(
} FunctionArea.this.m_x,
public void paint(Graphics g) { FunctionArea.this.m_y);
g.drawLine(-2, 0, 2, 0); DPointIcon icon1 = new DPointIcon() {
g.drawLine(0, 0, 0, 4); public DBorder getDBorder() {
} return new DBorder(4, 4, 4, 4);
}; }
temp.setIcon(icon1);
FunctionArea.this.addDElement(temp);
}
}, false);
addMenuItem(graphPopupMenu, " Remove graph", new ActionListener() {
public void actionPerformed(ActionEvent ee) {
clearGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y);
}
});
addMenuItem(graphPopupMenu, " Change graph color", new ActionListener() { public void paint(Graphics g) {
public void actionPerformed(ActionEvent ee) { g.drawLine(-2, 0, 2, 0);
changeColorGraph(FunctionArea.this.m_x, g.drawLine(0, 0, 0, 4);
FunctionArea.this.m_y); }
} };
}); temp.setIcon(icon1);
FunctionArea.this.addDElement(temp);
}
}, false);
addMenuItem(graphPopupMenu, " Remove graph",
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
clearGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y);
}
});
addMenuItem(graphPopupMenu, " Change graph color",
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
changeColorGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y);
}
});
} }
graphPopupMenu.show(FunctionArea.this, e.getX(), e.getY()); graphPopupMenu.show(FunctionArea.this, e.getX(), e.getY());
} }
} }
}); });
} }
/** /**
* Create an enabled menu item with given title and listener, add it to the menu and return it. * Create an enabled menu item with given title and listener, add it to the
* menu and return it.
* *
* @param menu * @param menu
* @param title * @param title
* @param aListener * @param aListener
* @return * @return
*/ */
private JMenuItem addMenuItem(JPopupMenu menu, String title, ActionListener aListener) { private JMenuItem addMenuItem(JPopupMenu menu, String title,
ActionListener aListener) {
return addMenuItem(menu, title, aListener, true); return addMenuItem(menu, title, aListener, true);
} }
/** /**
* Create a menu item with given title and listener, add it to the menu and return it. It may be * Create a menu item with given title and listener, add it to the menu and
* enabled or disabled. * return it. It may be enabled or disabled.
* *
* @param menu * @param menu
* @param title * @param title
@@ -329,9 +371,10 @@ public class FunctionArea extends DArea implements Serializable {
* @param enabled * @param enabled
* @return * @return
*/ */
private JMenuItem addMenuItem(JPopupMenu menu, String title, ActionListener aListener, boolean enabled) { private JMenuItem addMenuItem(JPopupMenu menu, String title,
ActionListener aListener, boolean enabled) {
JMenuItem item = new JMenuItem(title); JMenuItem item = new JMenuItem(title);
// if (bgColor!=null) item.setForeground(bgColor); // if (bgColor!=null) item.setForeground(bgColor);
item.addActionListener(aListener); item.addActionListener(aListener);
item.setEnabled(enabled); item.setEnabled(enabled);
menu.add(item); menu.add(item);
@@ -356,7 +399,7 @@ public class FunctionArea extends DArea implements Serializable {
getGraphPointSet(GraphLabel).incColor(); getGraphPointSet(GraphLabel).incColor();
repaint(); repaint();
} }
public void setColorByIndex(int graphLabel, int colorIndex) { public void setColorByIndex(int graphLabel, int colorIndex) {
getGraphPointSet(graphLabel).setColorByIndex(colorIndex); getGraphPointSet(graphLabel).setColorByIndex(colorIndex);
} }
@@ -379,10 +422,11 @@ public class FunctionArea extends DArea implements Serializable {
* *
*/ */
public void recolorAllGraphsByIndex() { public void recolorAllGraphsByIndex() {
int index=0; int index = 0;
for (int i=0; i<m_PointSetContainer.size(); i++) { for (int i = 0; i < m_PointSetContainer.size(); i++) {
GraphPointSet gps = ((GraphPointSet) (this.m_PointSetContainer.get(i))); GraphPointSet gps = ((GraphPointSet) (this.m_PointSetContainer
if (gps.getPointCount()>0) { .get(i)));
if (gps.getPointCount() > 0) {
gps.setColorByIndex(index); gps.setColorByIndex(index);
index++; index++;
} }
@@ -411,7 +455,8 @@ public class FunctionArea extends DArea implements Serializable {
DPointSet pSet = (m_PointSetContainer.get(i).getConnectedPointSet()); DPointSet pSet = (m_PointSetContainer.get(i).getConnectedPointSet());
if (pSet.getSize() > 0) { if (pSet.getSize() > 0) {
double tmpMinY = Math.min(minY, pSet.getMinPositiveYValue()); double tmpMinY = Math.min(minY, pSet.getMinPositiveYValue());
if (tmpMinY>0) minY=tmpMinY; if (tmpMinY > 0)
minY = tmpMinY;
} }
} }
return minY; return minY;
@@ -441,7 +486,8 @@ public class FunctionArea extends DArea implements Serializable {
for (int i = 0; i < m_PointSetContainer.size(); i++) for (int i = 0; i < m_PointSetContainer.size(); i++)
((GraphPointSet) (m_PointSetContainer.get(i))).removeAllPoints(); ((GraphPointSet) (m_PointSetContainer.get(i))).removeAllPoints();
m_PointSetContainer.clear(); m_PointSetContainer.clear();
if (getYScale() instanceof Exp) setYScale(new Exp()); // to remove smallest seen value if (getYScale() instanceof Exp)
setYScale(new Exp()); // to remove smallest seen value
notifyNegLog = true; notifyNegLog = true;
} }
@@ -452,7 +498,7 @@ public class FunctionArea extends DArea implements Serializable {
getGraphPointSet(graphLabel).removeAllPoints(); getGraphPointSet(graphLabel).removeAllPoints();
m_PointSetContainer.remove(getGraphPointSet(graphLabel)); m_PointSetContainer.remove(getGraphPointSet(graphLabel));
if (getYScale() instanceof Exp) { if (getYScale() instanceof Exp) {
((Exp)getYScale()).setMinValue(getMinimalPositiveYValue()); ((Exp) getYScale()).setMinValue(getMinimalPositiveYValue());
} }
repaint(); repaint();
notifyNegLog = true; notifyNegLog = true;
@@ -713,7 +759,7 @@ public class FunctionArea extends DArea implements Serializable {
public int getContainerSize() { public int getContainerSize() {
return m_PointSetContainer.size(); return m_PointSetContainer.size();
} }
/** /**
* *
* @param x * @param x
@@ -737,18 +783,20 @@ public class FunctionArea extends DArea implements Serializable {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0)) if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
return ret; return ret;
if (graphIndex >= 0 && (graphIndex <m_PointSetContainer.size())) if (graphIndex >= 0 && (graphIndex < m_PointSetContainer.size()))
return ((GraphPointSet) (m_PointSetContainer.get(graphIndex))) return ((GraphPointSet) (m_PointSetContainer.get(graphIndex)))
.getInfoString(); .getInfoString();
else else
return "none"; return "none";
} }
public Color getGraphColor(int graphIndex) { public Color getGraphColor(int graphIndex) {
if (graphIndex>=0) return m_PointSetContainer.get(graphIndex).getColor(); if (graphIndex >= 0)
else return null; return m_PointSetContainer.get(graphIndex).getColor();
else
return null;
} }
/** /**
* *
* @param GraphLabel * @param GraphLabel
@@ -944,9 +992,10 @@ public class FunctionArea extends DArea implements Serializable {
public void setConnectedPoint(double x, double y, int graphLabel) { public void setConnectedPoint(double x, double y, int graphLabel) {
DFunction scF = getYScale(); DFunction scF = getYScale();
if (scF instanceof Exp) ((Exp)scF).updateMinValue(y); if (scF instanceof Exp)
((Exp) scF).updateMinValue(y);
if (!checkLogValidYValue(x, y, graphLabel)) { if (!checkLogValidYValue(x, y, graphLabel)) {
// if (m_log) toggleLog(); // if (m_log) toggleLog();
} }
getGraphPointSet(graphLabel).addDPoint(x, y); getGraphPointSet(graphLabel).addDPoint(x, y);
} }
@@ -1065,7 +1114,6 @@ public class FunctionArea extends DArea implements Serializable {
repaint(); repaint();
} }
/** /**
* *
* @param x * @param x
@@ -1074,9 +1122,10 @@ public class FunctionArea extends DArea implements Serializable {
*/ */
public void setUnconnectedPoint(double x, double y, int GraphLabel) { public void setUnconnectedPoint(double x, double y, int GraphLabel) {
DFunction scF = getYScale(); DFunction scF = getYScale();
if (scF instanceof Exp) ((Exp)scF).updateMinValue(y); if (scF instanceof Exp)
((Exp) scF).updateMinValue(y);
if (!checkLogValidYValue(x, y, GraphLabel)) { if (!checkLogValidYValue(x, y, GraphLabel)) {
// if (m_log) toggleLog(); // if (m_log) toggleLog();
} }
this.getGraphPointSet(GraphLabel).addDPoint(x, y); this.getGraphPointSet(GraphLabel).addDPoint(x, y);
this.getGraphPointSet(GraphLabel).setConnectedMode(false); this.getGraphPointSet(GraphLabel).setConnectedMode(false);
@@ -1103,7 +1152,7 @@ public class FunctionArea extends DArea implements Serializable {
public boolean isShowLegend() { public boolean isShowLegend() {
return m_legend; return m_legend;
} }
/** /**
* Shows the legend or switches it off. * Shows the legend or switches it off.
* *
@@ -1111,10 +1160,12 @@ public class FunctionArea extends DArea implements Serializable {
*/ */
public void setShowLegend(boolean on) { public void setShowLegend(boolean on) {
m_legend = on; m_legend = on;
if (!on) if (!on) {
legendBox = null; legendBox = null;
else } else {
legendBox = new GraphPointSetLegend(m_PointSetContainer, isAppendIndexInLegend()); legendBox = new GraphPointSetLegend(m_PointSetContainer,
isAppendIndexInLegend());
}
repaint(); repaint();
} }
@@ -1123,20 +1174,22 @@ public class FunctionArea extends DArea implements Serializable {
*/ */
public void toggleLog() { public void toggleLog() {
// System.out.println("ToggleLog log was: "+m_log); // System.out.println("ToggleLog log was: "+m_log);
boolean setMinPos=false; boolean setMinPos = false;
if (!m_log && !checkLoggable()) { if (!m_log && !checkLoggable()) {
System.err.println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed."); System.err
setMinPos=true; .println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed.");
setMinPos = true;
} }
if (m_log == false) { if (m_log == false) {
setMinRectangle(0.001, 0.001, 1, 1); setMinRectangle(0.001, 0.001, 1, 1);
//setVisibleRectangle( 0.001, 0.001, 100000, 1000 ); // setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
Exp exp = new Exp(); Exp exp = new Exp();
if (setMinPos) exp.setMinValue(getMinimalPositiveYValue()); if (setMinPos)
setYScale(exp); exp.setMinValue(getMinimalPositiveYValue());
m_Border.setSrcdY(Math.log(10)); setYScale(exp);
m_Border.applyPattern(false, "0.###E0"); m_Border.setSrcdY(Math.log(10));
m_log = true; m_Border.applyPattern(false, "0.###E0");
m_log = true;
} else { } else {
m_log = false; m_log = false;
setYScale(null); setYScale(null);
@@ -1167,7 +1220,8 @@ public class FunctionArea extends DArea implements Serializable {
* *
*/ */
public void updateLegend() { public void updateLegend() {
GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer, isAppendIndexInLegend() ); GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer,
isAppendIndexInLegend());
setLegend(lb); setLegend(lb);
} }