diff --git a/src/eva2/gui/FunctionArea.java b/src/eva2/gui/FunctionArea.java index 75d4f511..7272113e 100644 --- a/src/eva2/gui/FunctionArea.java +++ b/src/eva2/gui/FunctionArea.java @@ -263,7 +263,7 @@ public class FunctionArea extends DArea implements Serializable { } } - if (FunctionArea.this.m_PointSetContainer.size() > 0) { + if (FunctionArea.this.m_PointSetContainer.size() > 0) { // there is at least one graph String togGTTName = (isShowGraphToolTips() ? "Deactivate":"Activate") + " graph tool tips"; JMenuItem togGraphToolTips = new JMenuItem(togGTTName); togGraphToolTips.addActionListener(new ActionListener() { @@ -291,17 +291,23 @@ public class FunctionArea extends DArea implements Serializable { }); GraphMenu.add(removeGraph); - JMenuItem changecolorGraph = new JMenuItem( - "Change color"); - changecolorGraph - .addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ee) { - changeColorGraph(FunctionArea.this.m_x, - FunctionArea.this.m_y); - } - }); + JMenuItem changecolorGraph = new JMenuItem("Change graph color"); + changecolorGraph.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ee) { + changeColorGraph(FunctionArea.this.m_x, + FunctionArea.this.m_y); + } + }); GraphMenu.add(changecolorGraph); + JMenuItem changeAllColors = new JMenuItem("Recolor all graphs"); + changeAllColors.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ee) { + recolorAllGraphsByIndex(); + } + }); + GraphMenu.add(changeAllColors); + JMenuItem removePoint = new JMenuItem("Remove point"); removePoint.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ee) { @@ -335,6 +341,10 @@ public class FunctionArea extends DArea implements Serializable { getGraphPointSet(GraphLabel).incColor(); repaint(); } + + public void setColorByIndex(int graphLabel, int colorIndex) { + getGraphPointSet(graphLabel).setColorByIndex(colorIndex); + } /** * @@ -349,6 +359,21 @@ public class FunctionArea extends DArea implements Serializable { updateLegend(); } + /** + * Re-color all graphs which are nonempty by their index. + * + */ + public void recolorAllGraphsByIndex() { + int index=0; + for (int i=0; i0) { + gps.setColorByIndex(index); + index++; + } + } + } + /** * * @return diff --git a/src/eva2/gui/Graph.java b/src/eva2/gui/Graph.java index 85d92d9e..cafed48c 100644 --- a/src/eva2/gui/Graph.java +++ b/src/eva2/gui/Graph.java @@ -102,6 +102,10 @@ public class Graph implements Serializable { m_Plotter.jump(); } + public void setColorByIndex(int j) { + ((Plot)m_Plotter).setColorByIndex(m_GraphLabel, j); + } + // public boolean isValid() { // this was evil in RMI, use GraphWindow instead // //return true; // return (m_Plotter != null) && (m_Plotter.getFunctionArea() != null); diff --git a/src/eva2/gui/GraphPointSet.java b/src/eva2/gui/GraphPointSet.java index 8b9fbeec..6567da91 100644 --- a/src/eva2/gui/GraphPointSet.java +++ b/src/eva2/gui/GraphPointSet.java @@ -33,6 +33,18 @@ import eva2.tools.math.Mathematics; * */ public class GraphPointSet { + // Color sequence of the plot graphs + public static Color[] colorSequence = + new Color[]{ + Color.black, Color.red, Color.blue, Color.pink, Color.green, + Color.gray, Color.magenta, Color.cyan, Color.orange, + new Color(148, 0, 211), // dark violet, + new Color(72 , 209 , 204), // turquoise + new Color(128 ,128 ,0), // olive + new Color(34 ,139 ,34), // forest green + new Color(100 ,149 ,237 ) // cornflower + }; + /** * */ @@ -404,41 +416,8 @@ public class GraphPointSet { * @return */ private Color indexToColor(int index) { - Color c = Color.black; - int k = index % 10; - switch (k) { - case 0: - c = Color.black; - break; - case 1: - c = Color.red; - break; - case 2: - c = Color.blue; - break; - case 3: - c = Color.pink; - break; - case 4: - c = Color.green; - break; - case 5: - c = Color.gray; - break; - case 6: - c = Color.magenta; - break; - case 7: - c = Color.cyan; - break; - case 8: - c = Color.orange; - break; - case 9: - c = Color.darkGray; - break; - } - return c; + int k = index % colorSequence.length; + return colorSequence[k]; } /** diff --git a/src/eva2/gui/Plot.java b/src/eva2/gui/Plot.java index 5c6d4a23..e6299117 100644 --- a/src/eva2/gui/Plot.java +++ b/src/eva2/gui/Plot.java @@ -490,6 +490,14 @@ public class Plot implements PlotInterface, Serializable { setUnconnectedPoint(range[0][1], range[1][1], graphLabel); } + public void setColorByIndex(int graphLabel, int index) { + getFunctionArea().setColorByIndex(graphLabel, index); + } + + public void recolorAllGraphsByIndex() { + getFunctionArea().recolorAllGraphsByIndex(); + } + // /** // * Just for testing the Plot class. // */