Merging MK branch rev. 661 (graphs can be renamed in the stats-GUI)

This commit is contained in:
Marcel Kronfeld 2010-10-29 11:33:18 +00:00
parent dbbd5a5786
commit a2b88073ba
3 changed files with 105 additions and 0 deletions

View File

@ -36,6 +36,7 @@ import javax.swing.JPopupMenu;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.mocco.paretofrontviewer.InterfaceRefPointListener;
import eva2.tools.ToolBoxGui;
import eva2.tools.chart2d.Chart2DDPointIconCircle;
import eva2.tools.chart2d.Chart2DDPointIconContent;
import eva2.tools.chart2d.Chart2DDPointIconCross;
@ -194,6 +195,11 @@ public class FunctionArea extends DArea implements Serializable {
m_x = e.getX();
m_y = e.getY();
addMenuItem(graphPopupMenu, "Rename graph", new ActionListener() {
public void actionPerformed(ActionEvent ee) {
renameGraph(getNearestGraphIndex(FunctionArea.this.m_x, FunctionArea.this.m_y));
}
});
// General entries
String togGTTName = (isShowGraphToolTips() ? "Deactivate"
: "Activate")
@ -1168,6 +1174,36 @@ public class FunctionArea extends DArea implements Serializable {
repaint();
}
private boolean renameGraph(int graphIndex) {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0)) {
return false;
}
if (graphIndex >= 0 && (graphIndex <m_PointSetContainer.size())) {
String oldName = getGraphInfo(graphIndex);
String newName = ToolBoxGui.getInputPaneInitialVal(this, "Rename a graph", "Enter new name for graph " + graphIndex+ ":", oldName);
if (newName!=null) {
return renameGraph(graphIndex, newName);
}
return true;
} else {
return false;
}
}
private boolean renameGraph(int graphIndex, String newName) {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
return false;
if (graphIndex >= 0 && (graphIndex <m_PointSetContainer.size())) {
GraphPointSet gps = ((GraphPointSet) (m_PointSetContainer.get(graphIndex)));
gps.setInfoString(newName);
updateLegend();
return true;
} else {
return false;
}
}
/**
*
*/

View File

@ -548,6 +548,15 @@ public class GraphPointSet {
// setStroke(new BasicStroke( m_Stroke ));
}
/**
* Sets the info string without changing the stroke.
*
* @param x
*/
public void setInfoString(String x) {
m_InfoString = x;
}
/**
* Retrieve the median point of this point set.
*

View File

@ -0,0 +1,60 @@
package eva2.tools;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
/**
* Some helper methods connected to the GUI.
*
* @author mkron
*
*/
public class ToolBoxGui {
/**
* Create a modal dialog similar to JOptionPane.showInputDialog, with the difference that an initial
* value can be set.
*
* @see JOptionPane
* @param parent the parent component
* @param title title of the dialog
* @param message message the input field is annotated with
* @param initialVal initial value of the input field
* @return A string the user has entered or null if the user canceled the action.
*/
public static String getInputPaneInitialVal(Component parent, String title, String message, String initialVal) {
return getInputPaneInitialVal(parent, title, message, initialVal, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
}
/**
* Create a modal dialog similar to JOptionPane.showInputDialog, with the difference that an initial
* value can be set.
*
* @see JOptionPane
* @param parent the parent component
* @param title title of the dialog
* @param message message the input field is annotated with
* @param initialVal initial value of the input field
* @param msgType message type
* @param optType option type
* @return A string the user has entered or null if the user canceled the action.
*/
public static String getInputPaneInitialVal(Component parent, String title, String message, String initialVal, int msgType, int optType) {
JOptionPane jop = new JOptionPane(message, msgType, optType, (Icon)null);
jop.setWantsInput(true);
// its a mess with these initial values
jop.setInputValue(initialVal); // this I expected to work
jop.setInitialValue(initialVal); // this I expected to work next
jop.setInitialSelectionValue(initialVal); // this actually seems to work...
JDialog dialog = jop.createDialog(parent, title);
dialog.show();
Object value = jop.getValue();
if (value!=null && (value instanceof Integer) && ((Integer)value)==JOptionPane.OK_OPTION) {
String newStr=(String)jop.getInputValue();
return newStr;
} else return null;
}
}