+ /**
+ * Copy the contents of a file to a new file added to the output jar
+ *
+ * @param jout
+ * @param infilePath
+ * @param jarfileName
+ */
+ protected void copyFileToJar(JarOutputStream jout, String infilePath,
+ String jarfileName)
+ {
+ DataInputStream dis = null;
+ try
+ {
+ File file = new File(infilePath);
+ if (file.exists() && jout != null)
+ {
+ dis = new DataInputStream(new FileInputStream(file));
+ byte[] data = new byte[(int) file.length()];
+ dis.readFully(data);
+ writeJarEntry(jout, jarfileName, data);
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } finally
+ {
+ if (dis != null)
+ {
+ try
+ {
+ dis.close();
+ } catch (IOException e)
+ {
+ // ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Write the data to a new entry of given name in the output jar file
+ *
+ * @param jout
+ * @param jarfileName
+ * @param data
+ * @throws IOException
+ */
+ protected void writeJarEntry(JarOutputStream jout, String jarfileName,
+ byte[] data) throws IOException
+ {
+ if (jout != null)
+ {
+ jout.putNextEntry(new JarEntry(jarfileName));
+ DataOutputStream dout = new DataOutputStream(jout);
+ dout.write(data, 0, data.length);
+ dout.flush();
+ jout.closeEntry();
+ }
+ }
+
+ /**
+ * Save the state of a structure viewer
+ *
+ * @param ap
+ * @param jds
+ * @param pdb
+ * the archive XML element under which to save the state
+ * @param entry
+ * @param viewIds
+ * @param matchedFile
+ * @param viewFrame
+ * @return
+ */
+ protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+ Pdbids pdb, PDBEntry entry, List<String> viewIds,
+ String matchedFile, StructureViewerBase viewFrame)
+ {
+ final AAStructureBindingModel bindingModel = viewFrame.getBinding();
+
+ /*
+ * Look for any bindings for this viewer to the PDB file of interest
+ * (including part matches excluding chain id)
+ */
+ for (int peid = 0; peid < bindingModel.getPdbCount(); peid++)
+ {
+ final PDBEntry pdbentry = bindingModel.getPdbEntry(peid);
+ final String pdbId = pdbentry.getId();
+ if (!pdbId.equals(entry.getId())
+ && !(entry.getId().length() > 4 && entry.getId()
+ .toLowerCase().startsWith(pdbId.toLowerCase())))
+ {
+ /*
+ * not interested in a binding to a different PDB entry here
+ */
+ continue;
+ }
+ if (matchedFile == null)
+ {
+ matchedFile = pdbentry.getFile();
+ }
+ else if (!matchedFile.equals(pdbentry.getFile()))
+ {
+ Cache.log
+ .warn("Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): "
+ + pdbentry.getFile());
+ }
+ // record the
+ // file so we
+ // can get at it if the ID
+ // match is ambiguous (e.g.
+ // 1QIP==1qipA)
+
+ for (int smap = 0; smap < viewFrame.getBinding().getSequence()[peid].length; smap++)
+ {
+ // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1)
+ if (jds == viewFrame.getBinding().getSequence()[peid][smap])
+ {
+ StructureState state = new StructureState();
+ state.setVisible(true);
+ state.setXpos(viewFrame.getX());
+ state.setYpos(viewFrame.getY());
+ state.setWidth(viewFrame.getWidth());
+ state.setHeight(viewFrame.getHeight());
+ final String viewId = viewFrame.getViewId();
+ state.setViewId(viewId);
+ state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
+ state.setColourwithAlignPanel(viewFrame.isUsedforcolourby(ap));
+ state.setColourByJmol(viewFrame.isColouredByViewer());
+ // FIXME add attribute to schema and enable next line
+ // state.setType(viewFrame.getViewerType().toString());
+ state.setContent(viewFrame.getViewerType().toString());
+ pdb.addStructureState(state);
+ }
+ }
+ }
+ return matchedFile;
+ }
+
+ private AnnotationColours constructAnnotationColours(
+ AnnotationColourGradient acg, List<UserColourScheme> userColours,
+ JalviewModelSequence jms)
+ {
+ AnnotationColours ac = new AnnotationColours();
+ ac.setAboveThreshold(acg.getAboveThreshold());
+ ac.setThreshold(acg.getAnnotationThreshold());
+ ac.setAnnotation(acg.getAnnotation());
+ if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
+ {
+ ac.setColourScheme(setUserColourScheme(acg.getBaseColour(),
+ userColours, jms));
+ }
+ else
+ {
+ ac.setColourScheme(ColourSchemeProperty.getColourName(acg
+ .getBaseColour()));
+ }
+
+ ac.setMaxColour(acg.getMaxColour().getRGB());
+ ac.setMinColour(acg.getMinColour().getRGB());
+ ac.setPerSequence(acg.isSeqAssociated());
+ ac.setPredefinedColours(acg.isPredefinedColours());
+ return ac;
+ }
+
+ private void storeAlignmentAnnotation(AlignmentAnnotation[] aa,
+ IdentityHashMap groupRefs, AlignmentViewport av,
+ Set<String> calcIdSet, boolean storeDS, SequenceSet vamsasSet)