I have a requirement using a customized VectorRenderer to show all associated vectors related to the one selected.
Its a bit involved but bear with me on this.
When creating the VectorXYDataset when the data exceeds the length of the screen another point the first vector
is created from a start point and the delta in X runs to the end of that screen. It then wraps by starting at the beginning
of the next line and continues until the full length of the vector has been accounted for. Each line represents a vectorseries
entry in the VectorXYDatatset. Now this works correctly. When an X/Y point is mouse-clicked, the first entry in the the series
(item=0) is colored (white) is presented correctly. However, the remaining lines show some shade of white along with the original
color for the series. what I desire is for all vectors to have the same color (white) as the first item (0) in the series.
Code snippet below:
Code: Select all
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPLot plot,
ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double dx = 0.0;
double dy = 0.0;
if (dataset instanceof VectorXYDataset) {
dx = ((VectorXYDataset)dataset).getVectorXValue(series, item);
dy = ((VectorXYDataset)dataset).getVectorYValue(series, item);
}
double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
Line2D line;
PlotOrientation orientation = plot.getOrientation();
if (orientation.equals(PlotOrientation.HORIZONTAL)) {
line = new Line2D.Double(yy0, xx0, yy1, xx1);
}
else {
line = new Line2D.Double(xx0, yy0, xx1, yy1);
}
boolean isSelected = false;
if (SelectedRaster.isItemSelected(series, item)) {
g2.setPaint(Color.WHITE);
g2.setStroke(new BasicStroke(2.0f));
isSelected = true;
}
else {
g2.setPaint(getItemPaint(series, item));
g2.setStorke(getItemStroke(series, item));
}
g2.draw(line);
if (isSelected) {
int itemCount = getItemCountOfSeries(series);
for (int k=0; k<itemCount; k++){
if (k != item){
x = dataset.getXValue(series, k);
y = dataset.getYValue(series, k);
if (dataset instanceof VectorXYDataset) {
dx = ((VectorXYDataset)dataset).getVectorXValue(series, item);
dy = ((VectorXYDataset)dataset).getVectorYValue(series, item);
}
xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
PlotOrientation nextOrient = plot.getOrientation();
Line2D nextLine;
if (nextOrient.equals(PlotOrientation.HORIZONTAL)) {
nextLine = new Line2D.Double(yy0, xx0, yy1, xx1);
}
else {
nextLine = new Line2D.Double(xx0, yy0, xx1, yy1);
}
g2.setPaint(Color.WHITE);
g2.setStroke(new BasicStroke(2.0f));
g2.draw(nextLine);
}
}
}
}
But the color used is what I'm having an issue with.
Suggestions?
Fred