Merging MK branch rev. 581 (Methods for recoloring graphs)
This commit is contained in:
parent
3f5b844101
commit
16634440b0
@ -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,10 +291,8 @@ public class FunctionArea extends DArea implements Serializable {
|
||||
});
|
||||
GraphMenu.add(removeGraph);
|
||||
|
||||
JMenuItem changecolorGraph = new JMenuItem(
|
||||
"Change color");
|
||||
changecolorGraph
|
||||
.addActionListener(new ActionListener() {
|
||||
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);
|
||||
@ -302,6 +300,14 @@ public class FunctionArea extends DArea implements Serializable {
|
||||
});
|
||||
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) {
|
||||
@ -336,6 +342,10 @@ public class FunctionArea extends DArea implements Serializable {
|
||||
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; i<m_PointSetContainer.size(); i++) {
|
||||
GraphPointSet gps = ((GraphPointSet) (this.m_PointSetContainer.get(i)));
|
||||
if (gps.getPointCount()>0) {
|
||||
gps.setColorByIndex(index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
@ -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);
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
// */
|
||||
|
Loading…
x
Reference in New Issue
Block a user