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;
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;
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;
/////
// 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;
/////
// Apply the temporary colourscheme to the linked alignment
// TODO: enhance for multiple linked alignments.
-
+
String imageColour = avm.getValueFromSubValOrArg(
structureImageArgValue, Arg.IMAGECOLOUR,
structureImageSubVals);
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;
}
}
.getJalviewStructureDisplay();
File sessionToRestore = null;
-
- List<StructureCommandI> extraCommands=new ArrayList<>();
-
- if (extraCommands.size() > 0 || bgcolour!=null)
+
+ List<StructureCommandI> 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)
{
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);