cmd = commandGenerator
+ .colourByResidues(colours);
+ executeCommands(cmd, false, COLOURING_STRUCTURES);
+ }
+
+ public void setBackgroundColour(Color col)
+ {
+ StructureCommandI cmd = commandGenerator.setBackgroundColour(col);
+ executeCommand(cmd, false, null);
+ }
+
+ /**
+ * Sends one command to the structure viewer. If {@code getReply} is true, the
+ * command is sent synchronously, otherwise in a deferred thread.
+ *
+ * If a progress message is supplied, this is displayed before command
+ * execution, and removed afterwards.
+ *
+ * @param cmd
+ * @param getReply
+ * @param msg
+ * @return
+ */
+ private List executeCommand(StructureCommandI cmd,
+ boolean getReply, String msg)
+ {
+ final JalviewStructureDisplayI theViewer = getViewer();
+ final long handle = msg == null ? 0 : theViewer.startProgressBar(msg);
+ if (getReply)
+ {
+ /*
+ * synchronous (same thread) execution so reply can be returned
+ */
+ try
+ {
+ return executeCommand(cmd, true);
+ } finally
+ {
+ if (msg != null)
+ {
+ theViewer.stopProgressBar(null, handle);
+ }
+ }
+ }
+ else
+ {
+ /*
+ * asynchronous (new thread) execution if no reply needed
+ */
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ executeCommand(cmd, false);
+ } finally
+ {
+ if (msg != null)
+ {
+ theViewer.stopProgressBar(null, handle);
+ }
+ }
+ }
+ });
+ return null;
+ }
+ }
+
+ /**
+ * Execute one structure viewer command. If {@code getReply} is true, may
+ * optionally return one or more reply messages, else returns null.
+ *
+ * @param cmd
+ * @param getReply
+ */
+ protected abstract List executeCommand(StructureCommandI cmd,
+ boolean getReply);
+
+ /**
+ * Executes one or more structure viewer commands
+ *
+ * @param commands
+ * @param getReply
+ * @param msg
+ */
+ protected List executeCommands(List commands,
+ boolean getReply, String msg)
+ {
+ List response = getReply ? new ArrayList<>() : null;
+ for (StructureCommandI cmd : commands)
+ {
+ List replies = executeCommand(cmd, getReply, msg);
+ if (replies != null)
+ {
+ response.addAll(replies);
+ }
+ }
+ return response;
+ }
+
+ /**
+ * Colours any structures associated with sequences in the given alignment as
+ * coloured in the alignment view, provided colourBySequence is enabled
+ */
+ public void colourBySequence(AlignmentViewPanel alignmentv)
+ {
+ if (!colourBySequence || !isLoadingFinished() || getSsm() == null)
+ {
+ return;
+ }
+ Map