From 8d82fc49d4ba935b2969b4e8fa2c252d14149cfe Mon Sep 17 00:00:00 2001 From: tcarver <tjc> Date: Mon, 8 Jul 2013 09:56:07 +0100 Subject: [PATCH] allow graph lines to have a line size of zero to be able to hide them --- uk/ac/sanger/artemis/components/BasePlot.java | 2 ++ uk/ac/sanger/artemis/plot/LineAttributes.java | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/uk/ac/sanger/artemis/components/BasePlot.java b/uk/ac/sanger/artemis/components/BasePlot.java index 16e8e70b1..a2c9b94d9 100644 --- a/uk/ac/sanger/artemis/components/BasePlot.java +++ b/uk/ac/sanger/artemis/components/BasePlot.java @@ -767,6 +767,8 @@ public class BasePlot extends Plot if(i < lines.length) { g.setColor(lines[i].getLineColour()); + if(lines[i].getStroke() == null) + continue; ((Graphics2D)g).setStroke(lines[i].getStroke()); } else diff --git a/uk/ac/sanger/artemis/plot/LineAttributes.java b/uk/ac/sanger/artemis/plot/LineAttributes.java index 81b7530de..f517fb51c 100644 --- a/uk/ac/sanger/artemis/plot/LineAttributes.java +++ b/uk/ac/sanger/artemis/plot/LineAttributes.java @@ -67,7 +67,7 @@ public class LineAttributes private BasicStroke stroke; private static float dotDash[] = {10.f, 5.f, 3.f, 5.f}; - private static float dash[] = {10.f}; + private static float dash[] = {5.f}; private static BasicStroke style1 = new BasicStroke(1.f); @@ -131,6 +131,8 @@ public class LineAttributes */ private static int getStyleIndex(BasicStroke stroke) { + if(stroke == null) + stroke = style1; float myDash[] = stroke.getDashArray(); if(myDash != null && myDash.length == dotDash.length) @@ -304,8 +306,13 @@ public class LineAttributes panel.add(butt, c); // line style - final JSlider slider = new JSlider(1, 10, - (int)lines[colourNumber].getStroke().getLineWidth()); + final int lineWidth; + if(lines[colourNumber].getStroke() == null) + lineWidth = 0; + else + lineWidth = (int)lines[colourNumber].getStroke().getLineWidth(); + + final JSlider slider = new JSlider(0, 10, lineWidth); Integer index[] = new Integer[STROKES.length]; for(int j=0; j<index.length; j++) index[j] = j; @@ -331,6 +338,8 @@ public class LineAttributes { public void stateChanged(ChangeEvent e) { + thislines[colourNumber].setStroke( + STROKES[lineStyle.getSelectedIndex()]); setLineSize(plot, slider, thislines, colourNumber); } }); @@ -369,11 +378,16 @@ public class LineAttributes private static void setLineSize(Plot plot, JSlider slider, LineAttributes[] thislines, int number) { - BasicStroke oldStroke = thislines[number].getStroke(); - BasicStroke newStroke = new BasicStroke(slider.getValue(), + if(slider.getValue() == 0.f) + thislines[number].setStroke(null); + else + { + BasicStroke oldStroke = thislines[number].getStroke(); + BasicStroke newStroke = new BasicStroke(slider.getValue(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1.f, oldStroke.getDashArray(), 0.f); - thislines[number].setStroke(newStroke); + thislines[number].setStroke(newStroke); + } plot.repaint(); } } -- GitLab