From: Ben Soares Date: Thu, 21 Sep 2023 08:57:22 +0000 (+0100) Subject: JAL-4265 Use ColourUtils.parseColourString() for consistency with the rest of Jalview... X-Git-Tag: Release_2_11_4_0~174^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=809c044d96563eea97b00f2c55d2065480f6cac8;p=jalview.git JAL-4265 Use ColourUtils.parseColourString() for consistency with the rest of Jalview (and it's better). Change documentation to match new hexstring format --- diff --git a/help/help/html/features/clarguments-basic.html b/help/help/html/features/clarguments-basic.html index f9fef90..c82cb20 100644 --- a/help/help/html/features/clarguments-basic.html +++ b/help/help/html/features/clarguments-basic.html @@ -540,7 +540,7 @@

‑‑bgcolour

- Only applies to ‑‑structureimage. Specify a background colour for a structure image. The colour can be specified as a named colour recognised by Java (e.g. "white", "cyan") or as a #RRGGBB hash-6-digit-hex-string as used in web pages (e.g. "#ffffff", "#00ffff"). Note that if you're using a hash in a bash-like shell then you should quote the string to avoid problems with it being interpreted as a comment character. + Only applies to ‑‑structureimage. Specify a background colour for a structure image. The colour can be specified as a named colour recognised by Java (e.g. "white", "cyan") or as a RRGGBB 6 digit hex string (e.g. ffffff, 00ffff).

E.g. diff --git a/help/help/html/features/clarguments-reference.html b/help/help/html/features/clarguments-reference.html index 62ef374..b2e29e9 100644 --- a/help/help/html/features/clarguments-reference.html +++ b/help/help/html/features/clarguments-reference.html @@ -713,7 +713,7 @@ Automatically create directories when outputting a file to a new directory ‑‑bgcolour name - Only applies to structure images (opened with jmol structure viewer). Sets the background colour of the preceding ‑‑structureimage. name should be either a named colour (e.g. white, cyan) known to Jmol, or can be given as a six digit RGB hex string preceded by a hash (#) character (e.g. #ffffff, 00ffff). Note that you made need to quote a hashed RGB hex string. This can also be set as a sub-value modifier to the ‑‑structureimage value. + Only applies to structure images (opened with jmol structure viewer). Sets the background colour of the preceding ‑‑structureimage. name should be either a named colour (e.g. white, cyan) known to Jmol, or can be given as a six digit RGB hex string (e.g. ffffff, 00ffff). This can also be set as a sub-value modifier to the ‑‑structureimage value. ✓ diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index faa5e43..1d65fc6 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -3,7 +3,6 @@ package jalview.bin; import java.awt.Color; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; @@ -25,8 +24,6 @@ import jalview.bin.argparser.SubVals; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder; -import jalview.ext.jmol.JalviewJmolBinding; -import jalview.ext.jmol.JmolCommands; import jalview.gui.AlignFrame; import jalview.gui.AlignmentPanel; import jalview.gui.AppJmol; @@ -51,7 +48,6 @@ import jalview.io.exceptions.ImageOutputException; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.structure.StructureCommandI; -import jalview.structure.StructureCommandsI; import jalview.structure.StructureImportSettings.TFType; import jalview.structure.StructureSelectionManager; import jalview.util.ColorUtils; @@ -686,7 +682,8 @@ public class Commands ///// // DON'T TRY TO EXPORT IF VIEWER IS UNSUPPORTED - if (viewerType!=ViewerType.JMOL) { + if (viewerType != ViewerType.JMOL) + { addWarn("Cannot export image for structure viewer " + viewerType.name() + " yet"); continue; @@ -695,7 +692,7 @@ public class Commands ///// // Apply the temporary colourscheme to the linked alignment // TODO: enhance for multiple linked alignments. - + String imageColour = avm.getValueFromSubValOrArg( structureImageArgValue, Arg.IMAGECOLOUR, structureImageSubVals); @@ -712,27 +709,12 @@ public class Commands Color bgcolour = null; if (bgcolourstring != null && bgcolourstring.length() > 0) { - try - { - // - // FIXME: Why not use ColorUtils.parseColourString(bgcolourstring) - this is consistent and backwards compatible - // - if (bgcolourstring.charAt(0) == '#') - { - bgcolour = Color.decode(bgcolourstring); - } - else - { - Field field = Color.class.getField(bgcolourstring); - bgcolour = (Color) field.get(null); - } - } catch (IllegalArgumentException | NoSuchFieldException - | SecurityException | IllegalAccessException nfe) + bgcolour = ColorUtils.parseColourString(bgcolourstring); + if (bgcolour == null) { Console.warn( "Background colour string '" + bgcolourstring + "' not recognised -- using default"); - //bgcolour = Color.black; } } @@ -740,49 +722,56 @@ public class Commands .getJalviewStructureDisplay(); File sessionToRestore = null; - - List extraCommands=new ArrayList<>(); - - if (extraCommands.size() > 0 || bgcolour!=null) + + List extraCommands = new ArrayList<>(); + + if (extraCommands.size() > 0 || bgcolour != null) { - try { + try + { sessionToRestore = sview.saveSession(); } catch (Throwable t) { - Console.warn("Unable to save temporary session file before custom structure view export operation."); + Console.warn( + "Unable to save temporary session file before custom structure view export operation."); } } - + //// - // Do temporary ops + // Do temporary ops + + if (bgcolour != null) + { + sview.getBinding().setBackgroundColour(bgcolour); + } + + sview.getBinding().executeCommands(extraCommands, false, + "Executing Custom Commands"); - sview.getBinding().setBackgroundColour(bgcolour); - - sview.getBinding().executeCommands(extraCommands, false, "Executing Custom Commands"); - // and export the view as an image boolean success = this.checksBeforeWritingToFile(avm, subVals, false, structureImageFilename, "structure image", isError); - + if (!success) { continue; } - Console.debug( - "Rendering image to " + structureImageFile); - // - // TODO - extend StructureViewer / Binding with makePDBImage so we can do this with every viewer - // - - try { + Console.debug("Rendering image to " + structureImageFile); + // + // TODO - extend StructureViewer / Binding with makePDBImage so + // we can do this with every viewer + // + + try + { // We don't expect class cast exception AppJmol jmol = (AppJmol) sview; - jmol.makePDBImage(structureImageFile, imageType, - renderer, userBis); + jmol.makePDBImage(structureImageFile, imageType, renderer, + userBis); Console.debug("Finished Rendering image to " + structureImageFile); - + // RESTORE SESSION AFTER EXPORT IF NEED BE if (sessionToRestore != null) { @@ -792,14 +781,13 @@ public class Commands sview.getBinding().restoreSession(sessionToRestore.getAbsolutePath()); } - } catch (ImageOutputException ioexc) + } catch (ImageOutputException ioexec) { - addError("Unexpected error whilst exporting image to " - + structureImageFile, ioexc); + addError( + "Unexpected error when restoring structure viewer session after custom view operations."); isError = true; continue; - } - finally + } finally { try { this.colourAlignFrame(af, originalColourScheme);