X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAppJmol.java;h=7179a188e5657cd3bc0273a6fe19f09394f6ecbd;hb=4c132b37c867a60959dae032addd78892d996345;hp=af25653a997b35c4bf080e0a4c0dcb8cb3297e8e;hpb=2783208dc83a836be2cac47efb9877949909e781;p=jalview.git diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index af25653..7179a18 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -24,9 +24,11 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.gui.ImageExporter.ImageWriterI; import jalview.gui.StructureViewer.ViewerType; import jalview.structures.models.AAStructureBindingModel; import jalview.util.BrowserLauncher; +import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.dbsources.Pdb; @@ -44,7 +46,6 @@ import java.util.List; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.SwingUtilities; @@ -58,7 +59,7 @@ public class AppJmol extends StructureViewerBase private static final String SPACE = " "; - private static final String BACKSLASH = "\""; + private static final String QUOTE = "\""; AppJmolBinding jmb; @@ -162,8 +163,9 @@ public class AppJmol extends StructureViewerBase { return progressBar; } + /** - * add a single PDB structure to a new or existing Jmol view + * display a single PDB structure in a new Jmol view * * @param pdbentry * @param seq @@ -174,33 +176,14 @@ public class AppJmol extends StructureViewerBase final AlignmentPanel ap) { progressBar = ap.alignFrame; - String pdbId = pdbentry.getId(); - /* - * If the PDB file is already loaded, the user may just choose to add to an - * existing viewer (or cancel) - */ - if (addAlreadyLoadedFile(seq, chains, ap, pdbId)) - { - return; - } - - /* - * Check if there are other Jmol views involving this alignment and prompt - * user about adding this molecule to one of them - */ - if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId)) - { - return; - } - - /* - * If the options above are declined or do not apply, open a new viewer - */ - openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }); + openNewJmol(ap, alignAddedStructures, new PDBEntry[] { pdbentry }, + new SequenceI[][] + { seq }); } - private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, + private void openNewJmol(AlignmentPanel ap, boolean alignAdded, + PDBEntry[] pdbentrys, SequenceI[][] seqs) { progressBar = ap.alignFrame; @@ -209,11 +192,9 @@ public class AppJmol extends StructureViewerBase addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); - if (pdbentrys.length > 1) - { - alignAddedStructures = true; - useAlignmentPanelForSuperposition(ap); - } + alignAddedStructures = alignAdded; + useAlignmentPanelForSuperposition(ap); + jmb.setColourBySequence(true); setSize(400, 400); // probably should be a configurable/dynamic default here initMenus(); @@ -234,16 +215,19 @@ public class AppJmol extends StructureViewerBase } /** - * create a new Jmol containing several structures superimposed using the - * given alignPanel. + * create a new Jmol containing several structures optionally superimposed + * using the given alignPanel. * * @param ap + * @param alignAdded + * - true to superimpose * @param pe * @param seqs */ - public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs) + public AppJmol(AlignmentPanel ap, boolean alignAdded, PDBEntry[] pe, + SequenceI[][] seqs) { - openNewJmol(ap, pe, seqs); + openNewJmol(ap, alignAdded, pe, seqs); } @@ -277,8 +261,6 @@ public class AppJmol extends StructureViewerBase jmb.setFinishedInit(true); } - boolean allChainsSelected = false; - @Override void showSelectedChains() { @@ -345,8 +327,8 @@ public class AppJmol extends StructureViewerBase StringBuilder fileList = new StringBuilder(); for (String s : files) { - fileList.append(SPACE).append(BACKSLASH) - .append(Platform.escapeString(s)).append(BACKSLASH); + fileList.append(SPACE).append(QUOTE) + .append(Platform.escapeString(s)).append(QUOTE); } String filesString = fileList.toString(); @@ -362,6 +344,8 @@ public class AppJmol extends StructureViewerBase } catch (Exception ex) { Cache.log.error("Couldn't open Jmol viewer!", ex); + ex.printStackTrace(); + return; } } else @@ -381,9 +365,12 @@ public class AppJmol extends StructureViewerBase new OOMWarning("When trying to add structures to the Jmol viewer!", oomerror); Cache.log.debug("File locations are " + filesString); + return; } catch (Exception ex) { Cache.log.error("Couldn't add files to Jmol viewer!", ex); + ex.printStackTrace(); + return; } } @@ -421,7 +408,7 @@ public class AppJmol extends StructureViewerBase jmb.updateColours(ap); } // do superposition if asked to - if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + if (alignAddedStructures) { alignAddedStructures(); } @@ -455,7 +442,7 @@ public class AppJmol extends StructureViewerBase } } }); - alignAddedStructures = false; + } /** @@ -484,6 +471,7 @@ public class AppJmol extends StructureViewerBase String file = jmb.getPdbEntry(pi).getFile(); if (file == null) { + // todo: extract block as method and pull up (also ChimeraViewFrame) // retrieve the pdb and store it locally AlignmentI pdbseq = null; pdbid = jmb.getPdbEntry(pi).getId(); @@ -568,50 +556,29 @@ public class AppJmol extends StructureViewerBase return files; } - @Override - public void eps_actionPerformed(ActionEvent e) - { - makePDBImage(jalview.util.ImageMaker.TYPE.EPS); - } - - @Override - public void png_actionPerformed(ActionEvent e) - { - makePDBImage(jalview.util.ImageMaker.TYPE.PNG); - } - - void makePDBImage(jalview.util.ImageMaker.TYPE type) + /** + * Outputs the Jmol viewer image as an image file, after prompting the user to + * choose a file and (for EPS) choice of Text or Lineart character rendering + * (unless a preference for this is set) + * + * @param type + */ + public void makePDBImage(ImageMaker.TYPE type) { int width = getWidth(); int height = getHeight(); - - jalview.util.ImageMaker im; - - if (type == jalview.util.ImageMaker.TYPE.PNG) - { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view", - width, height, null, null, null, 0, false); - } - else if (type == jalview.util.ImageMaker.TYPE.EPS) + ImageWriterI writer = new ImageWriterI() { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view", - width, height, null, this.getTitle(), null, 0, false); - } - else - { - - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA", - width, height, null, this.getTitle(), null, 0, false); - } - - if (im.getGraphics() != null) - { - jmb.viewer.renderScreenImage(im.getGraphics(), width, height); - im.writeImage(); - } + @Override + public void exportImage(Graphics g) throws Exception + { + jmb.viewer.renderScreenImage(g, width, height); + } + }; + String view = MessageManager.getString("action.view").toLowerCase(); + ImageExporter exporter = new ImageExporter(writer, + jmb.getIProgressIndicator(), type, getTitle()); + exporter.doExport(null, this, width, height, view); } @Override @@ -619,8 +586,8 @@ public class AppJmol extends StructureViewerBase { try { - BrowserLauncher - .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/"); + BrowserLauncher // BH 2018 + .openURL("http://wiki.jmol.org");//http://jmol.sourceforge.net/docs/JmolUserGuide/"); } catch (Exception ex) { }