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;
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.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.FileUtils;
commandArgsProvided = true;
for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
{
+ argParser.setStructureFilename(null);
String val = av.getValue();
SubVals subVals = av.getSubVals();
int argIndex = av.getArgIndex();
.getColourScheme(af);
this.colourAlignFrame(af, imageColour);
- List<String> extraCommands = new ArrayList<>();
- // these don't actually do anything to the output image since we
- // renderScreenImage
- // extraCommands.add("set antialiasImages on");
- // extraCommands.add("set antialiasTranslucent on");
+ List<StructureCommandI> extraCommands = new ArrayList<>();
+ StructureCommandsI sc;
+ switch (viewerType)
+ {
+ case JMOL:
+ sc = new JmolCommands();
+ break;
+ default:
+ addWarn("Cannot export image for structure viewer "
+ + viewerType.name() + " yet");
+ continue;
+ }
- String bgcolour = avm.getValueFromSubValOrArg(
+ String bgcolourstring = avm.getValueFromSubValOrArg(
structureImageArgValue, Arg.BGCOLOUR,
structureImageSubVals);
- if (bgcolour != null && bgcolour.length() > 0)
+ Color bgcolour = null;
+ if (bgcolourstring != null && bgcolourstring.length() > 0)
{
- if (bgcolour.charAt(0) == '#')
+ try
{
- bgcolour = "[x" + bgcolour.substring(1) + "]";
+ 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)
+ {
+ Console.warn(
+ "Background colour string '" + bgcolourstring
+ + "' not recognised -- using black.");
+ bgcolour = Color.black;
}
- extraCommands.add("background " + bgcolour);
+ extraCommands.add(sc.setBackgroundColour(bgcolour));
}
// TODO MAKE THIS VIEWER INDEPENDENT!!
- switch (StructureViewer.getViewerType())
+ switch (viewerType)
{
case JMOL:
JalviewStructureDisplayI sview = structureViewer
.getJalviewStructureDisplay();
+ JmolCommands jc = (JmolCommands) sc;
if (sview instanceof AppJmol)
{
AppJmol jmol = (AppJmol) sview;
+ JalviewJmolBinding jmb = (JalviewJmolBinding) jmol
+ .getBinding();
+ String state = new StringBuilder()
+ .append("JalviewCommandsStructureState_")
+ .append(viewerType.name()).toString();
+ jmb.executeCommand(jc.saveState(state), false);
+ for (StructureCommandI scmd : extraCommands)
+ {
+ jmb.executeCommand(scmd, false);
+ }
try
{
boolean success = this.checksBeforeWritingToFile(avm,
Console.debug(
"Rendering image to " + structureImageFile);
jmol.makePDBImage(structureImageFile, imageType,
- renderer, userBis, extraCommands);
+ renderer, userBis);
Console.debug("Finished Rendering image to "
+ structureImageFile);
+ structureImageFile, ioexc);
isError = true;
continue;
+ } finally
+ {
+ jmb.executeCommand(jc.restoreState(state), false);
}
}
break;
default:
+ // this shouldn't happen!
addWarn("Cannot export image for structure viewer "
- + structureViewer.getViewerType() + " yet");
+ + viewerType.name() + " yet");
continue;
}
this.colourAlignFrame(af, originalColourScheme);
}
}
}
+ argParser.setStructureFilename(null);
}
}
}
try
{
makePDBImage(null, type, null,
- BitmapImageSizing.defaultBitmapImageSizing(), null);
+ BitmapImageSizing.defaultBitmapImageSizing());
} catch (ImageOutputException ioex)
{
Console.error("Unexpected error whilst writing " + type.toString(),
}
public void makePDBImage(File file, ImageMaker.TYPE type, String renderer,
- BitmapImageSizing userBis, List<String> extraCommands)
- throws ImageOutputException
+ BitmapImageSizing userBis) throws ImageOutputException
{
int width = getWidth();
int height = getHeight();
}
}
- String saveStateNameTemp = "JalviewSaveStateTemp";
- jmb.executeCommand(
- new StructureCommand("save STATE " + saveStateNameTemp),
- false);
-
- if (extraCommands != null)
- {
- for (String cmd : extraCommands)
- {
- jmb.executeCommand(new StructureCommand(cmd), false);
- }
- }
-
jmb.jmolViewer.requestRepaintAndWait("image export");
jmb.jmolViewer.renderScreenImage(ig2, usewidth, useheight);
- jmb.executeCommand(
- new StructureCommand("restore STATE " + saveStateNameTemp),
- false);
}
};
String view = MessageManager.getString("action.view")