From: jprocter Date: Fri, 2 Apr 2010 14:41:39 +0000 (+0000) Subject: load and save graduated feature colours in XML X-Git-Tag: Release_2_5~87 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0e5bdbba50619f3c626b14c7f1cd2261e0552440;p=jalview.git load and save graduated feature colours in XML --- diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index d8a674f..7bf291d 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -33,6 +33,7 @@ import javax.swing.event.*; import javax.swing.table.*; import jalview.analysis.AlignmentSorter; +import jalview.bin.Cache; import jalview.commands.OrderCommand; import jalview.datamodel.*; import jalview.io.*; @@ -606,15 +607,62 @@ public class FeatureSettings extends JPanel InputStreamReader in = new InputStreamReader(new FileInputStream( file), "UTF-8"); - jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours(); - jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in); - + jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours(); + jucs = (jalview.schemabinding.version2.JalviewUserColours) jucs.unmarshal(in); + for (int i = jucs.getColourCount() - 1; i >= 0; i--) { String name; - // TODO: update Colour XML - fr.setColour(name = jucs.getColour(i).getName(), new Color( + jalview.schemabinding.version2.Colour newcol = jucs.getColour(i); + if (newcol.hasMax()) + { + Color mincol=null,maxcol=null; + float thrsh=Float.NaN; + try { + mincol = new Color( + Integer.parseInt(newcol.getMinRGB(), 16)); + maxcol = new Color( + Integer.parseInt(newcol.getRGB(), 16)); + + } catch (Exception e) + { + Cache.log.warn("Couldn't parse out graduated feature color.",e); + } + GraduatedColor gcol = + new GraduatedColor(mincol,maxcol, + newcol.getMin(),newcol.getMax()); + if (newcol.hasAutoScale()) + { + gcol.setAutoScaled(newcol.getAutoScale()); + } + if (newcol.hasColourByLabel()) + { + gcol.setColourByLabel(newcol.getColourByLabel()); + } + if (newcol.hasThreshold()) + { + gcol.setThresh(newcol.getThreshold()); + gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); // default + } + if (newcol.getThreshType().length()>0) + { + String ttyp = newcol.getThreshType(); + if (ttyp.equalsIgnoreCase("NONE")) { + gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); + } + if (ttyp.equalsIgnoreCase("ABOVE")) + { + gcol.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD); + } + if (ttyp.equalsIgnoreCase("BELOW")){ + gcol.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD); + } + } + fr.setColour(name = newcol.getName(), gcol); + } else { + fr.setColour(name = jucs.getColour(i).getName(), new Color( Integer.parseInt(jucs.getColour(i).getRGB(), 16))); + } fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount()); } if (table != null) @@ -648,7 +696,7 @@ public class FeatureSettings extends JPanel if (value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours(); + jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours(); ucs.setSchemeName("Sequence Features"); try { @@ -667,12 +715,38 @@ public class FeatureSettings extends JPanel } jalview.util.QuickSort.sort(sortOrder, sortTypes); sortOrder = null; + Object fcol; + GraduatedColor gcol; for (i = 0; i < sortTypes.length; i++) { - jalview.binding.Colour col = new jalview.binding.Colour(); + jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour(); col.setName(sortTypes[i]); col.setRGB(jalview.util.Format.getHexString(fr.getColour(col .getName()))); + fcol = fr.getFeatureStyle(sortTypes[i]); + if (fcol instanceof GraduatedColor) + { + gcol = (GraduatedColor) fcol; + col.setMin(gcol.getMin()); + col.setMax(gcol.getMax()); + col.setMinRGB(jalview.util.Format.getHexString(gcol + .getMinColor())); + col.setAutoScale(gcol.isAutoScale()); + col.setThreshold(gcol.getThresh()); + col.setColourByLabel(gcol.isColourByLabel()); + switch (gcol.getThreshType()) + { + case AnnotationColourGradient.NO_THRESHOLD: + col.setThreshType("NONE"); + break; + case AnnotationColourGradient.ABOVE_THRESHOLD: + col.setThreshType("ABOVE"); + break; + case AnnotationColourGradient.BELOW_THRESHOLD: + col.setThreshType("BELOW"); + break; + } + } ucs.addColour(col); } ucs.marshal(out);