From: amwaterhouse Date: Tue, 6 Dec 2005 12:03:46 +0000 (+0000) Subject: After merge X-Git-Tag: Release_2_07~51 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9c5d69ef1e102b1eac18ec13c362522f40c9000d;p=jalview.git After merge --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d6be387..8c31ed0 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -34,6 +34,7 @@ import jalview.io.*; import jalview.jbgui.*; import jalview.schemes.*; import jalview.ws.*; +import javax.swing.event.AncestorEvent; /** * DOCUMENT ME! @@ -42,15 +43,18 @@ import jalview.ws.*; * @version $Revision$ */ public class AlignFrame - extends GAlignFrame + extends GAlignFrame implements ClipboardOwner { /** DOCUMENT ME!! */ public static final int NEW_WINDOW_WIDTH = 700; /** DOCUMENT ME!! */ public static final int NEW_WINDOW_HEIGHT = 500; - final AlignmentPanel alignPanel; - final AlignViewport viewport; + AlignmentPanel alignPanel; + AlignViewport viewport; + + Vector viewports = new Vector(); + Vector alignPanels = new Vector(); /** DOCUMENT ME!! */ public String currentFileFormat = null; @@ -58,6 +62,7 @@ public class AlignFrame Stack redoList = new Stack(); private int treeCount = 0; + /** * Creates a new AlignFrame object. * @@ -66,10 +71,12 @@ public class AlignFrame public AlignFrame(AlignmentI al) { viewport = new AlignViewport(al); + viewports.add(viewport); + if(viewport.vconsensus==null) { - //Out of memory caluclating consensus. + //Out of memory calculating consensus. BLOSUM62Colour.setEnabled(false); PIDColour.setEnabled(false); conservationMenuItem.setEnabled(false); @@ -79,12 +86,7 @@ public class AlignFrame } alignPanel = new AlignmentPanel(this, viewport); - alignPanel.annotationPanel.adjustPanelHeight(); - alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel. - annotationPanel.getPreferredSize()); - alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel. - getPreferredSize()); - alignPanel.setAnnotationVisible(viewport.getShowAnnotation()); + alignPanels.add(alignPanel); String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort"); @@ -93,7 +95,26 @@ public class AlignFrame else if(sortby.equals("Pairwise Identity")) sortPairwiseMenuItem_actionPerformed(null); - getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); + // remove(tabbedPane); + getContentPane().add(alignPanel, BorderLayout.CENTER); + + + + // tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel); + + ///Dataset tab + ///////////////////////// + if(al.getDataset()==null) + { + al.setDataset(null); + } + // AlignViewport ds = new AlignViewport(al.getDataset(), true); + // AlignmentPanel dap = new AlignmentPanel(this, ds); + // tabbedPane.add("Dataset", dap); + // viewports.add(ds); + // alignPanels.add(dap); + ///////////////////////// + viewport.addPropertyChangeListener(new PropertyChangeListener() { @@ -106,8 +127,12 @@ public class AlignFrame } }); - if(Desktop.desktop!=null) + + if (Desktop.desktop != null) + { addServiceListeners(); + setGUINucleotide(al.isNucleotide()); + } } /* Set up intrinsic listeners for dynamically generated GUI bits. */ @@ -144,6 +169,36 @@ public class AlignFrame } + public void setGUINucleotide(boolean nucleotide) + { + showTranslation.setVisible( nucleotide ); + sequenceFeatures.setVisible(!nucleotide ); + featureSettings.setVisible( !nucleotide ); + conservationMenuItem.setVisible( !nucleotide ); + modifyConservation.setVisible( !nucleotide ); + + //Deal with separators + //Remember AlignFrame always starts as protein + if(nucleotide) + { + viewMenu.remove(viewMenu.getItemCount()-2); + } + else + { + calculateMenu.remove(calculateMenu.getItemCount()-2); + } + } + + + /* + Added so Castor Mapping file can obtain Jalview Version + */ + public String getVersion() + { + return jalview.bin.Cache.getProperty("VERSION"); + } + + /** * DOCUMENT ME! * @@ -156,24 +211,28 @@ public class AlignFrame { BufferedReader in = new BufferedReader(new FileReader(file)); SequenceI seq = null; - String line, text, token; - UserColourScheme ucs; + String line, type, desc, token; + int index, start, end; StringTokenizer st; - SequenceGroup sg; + SequenceFeature sf; + FeatureRenderer fr = alignPanel.seqPanel.seqCanvas.getFeatureRenderer(); + int lineNo = 0; while ( (line = in.readLine()) != null) { + lineNo++; st = new StringTokenizer(line, "\t"); - if (st.countTokens() != 6) + if (st.countTokens() == 2) { - System.out.println("Groups file " + file + - " is invalid. Read help file."); - System.exit(1); + type = st.nextToken(); + UserColourScheme ucs = new UserColourScheme(st.nextToken()); + fr.setColour(type, ucs.findColour("A")); + continue; } while (st.hasMoreElements()) { - text = st.nextToken(); + desc = st.nextToken(); token = st.nextToken(); if (!token.equals("ID_NOT_SPECIFIED")) { @@ -188,19 +247,38 @@ public class AlignFrame start = Integer.parseInt(st.nextToken()); end = Integer.parseInt(st.nextToken()); - ucs = new UserColourScheme(st.nextToken()); seq = viewport.alignment.getSequenceAt(index); start = seq.findIndex(start) - 1; end = seq.findIndex(end) - 1; - sg = new SequenceGroup(text, ucs, true, true, false, start, end); - sg.addSequence(seq, true); + type = st.nextToken(); + + if (fr.getColour(type) == null) + { + // Probably the old style groups file + UserColourScheme ucs = new UserColourScheme(type); + fr.setColour(type, ucs.findColour("A")); + } + + + sf = new SequenceFeature(type, desc, "", start, end); + + seq.addSequenceFeature(sf); + + + // sg = new SequenceGroup(text, ucs, true, true, false, start, end); + // sg.addSequence(seq, false); + + // viewport.alignment.addGroup(sg); - viewport.alignment.addGroup(sg); } } + viewport.showSequenceFeatures = true; + + alignPanel.repaint(); + } catch (Exception ex) { @@ -208,6 +286,12 @@ public class AlignFrame } } + public void fetchSequence_actionPerformed(ActionEvent e) + { + new SequenceFetcher(this); + } + + /** * DOCUMENT ME! * @@ -326,7 +410,9 @@ public class AlignFrame */ protected void htmlMenuItem_actionPerformed(ActionEvent e) { - new HTMLOutput(viewport); + new HTMLOutput(viewport, + alignPanel.seqPanel.seqCanvas.getSequenceRenderer(), + alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); } public void createImageMap(File file, String image) @@ -561,6 +647,12 @@ public class AlignFrame alignPanel.repaint(); } + public void lostOwnership(Clipboard clipboard, Transferable contents) + { + Desktop.jalviewClipboard = null; + } + + /** * DOCUMENT ME! * @@ -570,7 +662,6 @@ public class AlignFrame { if (viewport.getSelectionGroup() == null) { - System.out.println("null here"); return; } @@ -579,7 +670,7 @@ public class AlignFrame Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); Hashtable orderedSeqs = new Hashtable(); - SequenceI [] seqs = new SequenceI[sg.getSize()]; + SequenceI[] seqs = new SequenceI[sg.getSize()]; for (int i = 0; i < sg.getSize(); i++) { @@ -610,7 +701,6 @@ public class AlignFrame } } - //FIND START RES //Returns residue following index if gap startRes = seq.findPosition(sg.getStartRes()); @@ -634,12 +724,20 @@ public class AlignFrame } seqs[i] = new Sequence(seq.getName(), - seq.getSequence(sg.getStartRes(), sg.getEndRes()+1), + seq.getSequence(sg.getStartRes(), sg.getEndRes() + 1), startRes, endRes); + seqs[i].setDescription(seq.getDescription()); + seqs[i].setDBRef(seq.getDBRef()); + seqs[i].setSequenceFeatures(seq.getSequenceFeatures()); + seqs[i].setDatasetSequence(seq.getDatasetSequence()); + } - c.setContents(new StringSelection(FastaFile.print(seqs)), null); + FastaFile ff = new FastaFile(); + ff.addJVSuffix( viewport.showJVSuffix ); + c.setContents(new StringSelection( ff.print(seqs)), this); + Desktop.jalviewClipboard = new Object[]{seqs, viewport.alignment.getDataset()}; } /** @@ -682,14 +780,35 @@ public class AlignFrame } String str = (String) contents.getTransferData(DataFlavor.stringFlavor); + if(str.length()<1) + return; String format = IdentifyFile.Identify(str, "Paste"); - SequenceI[] sequences = new FormatAdapter().readFile(str, "Paste", format); + SequenceI[] sequences; + if(Desktop.jalviewClipboard!=null) + { + // The clipboard was filled from within Jalview, we must use the sequences + // And dataset from the copied alignment + sequences = (SequenceI[])Desktop.jalviewClipboard[0]; + } + else + { + sequences = new FormatAdapter().readFile(str, "Paste", format); + } if (newAlignment) { - AlignFrame af = new AlignFrame(new Alignment(sequences)); + + Alignment alignment = new Alignment(sequences); + + if(Desktop.jalviewClipboard!=null) + alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] ); + else + alignment.setDataset( null ); + + + AlignFrame af = new AlignFrame(alignment); String newtitle = new String("Copied sequences"); if (title.startsWith("Copied sequences")) @@ -708,8 +827,25 @@ public class AlignFrame { //!newAlignment for (int i = 0; i < sequences.length; i++) - viewport.alignment.addSequence(sequences[i]); + { + Sequence newseq = new Sequence(sequences[i].getName(), + sequences[i].getSequence(), sequences[i].getStart(), + sequences[i].getEnd()); + viewport.alignment.addSequence(newseq); + if(sequences[i].getDatasetSequence()==null) + { + //////////////////////////// + //Datset needs extension; + ///////////////////////////// + Sequence ds = new Sequence(sequences[i].getName(), + AlignSeq.extractGaps("-. ", sequences[i].getSequence()), + sequences[i].getStart(), + sequences[i].getEnd()); + newseq.setDatasetSequence(ds); + viewport.alignment.getDataset().addSequence(ds); + } + } viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); @@ -842,6 +978,7 @@ public class AlignFrame viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); + alignPanel.seqPanel.seqCanvas.highlightSearchResults(null); alignPanel.annotationPanel.activeRes = null; PaintRefresher.Refresh(null, viewport.alignment); } @@ -1167,14 +1304,15 @@ public class AlignFrame * * @param e DOCUMENT ME! */ - protected void fullSeqId_actionPerformed(ActionEvent e) + protected void seqLimit_actionPerformed(ActionEvent e) { - viewport.setShowFullId(fullSeqId.isSelected()); + viewport.setShowJVSuffix(seqLimits.isSelected()); alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth()); alignPanel.repaint(); } + /** * DOCUMENT ME! * @@ -1276,15 +1414,15 @@ public class AlignFrame { viewport.showSequenceFeatures(sequenceFeatures.isSelected()); - if (viewport.showSequenceFeatures && - ! ( (Alignment) viewport.alignment).featuresAdded) + if (viewport.showSequenceFeatures) { new SequenceFeatureFetcher(viewport. - alignment, + alignment, alignPanel); - ( (Alignment) viewport.alignment).featuresAdded = true; } + featureSettings.setEnabled(true); + alignPanel.repaint(); } @@ -2260,7 +2398,7 @@ public class AlignFrame { SequenceI[] msa = gatherSequencesForAlignment(); new jalview.ws.MsaWSClient(sh, title, msa, - false, true); + false, true, viewport.getAlignment().getDataset()); } @@ -2277,7 +2415,7 @@ public class AlignFrame { SequenceI[] msa = gatherSequencesForAlignment(); new jalview.ws.MsaWSClient(sh, title, msa, - true, true); + true, true, viewport.getAlignment().getDataset()); } @@ -2338,4 +2476,136 @@ public class AlignFrame // TODO: group services by location as well as function. } + /* public void vamsasStore_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty("LAST_DIRECTORY")); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Export to Vamsas file"); + chooser.setToolTipText("Export"); + + int value = chooser.showSaveDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport); + //vs.store(chooser.getSelectedFile().getAbsolutePath() ); + vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this); + } + }*/ + + public void featureSettings_actionPerformed(ActionEvent e) + { + new FeatureSettings(viewport, alignPanel); + } + + + +public void showTranslation_actionPerformed(ActionEvent e) +{ + int s, sSize = viewport.alignment.getHeight(); + SequenceI [] newSeq = new SequenceI[sSize]; + + int res, resSize; + StringBuffer protein; + String seq; + for(s=0; s idWidth) + { + idWidth = fm.stringWidth(id); + } - if (av.getShowFullId()) - { - id = s.getDisplayId(); - } - else - { - id = s.getName(); - } + i++; + } - if (fm.stringWidth(id) > idWidth) - { - idWidth = fm.stringWidth(id); - } + // Also check annotation label widths + i = 0; - i++; - } + if (al.getAlignmentAnnotation() != null) + { + fm = c.getFontMetrics(alabels.getFont()); - // Also check annotation label widths - i = 0; + while (i < al.getAlignmentAnnotation().length) + { + String label = al.getAlignmentAnnotation()[i].label; - if (al.getAlignmentAnnotation() != null) + if (fm.stringWidth(label) > idWidth) { - fm = c.getFontMetrics(alabels.getFont()); - - while (i < al.getAlignmentAnnotation().length) - { - String label = al.getAlignmentAnnotation()[i].label; - - if (fm.stringWidth(label) > idWidth) - { - idWidth = fm.stringWidth(label); - } - - i++; - } + idWidth = fm.stringWidth(label); } - return new Dimension(idWidth, 12); + i++; + } } - /** - * DOCUMENT ME! - * - * @param results DOCUMENT ME! - */ - public void highlightSearchResults(int[] results) - { - seqPanel.seqCanvas.highlightSearchResults(results); + return new Dimension(idWidth, 12); + } - // do we need to scroll the panel? - if (results != null) - { - SequenceI seq = av.alignment.getSequenceAt(results[0]); - int start = seq.findIndex(results[1]) - 1; - int end = seq.findIndex(results[2]) - 1; - - if ((av.getStartRes() > start) || (av.getEndRes() < end) || - ((av.getStartSeq() > results[0]) || - (av.getEndSeq() < results[0]))) - { - setScrollValues(start, results[0]); - } - } - } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public OverviewPanel getOverviewPanel() - { - return overviewPanel; - } + /** + * DOCUMENT ME! + * + * @param results DOCUMENT ME! + */ + public void highlightSearchResults(int[] results) + { + seqPanel.seqCanvas.highlightSearchResults(results); - /** - * DOCUMENT ME! - * - * @param op DOCUMENT ME! - */ - public void setOverviewPanel(OverviewPanel op) + // do we need to scroll the panel? + if (results != null) { - overviewPanel = op; - } + SequenceI seq = av.alignment.getSequenceAt(results[0]); + int start = seq.findIndex(results[1]) - 1; + int end = seq.findIndex(results[2]) - 1; - /** - * DOCUMENT ME! - * - * @param b DOCUMENT ME! - */ - public void setAnnotationVisible(boolean b) - { - if (!av.wrapAlignment) + if ( (av.getStartRes() > start) || (av.getEndRes() < end) || + ( (av.getStartSeq() > results[0]) || + (av.getEndSeq() < results[0]))) { - annotationSpaceFillerHolder.setVisible(b); - annotationScroller.setVisible(b); + setScrollValues(start, results[0]); } - repaint(); } - - /** - * DOCUMENT ME! - * - * @param wrap DOCUMENT ME! - */ - public void setWrapAlignment(boolean wrap) + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public OverviewPanel getOverviewPanel() + { + return overviewPanel; + } + + /** + * DOCUMENT ME! + * + * @param op DOCUMENT ME! + */ + public void setOverviewPanel(OverviewPanel op) + { + overviewPanel = op; + } + + /** + * DOCUMENT ME! + * + * @param b DOCUMENT ME! + */ + public void setAnnotationVisible(boolean b) + { + if (!av.wrapAlignment) { - av.startSeq = 0; - scalePanelHolder.setVisible(!wrap); - hscroll.setVisible(!wrap); - idwidthAdjuster.setVisible(!wrap); - - if(wrap) - { - annotationScroller.setVisible(false); - annotationSpaceFillerHolder.setVisible(false); - } - else if(av.showAnnotation) - { - annotationScroller.setVisible(true); - annotationSpaceFillerHolder.setVisible(true); - } - - idSpaceFillerPanel1.setVisible(!wrap); - - repaint(); + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); } - - - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) + repaint(); + } + + /** + * DOCUMENT ME! + * + * @param wrap DOCUMENT ME! + */ + public void setWrapAlignment(boolean wrap) + { + av.startSeq = 0; + scalePanelHolder.setVisible(!wrap); + hscroll.setVisible(!wrap); + idwidthAdjuster.setVisible(!wrap); + + if (wrap) { - if (up) - { - if (vscroll.getValue() < 1) - { - return false; - } - - fastPaint = false; - vscroll.setValue(vscroll.getValue() - 1); - } - else - { - if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) - { - return false; - } - - fastPaint = false; - vscroll.setValue(vscroll.getValue() + 1); - } - - fastPaint = true; - - return true; + annotationScroller.setVisible(false); + annotationSpaceFillerHolder.setVisible(false); } - - /** - * DOCUMENT ME! - * - * @param right DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public boolean scrollRight(boolean right) + else if (av.showAnnotation) { - if (right) - { - if (hscroll.getValue() < 1) - { - return false; - } + annotationScroller.setVisible(true); + annotationSpaceFillerHolder.setVisible(true); + } - fastPaint = false; - hscroll.setValue(hscroll.getValue() - 1); - } - else - { - if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) - { - return false; - } + idSpaceFillerPanel1.setVisible(!wrap); - fastPaint = false; - hscroll.setValue(hscroll.getValue() + 1); - } + repaint(); + } - fastPaint = true; + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if (up) + { + if (vscroll.getValue() < 1) + { + return false; + } - return true; + fastPaint = false; + vscroll.setValue(vscroll.getValue() - 1); } - - /** - * DOCUMENT ME! - * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - */ - public void setScrollValues(int x, int y) + else { - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - - 1); - - hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; - vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - - if (hextent > av.alignment.getWidth()) - { - hextent = av.alignment.getWidth(); - } - - if (vextent > av.alignment.getHeight()) - { - vextent = av.alignment.getHeight(); - } - - if ((hextent + x) > av.getAlignment().getWidth()) - { - x = av.getAlignment().getWidth() - hextent; - } - - if ((vextent + y) > av.getAlignment().getHeight()) - { - y = av.getAlignment().getHeight() - vextent; - } - - if (y < 0) - { - y = 0; - } - - if (x < 0) - { - x = 0; - } + if ( (vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) + { + return false; + } - hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); - vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + fastPaint = false; + vscroll.setValue(vscroll.getValue() + 1); } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void adjustmentValueChanged(AdjustmentEvent evt) + fastPaint = true; + + return true; + } + + /** + * DOCUMENT ME! + * + * @param right DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean scrollRight(boolean right) + { + if (right) { + if (hscroll.getValue() < 1) + { + return false; + } - int oldX = av.getStartRes(); - int oldY = av.getStartSeq(); - - if (evt.getSource() == hscroll) - { - int x = hscroll.getValue(); - av.setStartRes(x); - av.setEndRes((x + - (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); - } - - if (evt.getSource() == vscroll) - { - int offy = vscroll.getValue(); + fastPaint = false; + hscroll.setValue(hscroll.getValue() - 1); + } + else + { + if ( (hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) + { + return false; + } - if (av.getWrapAlignment()) - { - int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - av.setStartRes(vscroll.getValue() * rowSize); - av.setEndRes((vscroll.getValue() + 1) * rowSize); - } - else - { - av.setStartSeq(offy); - av.setEndSeq(offy + - (seqPanel.seqCanvas.getHeight() / av.getCharHeight())); - } - } + fastPaint = false; + hscroll.setValue(hscroll.getValue() + 1); + } - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } + fastPaint = true; - int xShift = av.getStartRes() - oldX; - int yShift = av.getStartSeq() - oldY; + return true; + } - if ( (xShift != 0 && yShift != 0) || - (Math.abs(xShift) > av.getEndRes() - av.getStartRes() - || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq()) - || av.getWrapAlignment() - || !fastPaint) - { - // Either no shift at all, or shift greater than visible amount - repaint(); - } - else - { - idPanel.idCanvas.fastPaint(yShift); - seqPanel.seqCanvas.fastPaint(xShift, yShift); + /** + * DOCUMENT ME! + * + * @param x DOCUMENT ME! + * @param y DOCUMENT ME! + */ + public void setScrollValues(int x, int y) + { + av.setEndRes( (x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - + 1); - scalePanel.repaint(); + hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; + vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; - if (av.getShowAnnotation()) - { - annotationPanel.fastPaint(xShift); - } - } + if (hextent > av.alignment.getWidth()) + { + hextent = av.alignment.getWidth(); } - /** - * DOCUMENT ME! - * - * @param g DOCUMENT ME! - */ - public void paintComponent(Graphics g) + if (vextent > av.alignment.getHeight()) { - invalidate(); - - Dimension d = idPanel.idCanvas.getPreferredSize(); - idPanelHolder.setPreferredSize(d); - hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - validate(); - - if (av.getWrapAlignment()) - { - int max = av.alignment.getWidth() / seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); - vscroll.setMaximum(max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); - } - else - { - setScrollValues(av.getStartRes(), av.getStartSeq()); - } + vextent = av.alignment.getHeight(); } - /** - * DOCUMENT ME! - * - * @param pg DOCUMENT ME! - * @param pf DOCUMENT ME! - * @param pi DOCUMENT ME! - * - * @return DOCUMENT ME! - * - * @throws PrinterException DOCUMENT ME! - */ - public int print(Graphics pg, PageFormat pf, int pi) - throws PrinterException + if ( (hextent + x) > av.getAlignment().getWidth()) { - pg.translate((int) pf.getImageableX(), (int) pf.getImageableY()); - - int pwidth = (int) pf.getImageableWidth(); - int pheight = (int) pf.getImageableHeight(); - - if (av.getWrapAlignment()) - { - return printWrappedAlignment(pg, pwidth, pheight, pi); - } - else - { - return printUnwrapped(pg, pwidth, pheight, pi); - } + x = av.getAlignment().getWidth() - hextent; } - /** - * DOCUMENT ME! - * - * @param pg DOCUMENT ME! - * @param pwidth DOCUMENT ME! - * @param pheight DOCUMENT ME! - * @param pi DOCUMENT ME! - * - * @return DOCUMENT ME! - * - * @throws PrinterException DOCUMENT ME! - */ - public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) - throws PrinterException + if ( (vextent + y) > av.getAlignment().getHeight()) { - int idWidth = calculateIdWidth().width + 4; - FontMetrics fm = getFontMetrics(av.getFont()); - int scaleHeight = av.charHeight + fm.getDescent(); - - pg.setColor(Color.white); - pg.fillRect(0, 0, pwidth, pheight); - pg.setFont(av.getFont()); - - //////////////////////////////////// - /// How many sequences and residues can we fit on a printable page? - int totalRes = (pwidth - idWidth) / av.getCharWidth(); - - int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - - 1; + y = av.getAlignment().getHeight() - vextent; + } - int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1; + if (y < 0) + { + y = 0; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int startRes; + if (x < 0) + { + x = 0; + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int endRes; + hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth()); + vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight()); + } - ///////////////////////////// - /// Only print these sequences and residues on this page - int startSeq; + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void adjustmentValueChanged(AdjustmentEvent evt) + { - ///////////////////////////// - /// Only print these sequences and residues on this page - int endSeq; - startRes = (pi % pagesWide) * totalRes; - endRes = (startRes + totalRes) - 1; + int oldX = av.getStartRes(); + int oldY = av.getStartSeq(); - if (endRes > (av.getAlignment().getWidth() - 1)) - { - endRes = av.getAlignment().getWidth() - 1; - } + if (evt.getSource() == hscroll) + { + int x = hscroll.getValue(); + av.setStartRes(x); + av.setEndRes( (x + + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); + } - startSeq = (pi / pagesWide) * totalSeq; - endSeq = startSeq + totalSeq; + if (evt.getSource() == vscroll) + { + int offy = vscroll.getValue(); - if (endSeq > av.getAlignment().getHeight()) - { - endSeq = av.getAlignment().getHeight(); - } + if (av.getWrapAlignment()) + { + int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel. + seqCanvas.getWidth()); + av.setStartRes(vscroll.getValue() * rowSize); + av.setEndRes( (vscroll.getValue() + 1) * rowSize); + } + else + { + av.setStartSeq(offy); + av.setEndSeq(offy + + (seqPanel.seqCanvas.getHeight() / av.getCharHeight())); + } + } - int pagesHigh = ((av.alignment.getHeight() / totalSeq) + 1) * pheight; + if (overviewPanel != null) + { + overviewPanel.setBoxPosition(); + } - if (av.showAnnotation) - { - pagesHigh += annotationPanel.adjustPanelHeight()+3; - } + int xShift = av.getStartRes() - oldX; + int yShift = av.getStartSeq() - oldY; - pagesHigh /= pheight; + if ( (xShift != 0 && yShift != 0) || + (Math.abs(xShift) > av.getEndRes() - av.getStartRes() + || Math.abs(yShift) > av.getEndSeq() - av.getStartSeq()) + || av.getWrapAlignment() + || !fastPaint) + { + // Either no shift at all, or shift greater than visible amount + repaint(); + } + else + { + idPanel.idCanvas.fastPaint(yShift); + seqPanel.seqCanvas.fastPaint(xShift, yShift); - if (pi >= (pagesWide * pagesHigh)) - { - return Printable.NO_SUCH_PAGE; - } + scalePanel.repaint(); - //draw Scale - pg.translate(idWidth, 0); - scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); - pg.translate(-idWidth, scaleHeight); + if (av.getShowAnnotation()) + { + annotationPanel.fastPaint(xShift); + } + } + } + + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + */ + public void paintComponent(Graphics g) + { + invalidate(); + + Dimension d = idPanel.idCanvas.getPreferredSize(); + idPanelHolder.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); + validate(); + + if (av.getWrapAlignment()) + { + int max = av.alignment.getWidth() / + seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()) +1; + vscroll.setMaximum(max); + vscroll.setUnitIncrement(1); + vscroll.setVisibleAmount(1); + } + else + { + setScrollValues(av.getStartRes(), av.getStartSeq()); + } - //////////////// - // Draw the ids - Color currentColor = null; - Color currentTextColor = null; - for (int i = startSeq; i < endSeq; i++) - { - if ((av.getSelectionGroup() != null) && - av.getSelectionGroup().sequences.contains( - av.getAlignment().getSequenceAt(i))) - { - currentColor = Color.gray; - currentTextColor = Color.black; - } - else - { - currentColor = av.getAlignment().getSequenceAt(i).getColor(); - currentTextColor = Color.black; - } + if( this.getVisibleRect().getBounds() == g.getClipBounds() ) + { + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); + } + } + + /** + * DOCUMENT ME! + * + * @param pg DOCUMENT ME! + * @param pf DOCUMENT ME! + * @param pi DOCUMENT ME! + * + * @return DOCUMENT ME! + * + * @throws PrinterException DOCUMENT ME! + */ + public int print(Graphics pg, PageFormat pf, int pi) + throws PrinterException + { + pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY()); + + int pwidth = (int) pf.getImageableWidth(); + int pheight = (int) pf.getImageableHeight(); + + if (av.getWrapAlignment()) + { + return printWrappedAlignment(pg, pwidth, pheight, pi); + } + else + { + return printUnwrapped(pg, pwidth, pheight, pi); + } + } + + /** + * DOCUMENT ME! + * + * @param pg DOCUMENT ME! + * @param pwidth DOCUMENT ME! + * @param pheight DOCUMENT ME! + * @param pi DOCUMENT ME! + * + * @return DOCUMENT ME! + * + * @throws PrinterException DOCUMENT ME! + */ + public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) + throws PrinterException + { + int idWidth = calculateIdWidth().width + 4; + FontMetrics fm = getFontMetrics(av.getFont()); + int scaleHeight = av.charHeight + fm.getDescent(); + + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); + + //////////////////////////////////// + /// How many sequences and residues can we fit on a printable page? + int totalRes = (pwidth - idWidth) / av.getCharWidth(); + + int totalSeq = (int) ( (pheight - scaleHeight) / av.getCharHeight()) - + 1; + + int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1; + + ///////////////////////////// + /// Only print these sequences and residues on this page + int startRes; + + ///////////////////////////// + /// Only print these sequences and residues on this page + int endRes; + + ///////////////////////////// + /// Only print these sequences and residues on this page + int startSeq; + + ///////////////////////////// + /// Only print these sequences and residues on this page + int endSeq; + startRes = (pi % pagesWide) * totalRes; + endRes = (startRes + totalRes) - 1; + + if (endRes > (av.getAlignment().getWidth() - 1)) + { + endRes = av.getAlignment().getWidth() - 1; + } - pg.setColor(currentColor); - pg.fillRect(0, (i-startSeq) * av.charHeight, idWidth, - av.getCharHeight()); + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; - pg.setColor(currentTextColor); + if (endSeq > av.getAlignment().getHeight()) + { + endSeq = av.getAlignment().getHeight(); + } - String string = av.getAlignment().getSequenceAt(i).getName(); + int pagesHigh = ( (av.alignment.getHeight() / totalSeq) + 1) * pheight; - if (av.getShowFullId()) - { - string = av.getAlignment().getSequenceAt(i).getDisplayId(); - } + if (av.showAnnotation) + { + pagesHigh += annotationPanel.adjustPanelHeight() + 3; + } - pg.drawString(string, 0, - (((i-startSeq) * av.charHeight) + av.getCharHeight()) - - (av.getCharHeight() / 5)); - } + pagesHigh /= pheight; - // draw main sequence panel - pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, - startRes, startSeq, 0); + if (pi >= (pagesWide * pagesHigh)) + { + return Printable.NO_SUCH_PAGE; + } - if (av.showAnnotation && (endSeq == av.alignment.getHeight())) - { - pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3); - alabels.drawComponent((Graphics2D) pg, idWidth); - pg.translate(idWidth, 0); - annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes + - 1); - } + //draw Scale + pg.translate(idWidth, 0); + scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); + pg.translate( -idWidth, scaleHeight); - return Printable.PAGE_EXISTS; - } + //////////////// + // Draw the ids + Color currentColor = null; + Color currentTextColor = null; - /** - * DOCUMENT ME! - * - * @param pg DOCUMENT ME! - * @param pwidth DOCUMENT ME! - * @param pheight DOCUMENT ME! - * @param pi DOCUMENT ME! - * - * @return DOCUMENT ME! - * - * @throws PrinterException DOCUMENT ME! - */ - public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, - int pi) throws PrinterException + for (int i = startSeq; i < endSeq; i++) { - - int annotationHeight = 0; - AnnotationLabels labels = null; - if (av.showAnnotation) + if ( (av.getSelectionGroup() != null) && + av.getSelectionGroup().sequences.contains( + av.getAlignment().getSequenceAt(i))) { - annotationHeight = annotationPanel.adjustPanelHeight(); - labels = new AnnotationLabels(av); + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getAlignment().getSequenceAt(i).getColor(); + currentTextColor = Color.black; } - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - hgap += av.charHeight; - - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap - + annotationHeight; - - - int idWidth = calculateIdWidth().width + 4; - - int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - - idWidth); + pg.setColor(currentColor); + pg.fillRect(0, (i - startSeq) * av.charHeight, idWidth, + av.getCharHeight()); - int totalHeight = cHeight * (av.alignment.getWidth() / resWidth +1); + pg.setColor(currentTextColor); - pg.setColor(Color.white); - pg.fillRect(0, 0, pwidth, pheight); - pg.setFont(av.getFont()); + String string = av.getAlignment().getSequenceAt(i).getDisplayId + ( av.getShowJVSuffix()); + pg.drawString(string, 0, + ( ( (i - startSeq) * av.charHeight) + av.getCharHeight()) - + (av.getCharHeight() / 5)); + } - //////////////// - // Draw the ids - pg.setColor(Color.black); + // draw main sequence panel + pg.translate(idWidth, 0); + seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, + startRes, startSeq, 0); - pg.translate(0, -pi * pheight); + if (av.showAnnotation && (endSeq == av.alignment.getHeight())) + { + pg.translate( -idWidth, (endSeq - startSeq) * av.charHeight + 3); + alabels.drawComponent( (Graphics2D) pg, idWidth); + pg.translate(idWidth, 0); + annotationPanel.drawComponent( (Graphics2D) pg, startRes, endRes + + 1); + } - pg.setClip(0, pi * pheight, pwidth, pheight); + return Printable.PAGE_EXISTS; + } + + /** + * DOCUMENT ME! + * + * @param pg DOCUMENT ME! + * @param pwidth DOCUMENT ME! + * @param pheight DOCUMENT ME! + * @param pi DOCUMENT ME! + * + * @return DOCUMENT ME! + * + * @throws PrinterException DOCUMENT ME! + */ + public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, + int pi) + throws PrinterException + { + + int annotationHeight = 0; + AnnotationLabels labels = null; + if (av.showAnnotation) + { + annotationHeight = annotationPanel.adjustPanelHeight(); + labels = new AnnotationLabels(av); + } - int ypos = hgap; - Font italic = new Font(av.getFont().getName(), Font.ITALIC, - av.getFont().getSize()); - pg.setFont(italic); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - do - { - for (int i = 0; i < av.alignment.getHeight(); i++) - { - SequenceI s = av.alignment.getSequenceAt(i); - String string = s.getName(); + int idWidth = calculateIdWidth().width + 4; - if (av.getShowFullId()) - { - string = s.getDisplayId(); - } + int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth - + idWidth); - pg.drawString(string, 0, - ( (i * av.charHeight) + ypos + av.charHeight) - - (av.charHeight / 5)); - } - if (labels != null) - { - pg.translate(0, - ypos + - (av.getAlignment().getHeight() * av.charHeight)); - - pg.setFont(av.getFont()); - labels.drawComponent( pg, idWidth ); - pg.setFont(italic); - pg.translate(0, - -ypos - - (av.getAlignment().getHeight() * av.charHeight)); - } + int totalHeight = cHeight * (av.alignment.getWidth() / resWidth + 1); - ypos += cHeight; - } - while (ypos < totalHeight); + pg.setColor(Color.white); + pg.fillRect(0, 0, pwidth, pheight); + pg.setFont(av.getFont()); - pg.translate(idWidth, 0); + //////////////// + // Draw the ids + pg.setColor(Color.black); - seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); + pg.translate(0, -pi * pheight); - if ((pi * pheight) < totalHeight) - { - return Printable.PAGE_EXISTS; + pg.setClip(0, pi * pheight, pwidth, pheight); - } - else - { - return Printable.NO_SUCH_PAGE; - } - } + int ypos = hgap; + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); + pg.setFont(italic); - /** - * DOCUMENT ME! - */ - public void makeEPS(File epsFile) + do { - boolean accurateText = true; - - String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", - "Prompt each time"); - - // If we need to prompt, and if the GUI is visible then - // Prompt for EPS rendering style - if (renderStyle.equalsIgnoreCase("Prompt each time") - && ! - (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true"))) + for (int i = 0; i < av.alignment.getHeight(); i++) { - EPSOptions eps = new EPSOptions(); - renderStyle = eps.getValue(); - - if(eps.cancelled || renderStyle==null) - return; + SequenceI s = av.alignment.getSequenceAt(i); + String string = s.getDisplayId( av.getShowJVSuffix()); - renderStyle = eps.getValue(); + pg.drawString(string, 0, + ( (i * av.charHeight) + ypos + av.charHeight) - + (av.charHeight / 5)); } - - if (renderStyle.equalsIgnoreCase("text")) + if (labels != null) { - accurateText = false; - } - + pg.translate(0, + ypos + + (av.getAlignment().getHeight() * av.charHeight)); - if(epsFile == null) - { - jalview.io.JalviewFileChooser chooser = new jalview.io. - JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"eps"}, - new String[] - {"Encapsulated Postscript"}, - "Encapsulated Postscript"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Create EPS file from alignment"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - return; - } - - epsFile = chooser.getSelectedFile(); - - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - } - - - int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; - int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); - - - if (av.getWrapAlignment()) - { - height = getWrappedHeight(); - width = seqPanel.getWidth() + idPanel.getWidth(); - } - else if (av.getShowAnnotation()) - { - height += annotationPanel.adjustPanelHeight()+3; - } + pg.setFont(av.getFont()); + labels.drawComponent(pg, idWidth); + pg.setFont(italic); + pg.translate(0, + -ypos - + (av.getAlignment().getHeight() * av.charHeight)); + } + ypos += cHeight; + } + while (ypos < totalHeight); - try - { - FileOutputStream out = new FileOutputStream(epsFile); - EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, - height); + pg.translate(idWidth, 0); - pg.setAccurateTextMode(accurateText); + seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); - if (av.getWrapAlignment()) - { - printWrappedAlignment(pg, width, height, 0); - } - else - { - printUnwrapped(pg, width, height, 0); - } + if ( (pi * pheight) < totalHeight) + { + return Printable.PAGE_EXISTS; - pg.flush(); - pg.close(); - } - catch (OutOfMemoryError err) - { - System.out.println("########################\n" - + "OUT OF MEMORY " + epsFile + "\n" - + "########################"); - - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory creating EPS file!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - JOptionPane.WARNING_MESSAGE); - System.out.println("Create EPS: " + err); - System.gc(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } } + else + { + return Printable.NO_SUCH_PAGE; + } + } + void makeAlignmentImage(int type, File file) + { + int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; + int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); - public void makePNGImageMap(File imgMapFile, String imageName) + if (av.getWrapAlignment()) { - ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS - ////////////////////////////////////////////// - int idWidth = calculateIdWidth().width + 4; - FontMetrics fm = getFontMetrics(av.getFont()); - int scaleHeight = av.charHeight + fm.getDescent(); - - // Gen image map - ////////////////////////////////// - if(imgMapFile!=null) - { - try - { - PrintWriter out = new PrintWriter(new FileWriter(imgMapFile)); - out.println(jalview.io.HTMLOutput.getImageMapHTML()); - out.println("" - +""); - - for (int s = 0; s < av.alignment.getHeight(); s++) - { - SequenceI seq = av.alignment.getSequenceAt(s); - SequenceGroup[] groups = av.alignment.findAllGroups(seq); - for (int i = 0; i < groups.length; i++) - { - int sy = s * av.charHeight + scaleHeight; - for (int res = groups[i].getStartRes(); - res < groups[i].getEndRes() + 1; res++) - { - int alIndex = seq.findPosition(res); - Object obj = ResidueProperties.aa2Triplet.get( - seq.getCharAt(res) + ""); - if (obj == null) - continue; - - String triplet = obj.toString(); - - out.println( - "" + groups[i].getName() + - "')\"; onMouseOut=\"toolTip()\"; " - + " href=\"#\">"); - } - } - } - - out.println(""); - out.close(); - - } - catch (Exception ex) - { - ex.printStackTrace(); - } - }///////////END OF IMAGE MAP - + height = getWrappedHeight(); + width = seqPanel.getWidth() + idPanel.getWidth(); } - - int getWrappedHeight() + else if (av.getShowAnnotation()) { + height += annotationPanel.adjustPanelHeight() + 3; + } - int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( - seqPanel.seqCanvas.getWidth()); - - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - hgap += av.charHeight; - - int annotationHeight = 0; - if (av.showAnnotation) + jalview.util.ImageMaker im; + if(type==jalview.util.ImageMaker.PNG) + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.PNG, + "Create PNG image from alignment", + width, height, file, null); + else + im = new jalview.util.ImageMaker(this, + jalview.util.ImageMaker.EPS, + "Create EPS file from alignment", + width, height, file, alignFrame.getTitle() ); + + try + { + if (av.getWrapAlignment()) { - annotationHeight = annotationPanel.adjustPanelHeight(); + if(im.getGraphics()!=null) + printWrappedAlignment(im.getGraphics(), width, height, 0); + } + else + { + if(im.getGraphics()!=null) + printUnwrapped(im.getGraphics(), width, height, 0); } - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap - + annotationHeight; - - - int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; - - return height; + im.writeImage(); } + catch (OutOfMemoryError err) + { + System.out.println("########################\n" + + "OUT OF MEMORY " + file + "\n" + + "########################"); + + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Out of Memory Creating Image!!" + + + "\nSee help files for increasing Java Virtual Machine memory." + , "Out of memory", + JOptionPane.WARNING_MESSAGE); + System.out.println("Create IMAGE: " + err); + System.gc(); - /** - * DOCUMENT ME! - */ - public void makePNG(File pngFile) + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + /** + * DOCUMENT ME! + */ + public void makeEPS(File epsFile) + { + makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile); + } + + /** + * DOCUMENT ME! + */ + public void makePNG(File pngFile) + { + makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile); + } + + public void makePNGImageMap(File imgMapFile, String imageName) + { + ///////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS + ////////////////////////////////////////////// + int idWidth = calculateIdWidth().width + 4; + FontMetrics fm = getFontMetrics(av.getFont()); + int scaleHeight = av.charHeight + fm.getDescent(); + + // Gen image map + ////////////////////////////////// + if (imgMapFile != null) { - if(pngFile==null) + try { - jalview.io.JalviewFileChooser chooser = new jalview.io. - JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] - {"png"}, - new String[] - {"Portable network graphics"}, - "Portable network graphics"); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Create EPS file from alignment"); - chooser.setToolTipText("Save"); - - int value = chooser.showSaveDialog(this); - - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + PrintWriter out = new PrintWriter(new FileWriter(imgMapFile)); + out.println(jalview.io.HTMLOutput.getImageMapHTML()); + out.println("" + + ""); + + for (int s = 0; s < av.alignment.getHeight(); s++) { - return; + SequenceI seq = av.alignment.getSequenceAt(s); + SequenceGroup[] groups = av.alignment.findAllGroups(seq); + for (int i = 0; i < groups.length; i++) + { + int sy = s * av.charHeight + scaleHeight; + for (int res = groups[i].getStartRes(); + res < groups[i].getEndRes() + 1; res++) + { + int alIndex = seq.findPosition(res); + Object obj = ResidueProperties.aa2Triplet.get( + seq.getCharAt(res) + ""); + if (obj == null) + continue; + + String triplet = obj.toString(); + + out.println( + "" + groups[i].getName() + + "')\"; onMouseOut=\"toolTip()\"; " + + " href=\"#\">"); + } + } } - pngFile = chooser.getSelectedFile(); + out.println(""); + out.close(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); } - - - - int height = ( (av.alignment.getHeight() + 1) * av.charHeight) + 30; - int width = idPanel.getWidth() + (av.alignment.getWidth() * av.charWidth); - - if (av.getWrapAlignment()) + catch (Exception ex) { - height = getWrappedHeight(); - width = seqPanel.getWidth() + idPanel.getWidth(); + ex.printStackTrace(); } - else if (av.getShowAnnotation()) - { - height += annotationPanel.adjustPanelHeight()+3; - } + } ///////////END OF IMAGE MAP - try - { + } - FileOutputStream out = new FileOutputStream(pngFile); + int getWrappedHeight() + { - BufferedImage bi = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); - Graphics2D png = (Graphics2D) bi.getGraphics(); + int chunkWidth = seqPanel.seqCanvas.getWrappedCanvasWidth( + seqPanel.seqCanvas.getWidth()); - png.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; - if (av.getWrapAlignment()) - { - printWrappedAlignment(png, width, height, 0); - } - else - { - printUnwrapped(png, width, height, 0); - } + int annotationHeight = 0; + if (av.showAnnotation) + { + annotationHeight = annotationPanel.adjustPanelHeight(); + } - ImageIO.write(bi, "png", out); - out.close(); - } - catch (OutOfMemoryError err) - { - System.out.println("########################\n" - + "OUT OF MEMORY " + pngFile + "\n" - + "########################"); - - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Out of memory creating PNG!!" - + - "\nSee help files for increasing Java Virtual Machine memory." - , "Out of memory", - JOptionPane.WARNING_MESSAGE); - System.out.println("Create PNG: " + err); - System.gc(); + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } -} + int height = ( (av.alignment.getWidth() / chunkWidth) + 1) * cHeight; + return height; + } -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class Preview extends JFrame -{ + /** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ + class Preview + extends JFrame + { /** * Creates a new Preview object. * @@ -1129,25 +989,25 @@ class Preview extends JFrame */ public Preview(Image image) { - setResizable(true); - setSize(image.getWidth(this), image.getHeight(this)); - setVisible(true); - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER); - validate(); - repaint(); + setResizable(true); + setSize(image.getWidth(this), image.getHeight(this)); + setVisible(true); + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(new PreviewPanel(image), BorderLayout.CENTER); + validate(); + repaint(); } -} - - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -class PreviewPanel extends JPanel -{ + } + + /** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ + class PreviewPanel + extends JPanel + { Image image; /** @@ -1157,7 +1017,7 @@ class PreviewPanel extends JPanel */ public PreviewPanel(Image image) { - this.image = image; + this.image = image; } /** @@ -1167,13 +1027,14 @@ class PreviewPanel extends JPanel */ public void paintComponent(Graphics g) { - if (image != null) - { - g.drawImage(image, 0, 0, this); - } - else - { - System.out.println("DEBUG:image is null"); - } + if (image != null) + { + g.drawImage(image, 0, 0, this); + } + else + { + System.out.println("DEBUG:image is null"); + } } + } } diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index a10f433..be2cf97 100755 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -80,6 +80,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer textarea.setText(text); } + public void appendText(String text) + { + textarea.append(text); + } + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 4186090..3acefe7 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -43,6 +43,10 @@ public class Desktop extends jalview.jbgui.GDesktop static final int xOffset = 30; static final int yOffset = 30; public static jalview.ws.Discoverer discoverer; + + public static Object [] jalviewClipboard; + + /** * Creates a new Desktop object. */ @@ -50,6 +54,7 @@ public class Desktop extends jalview.jbgui.GDesktop { Image image = null; + try { java.net.URL url = getClass().getResource("/images/logo.gif"); @@ -68,7 +73,7 @@ public class Desktop extends jalview.jbgui.GDesktop { } - setTitle("Jalview 2005"); + setTitle("Jalview "+jalview.bin.Cache.getProperty("VERSION")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); desktop = new JDesktopPane(); desktop.setBackground(Color.white); @@ -221,6 +226,7 @@ public class Desktop extends jalview.jbgui.GDesktop {} } + /** * DOCUMENT ME! * @@ -434,7 +440,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public void aboutMenuItem_actionPerformed(ActionEvent e) { - StringBuffer message = new StringBuffer("JalView 2005 version " + + StringBuffer message = new StringBuffer("JalView version " + jalview.bin.Cache.getProperty( "VERSION") + "; last updated: " + @@ -544,5 +550,31 @@ public class Desktop extends jalview.jbgui.GDesktop } } + /* public void vamsasLoad_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty("LAST_DIRECTORY")); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Load Vamsas file"); + chooser.setToolTipText("Import"); + + int value = chooser.showOpenDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(null); + vs.load( + chooser.getSelectedFile().getAbsolutePath() + ); + } + + }*/ + + + public void inputSequence_actionPerformed(ActionEvent e) + { + SequenceFetcher sf = new SequenceFetcher(null); + } } diff --git a/src/jalview/gui/EPSOptions.java b/src/jalview/gui/EPSOptions.java index 5926563..a9a60f2 100755 --- a/src/jalview/gui/EPSOptions.java +++ b/src/jalview/gui/EPSOptions.java @@ -27,7 +27,7 @@ public class EPSOptions extends JPanel { JDialog dialog; - boolean cancelled = false; + public boolean cancelled = false; String value; public EPSOptions() diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 8a94a89..03080bd 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -24,6 +24,8 @@ import java.awt.*; import java.util.*; +import java.awt.image.*; + /** * DOCUMENT ME! @@ -34,10 +36,15 @@ import java.util.*; public class FeatureRenderer { AlignViewport av; - SequenceGroup currentSequenceGroup = null; - SequenceGroup[] allGroups = null; Color resBoxColour; - Graphics graphics; + float transparency = 1.0f; + FontMetrics fm; + int charOffset; + boolean drawText = true; + + // The following vector holds the features which are + // to be added, in the correct order or rendering + Vector featuresDisplayed = null; /** * Creates a new FeatureRenderer object. @@ -47,8 +54,33 @@ public class FeatureRenderer public FeatureRenderer(AlignViewport av) { this.av = av; + initColours(); + } + + /** + * This is used by the Molecule Viewer to get the accurate colour + * of the rendered sequence + */ + BufferedImage bi; + public synchronized Color findFeatureColour(Color initialCol, SequenceI seq, int i) + { + if(!av.showSequenceFeatures) + return initialCol; + + if (bi == null) + bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); + + bi.setRGB(0,0, initialCol.getRGB()); + + drawText = false; + + drawSequence(bi.getGraphics(), seq, i, i, 0, 0, 1, 1); + drawText = true; + + return new Color(bi.getRGB(0, 0)); } + /** * DOCUMENT ME! * @@ -62,76 +94,222 @@ public class FeatureRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public void drawSequence(Graphics g, SequenceI seq, SequenceGroup[] sg, - int start, int end, int x1, int y1, int width, int height) + public void drawSequence(Graphics g, SequenceI seq, + int start, int end, int x1, int y1, int width, int height) { - Vector features = seq.getSequenceFeatures(); - Enumeration e = features.elements(); - while (e.hasMoreElements()) +//System.out.println(start+" "+end+" "+x1+" "+y1); + if (seq.getDatasetSequence().getSequenceFeatures() == null + || seq.getDatasetSequence().getSequenceFeatures().size()==0) + return; + + fm = g.getFontMetrics(); + + if (transparency != 1) + { + Graphics2D g2 = (Graphics2D) g; + g2.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, transparency)); + } + + String type; + SequenceFeature sf; + if (featuresDisplayed == null) + findAllFeatures(); + + Enumeration e = featuresDisplayed.elements(), e2; + + // Loop through each visible feature + while (e.hasMoreElements()) + { + + type = e.nextElement().toString(); + e2 = seq.getDatasetSequence().getSequenceFeatures().elements(); + // loop through all features in sequence to find + // current feature to render + while (e2.hasMoreElements()) { - SequenceFeature sf = (SequenceFeature) e.nextElement(); - if (sf.getStart() > seq.getEnd()) - { - continue; - } + sf = (SequenceFeature) e2.nextElement(); + if (!type.equals(sf.getType())) + continue; + + if (sf.getBegin() > seq.getEnd()) + continue; + + if (type.equals("disulfide bond")) + { + + renderFeature(g, seq, + seq.findIndex(sf.getBegin()) - 1, + seq.findIndex(sf.getBegin()) - 1, + type, start, end, x1, y1, width, height); + renderFeature(g, seq, + seq.findIndex(sf.getEnd()) - 1, + seq.findIndex(sf.getEnd()) - 1, + type, start, end, x1, y1, width, height); + + } + else + renderFeature(g, seq, + seq.findIndex(sf.getBegin()) - 1, + seq.findIndex(sf.getEnd()) - 1, + type, start, end, x1, y1, width, height); + } + } + + if(transparency!=1.0f) + { + Graphics2D g2 = (Graphics2D) g; + g2.setComposite( + AlphaComposite.getInstance( + AlphaComposite.SRC_OVER, 1.0f)); + } + } + - int fstart = seq.findIndex(sf.getStart()) - 1; - int fend = seq.findIndex(sf.getEnd()) - 1; + void renderFeature(Graphics g, SequenceI seq, + int fstart, int fend, String type, int start, int end, int x1, int y1, int width, int height) + { + + if (((fstart <= end) && (fend >= start))) + { + if (fstart < start) + { // fix for if the feature we have starts before the sequence start, + fstart = start; // but the feature end is still valid!! + } - if (((fstart <= end) && (fend >= start))) + if (fend >= end) + { + fend = end; + } + for (int i = fstart; i <= fend; i++) + { + char s = seq.getSequence().charAt(i); + + if (jalview.util.Comparison.isGap(s)) { - if (fstart < start) - { // fix for if the feature we have starts before the sequence start, - fstart = start; // but the feature end is still valid!! - } - - if (fend >= end) - { - fend = end; - } - - if (fstart == fend) - { - g.setColor(Color.red); - g.fillRoundRect((fstart - start) * width, y1, width, - height, 4, 4); - g.setColor(Color.white); - - char s = seq.getSequence().charAt(fstart); - FontMetrics fm = g.getFontMetrics(); - int charOffset = (width - fm.charWidth(s)) / 2; - int pady = height / 5; - g.drawString(String.valueOf(s), - charOffset + x1 + (width * (fstart - start)), - (y1 + height) - pady); - } - else - { - for (int i = fstart; i <= fend; i++) - { - char s = seq.getSequence().charAt(i); - - if (jalview.util.Comparison.isGap(s)) - { - continue; - } - - g.setColor(Color.blue); - g.fillRect((i - start) * width, y1, width, height); - - g.setColor(Color.white); - - FontMetrics fm = g.getFontMetrics(); - int charOffset = (width - fm.charWidth(s)) / 2; - int pady = height / 5; - g.drawString(String.valueOf(s), - charOffset + x1 + (width * (i - start)), - (y1 + height) - pady); - } - } + continue; } + + g.setColor(getColour(type)); + + g.fillRect( (i - start) * width, y1, width, height); + + if(drawText) + { + g.setColor(Color.white); + charOffset = (width - fm.charWidth(s)) / 2; + g.drawString(String.valueOf(s), + charOffset + x1 + (width * (i - start)), + (y1 + height) - height / 5); //pady = height / 5; + } + } + } + } + + void findAllFeatures() + { + Vector features = new Vector(); + SequenceFeature sf; + featuresDisplayed = new Vector(); + Enumeration e; + for (int i = 0; i < av.alignment.getHeight(); i++) + { + features = av.alignment.getSequenceAt(i).getDatasetSequence(). + getSequenceFeatures(); + if (features == null) + continue; + + e = features.elements(); + while (e.hasMoreElements()) + { + sf = (SequenceFeature) e.nextElement(); + if (!featuresDisplayed.contains(sf.getType())) + { + featuresDisplayed.addElement(sf.getType()); + } } + } + } + + public Color getColour(String featureType) + { + return (Color)featureColours.get(featureType); } + + public void setColour(String featureType, Color col) + { + featureColours.put(featureType, col); + } + + public void setTransparency(float value) + { + transparency = value; + } + + public float getTransparency() + { + return transparency; + } + + public void setFeaturePriority(Object [][] data) + { + // The feature table will display high priority + // features at the top, but theses are the ones + // we need to render last, so invert the data + featuresDisplayed.clear(); + for(int i=data.length-1; i>-1; i--) + { + String type = data[i][0].toString(); + setColour(type, (Color)data[i][1]); + if( ((Boolean)data[i][2]).booleanValue() ) + featuresDisplayed.addElement(type); + } + } + + Hashtable featureColours = new Hashtable(); + void initColours() + { + featureColours.put("active site", new Color(255, 75, 0)); + featureColours.put("binding site", new Color(245, 85, 0)); + featureColours.put("calcium-binding region", new Color(235, 95, 0)); + featureColours.put("chain", new Color(225, 105, 0)); + featureColours.put("coiled-coil region", new Color(215, 115, 0)); + featureColours.put("compositionally biased region", new Color(205, 125, 0)); + featureColours.put("cross-link", new Color(195, 135, 0)); + featureColours.put("disulfide bond", new Color(230,230,0)); + featureColours.put("DNA-binding region", new Color(175, 155, 0)); + featureColours.put("domain", new Color(165, 165, 0)); + featureColours.put("glycosylation site", new Color(155, 175, 0)); + featureColours.put("helix", new Color(145, 185, 0)); + featureColours.put("initiator methionine", new Color(135, 195, 5)); + featureColours.put("lipid moiety-binding region", new Color(125, 205, 15)); + featureColours.put("metal ion-binding site", new Color(115, 215, 25)); + featureColours.put("modified residue", new Color(105, 225, 35)); + featureColours.put("mutagenesis site", new Color(95, 235, 45)); + featureColours.put("non-consecutive residues", new Color(85, 245, 55)); + featureColours.put("non-terminal residue", new Color(75, 255, 65)); + featureColours.put("nucleotide phosphate-binding region",new Color(65, 245, 75)); + featureColours.put("peptide", new Color(55, 235, 85)); + featureColours.put("propeptide", new Color(45, 225, 95)); + featureColours.put("region of interest", new Color(35, 215, 105)); + featureColours.put("repeat", new Color(25, 205, 115)); + featureColours.put("selenocysteine", new Color(15, 195, 125)); + featureColours.put("sequence conflict", new Color(5, 185, 135)); + featureColours.put("sequence variant", new Color(0, 175, 145)); + featureColours.put("short sequence motif", new Color(0, 165, 155)); + featureColours.put("signal peptide", new Color(0, 155, 165)); + featureColours.put("site", new Color(0, 145, 175)); + featureColours.put("splice variant", new Color(0, 135, 185)); + featureColours.put("strand", new Color(0, 125, 195)); + featureColours.put("topological domain", new Color(0, 115, 205)); + featureColours.put("transit peptide", new Color(0, 105, 215)); + featureColours.put("transmembrane region", new Color(0, 95, 225)); + featureColours.put("turn", new Color(0, 85, 235)); + featureColours.put("unsure residue", new Color(0, 75, 245)); + featureColours.put("zinc finger region", new Color(0, 65, 255)); + } + } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java new file mode 100755 index 0000000..5325180 --- /dev/null +++ b/src/jalview/gui/FeatureSettings.java @@ -0,0 +1,478 @@ +package jalview.gui; + +import jalview.datamodel.*; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.*; +import java.util.*; +import javax.swing.BorderFactory; +import java.awt.event.*; +import javax.swing.table.*; +import java.io.*; +import jalview.io.JalviewFileChooser; + +public class FeatureSettings extends JPanel +{ + + final FeatureRenderer fr; + final AlignmentPanel ap; + final AlignViewport av; + Object [][] originalData; + final JInternalFrame frame; + JScrollPane scrollPane = new JScrollPane(); + JTable table; + + public FeatureSettings(AlignViewport av, final AlignmentPanel ap) + { + this.ap = ap; + this.av = av; + fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); + av.alignment.getSequences(); + frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 300); + + setTableData(); + + final JSlider transparency = new JSlider(0, 70, 0); + transparency.addChangeListener(new ChangeListener() + { + public void stateChanged(ChangeEvent evt) + { + fr.setTransparency( (float) (100 - transparency.getValue()) / 100f); + ap.repaint(); + } + }); + + JPanel transPanel = new JPanel(new FlowLayout()); + transPanel.add(new JLabel("Transparency")); + transPanel.add(transparency); + + ////////////////////////////////////////////// + //We're going to need those OK cancel buttons + JPanel buttonPanel = new JPanel(new FlowLayout()); + JButton button = new JButton("OK"); + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + try + { + frame.setClosed(true); + } + catch (Exception exe) + {} + } + }); + buttonPanel.add(button); + button = new JButton("Cancel"); + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + try + { + updateFeatureRenderer(originalData); + frame.setClosed(true); + } + catch (Exception exe) + {} + } + }); + buttonPanel.add(button); + + button = new JButton("Load Colours"); + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + load(); + } + }); + buttonPanel.add(button); + button = new JButton("Save Colours"); + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + save(); + } + }); + buttonPanel.add(button); + + this.setLayout(new BorderLayout()); + JPanel bigPanel = new JPanel(new BorderLayout()); + bigPanel.add(transPanel, BorderLayout.SOUTH); + bigPanel.add(scrollPane, BorderLayout.CENTER); + + add(bigPanel, BorderLayout.CENTER); + add(buttonPanel, BorderLayout.SOUTH); + + + } + + void setTableData() + { + Vector allFeatures = new Vector(); + Vector features; + Enumeration e; + SequenceFeature sf; + + for(int i=0; i< av.alignment.getHeight(); i++) + { + features = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures(); + if(features==null) + continue; + + e = features.elements(); + while(e.hasMoreElements()) + { + sf = (SequenceFeature)e.nextElement(); + if(!allFeatures.contains(sf.getType())) + { + allFeatures.addElement(sf.getType()); + } + } + } + if(allFeatures.size()<1) + { + try{ + frame.setClosed(true); + }catch(Exception ex){} + return; + } + + int fSize = allFeatures.size(); + + String type; + boolean originalExists = false; + if(originalData!=null) + originalExists = true; + else + originalData = new Object[fSize][3]; + + Object [][] data = new Object[fSize][3]; + for(int i=0; i"); + tip.append(av.alignment.getSequenceAt(seq).getDisplayId(true)); + if (av.alignment.getSequenceAt(seq).getDescription() != null) + { + tip.append("
"); + tip.append(av.alignment.getSequenceAt(seq).getDescription()); + tip.append("
"); + } + tip.append(""); + setToolTipText(tip.toString()); + } + } int getWrappedY(int y) @@ -124,7 +147,7 @@ public class IdPanel extends JPanel implements MouseListener, */ public void mouseClicked(MouseEvent e) { - if (e.getClickCount() < 2) + if (e.getClickCount() < 2) return; java.util.Vector links = Preferences.sequenceURLLinks; @@ -141,6 +164,9 @@ public class IdPanel extends JPanel implements MouseListener, //DEFAULT LINK IS FIRST IN THE LINK LIST int seq = av.getIndex(y); String id = av.getAlignment().getSequenceAt(seq).getName(); + if (id.indexOf("|") > -1) + id = id.substring(id.lastIndexOf("|") + 1); + String url = links.elementAt(0).toString(); url = url.substring(url.indexOf("|")+1); @@ -295,6 +321,9 @@ public class IdPanel extends JPanel implements MouseListener, */ void selectSeqs(int start, int end) { + if(av.getSelectionGroup()==null) + return; + lastid = start; if (end < start) @@ -307,7 +336,7 @@ public class IdPanel extends JPanel implements MouseListener, for (int i = start; i <= end; i++) { - av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), + av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), true); } } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 9ab6419..08b3903 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -27,6 +27,7 @@ import java.io.*; import java.net.*; import java.util.*; + import java.util.jar.*; import javax.swing.*; @@ -191,6 +192,56 @@ public class Jalview2XML jseq.setId(id); + if(jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures()!=null) + { + Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getSequenceFeatures().elements(); + while(en.hasMoreElements()) + { + Features features = new Features(); + jalview.datamodel.SequenceFeature sf + = (jalview.datamodel.SequenceFeature)en.nextElement(); + + features.setBegin(sf.getBegin()); + features.setEnd(sf.getEnd()); + features.setDescription(sf.getDescription()); + features.setStatus(sf.getStatus()); + features.setType(sf.getType()); + jseq.addFeatures(features); + } + } + + if(jal.getSequenceAt(i).getDatasetSequence().getPDBId()!=null) + { + Enumeration en = jal.getSequenceAt(i).getDatasetSequence().getPDBId().elements(); + while(en.hasMoreElements()) + { + Pdbids pdb = new Pdbids(); + jalview.datamodel.PDBEntry entry + = (jalview.datamodel.PDBEntry)en.nextElement(); + + pdb.setId(entry.getId()); + pdb.setType(entry.getType()); + + if(entry.getProperty()!=null) + { + PdbentryItem item = new PdbentryItem(); + Hashtable properties = entry.getProperty(); + Enumeration en2 = properties.keys(); + while(en2.hasMoreElements()) + { + Property prop = new Property(); + String key = en2.nextElement().toString(); + prop.setName(key); + prop.setValue( properties.get(key).toString() ); + item.addProperty(prop); + } + pdb.addPdbentryItem(item); + } + + jseq.addPdbids(pdb); + } + } + jms.addJSeq(jseq); vamsasSet.addSequence(vamsasSeq); id++; @@ -345,6 +396,7 @@ public class Jalview2XML jms.setJGroup(groups); } + ///////////SAVE VIEWPORT Viewport view = new Viewport(); view.setTitle(af.getTitle()); @@ -393,15 +445,40 @@ public class Jalview2XML view.setShowBoxes(av.getShowBoxes()); view.setShowColourText(av.getColourText()); view.setShowConservation(av.showConservation); - view.setShowFullId(av.getShowFullId()); + view.setShowFullId(av.getShowJVSuffix()); view.setShowIdentity(av.showIdentity); view.setShowQuality(av.showQuality); view.setShowSequenceFeatures(av.showSequenceFeatures); view.setShowText(av.getShowText()); view.setWrapAlignment(av.getWrapAlignment()); + if(af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed!=null) + { + jalview.binding.FeatureSettings fs = new jalview.binding.FeatureSettings(); + + Enumeration e = af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours.keys(); + while (e.hasMoreElements()) + { + String type = e.nextElement().toString(); + Setting setting = new Setting(); + setting.setType(type); + setting.setColour( + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(type).getRGB() + ); + setting.setDisplay( + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed.contains(type) + ); + + fs.addSetting(setting); + + } + jms.setFeatureSettings(fs); + + } + jms.addViewport(view); + object.setJalviewModelSequence(jms); object.getVamsasModel().addSequenceSet(vamsasSet); @@ -569,7 +646,6 @@ public class Jalview2XML //LOAD SEQUENCES jalview.datamodel.Sequence[] jseqs = new jalview.datamodel.Sequence[vamsasSeq.length]; JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq(); - for (int i = 0; i < vamsasSeq.length; i++) { jseqs[i] = new jalview.datamodel.Sequence(vamsasSeq[i].getName(), @@ -581,9 +657,41 @@ public class Jalview2XML seqids.add(jseqs[i]); } + ///SequenceFeatures are added to the DatasetSequence, + // so we must create the dataset before loading features ///////////////////////////////// jalview.datamodel.Alignment al = new jalview.datamodel.Alignment(jseqs); + al.setDataset(null); + ///////////////////////////////// + for (int i = 0; i < vamsasSeq.length; i++) + { + if (JSEQ[i].getFeaturesCount() > 0) + { + Features[] features = JSEQ[i].getFeatures(); + for (int f = 0; f < features.length; f++) + { + //features[f].getBegin() + jalview.datamodel.SequenceFeature sf + = new jalview.datamodel.SequenceFeature(features[f].getType(), + features[f].getDescription(), features[f].getStatus(), + features[f].getBegin(), features[f].getEnd()); + al.getSequenceAt(i).getDatasetSequence().addSequenceFeature(sf); + } + } + if (JSEQ[i].getPdbidsCount() > 0) + { + Pdbids[] ids = JSEQ[i].getPdbids(); + for (int p = 0; p < ids.length; p++) + { + jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry(); + entry.setId(ids[p].getId()); + entry.setType(ids[p].getType()); + al.getSequenceAt(i).getDatasetSequence().addPDBId(entry); + } + + } + } ///////////////////////////////// ////////////////////////////////// //LOAD ANNOTATIONS @@ -628,6 +736,7 @@ public class Jalview2XML AlignFrame af = new AlignFrame(al); + // af.changeColour() ); ///////////////////////// //LOAD GROUPS @@ -700,8 +809,8 @@ public class Jalview2XML af.viewport.setConservationSelected(view.getConservationSelected()); af.conservationMenuItem.setSelected(view.getConservationSelected()); - af.viewport.setShowFullId(view.getShowFullId()); - af.fullSeqId.setSelected(view.getShowFullId()); + af.viewport.setShowJVSuffix(view.getShowFullId()); + af.seqLimits.setSelected(view.getShowFullId()); af.viewport.setFont(new java.awt.Font(view.getFontName(), view.getFontStyle(), view.getFontSize())); @@ -762,10 +871,25 @@ public class Jalview2XML if (view.getShowSequenceFeatures()) { - af.viewport.showSequenceFeatures = true; - af.sequenceFeatures.setSelected(true); - new SequenceFeatureFetcher(al, af.alignPanel); - al.featuresAdded = true; + af.featureSettings.setEnabled(true); + af.viewport.showSequenceFeatures = true; + af.sequenceFeatures.setSelected(true); + } + + if(jms.getFeatureSettings()!=null) + { + af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed = new Vector(); + // af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed!=null) + // jalview.binding.FeatureSettings fs = new jalview.binding.FeatureSettings(); + for(int fs=0; fs-1) + id = id.substring(id.lastIndexOf("|")+1); final String url = link.substring(link.indexOf("|")+1, link.indexOf("$SEQUENCE_ID$")) - + sequence.getName() + + + id + link.substring(link.indexOf("$SEQUENCE_ID$") + 13); @@ -261,14 +280,7 @@ public class PopupMenu extends JPopupMenu unGroupMenuItem_actionPerformed(e); } }); - pdbMenuItem.setText("View PDB structure"); - pdbMenuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - pdbMenuItem_actionPerformed(e); - } - }); + outline.setText("Border colour"); outline.addActionListener(new java.awt.event.ActionListener() { @@ -325,7 +337,6 @@ public class PopupMenu extends JPopupMenu groupMenu.addSeparator(); groupMenu.add(outline); sequenceMenu.add(sequenceName); - sequenceMenu.add(pdbMenuItem); colourMenu.add(noColourmenuItem); colourMenu.add(clustalColour); colourMenu.add(BLOSUM62Colour); @@ -830,37 +841,6 @@ public class PopupMenu extends JPopupMenu refresh(); } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - void pdbMenuItem_actionPerformed(ActionEvent e) - { - if (sequence.getPDBId() == null) - { - return; - } - - try - { - EBIFetchClient ebi = new EBIFetchClient(); - String[] result = ebi.fetchData("pdb:" + sequence.getPDBId(), null, - null); - - PDBfile pdb = new PDBfile(result); - - rotCanvas rc = new rotCanvas(pdb, sequence, ap.av); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(rc); - Desktop.addInternalFrame(frame, - sequence.getName() + " " + sequence.getPDBId(), 400, 400); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } /** * DOCUMENT ME! diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 32aad84..2243a3d 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -79,7 +79,7 @@ public class Preferences extends GPreferences Desktop.addInternalFrame(frame, "Preferences", 480, 390); frame.setMinimumSize(new Dimension(480,390)); - fullID.setSelected( Cache.getDefault("SHOW_FULL_ID", true)); + seqLimit.setSelected( Cache.getDefault("SHOW_JVSUFFIX", true)); fullScreen.setSelected( Cache.getDefault("SHOW_FULLSCREEN", false)); annotations.setSelected( Cache.getDefault("SHOW_ANNOTATIONS", true)); @@ -140,6 +140,14 @@ public class Preferences extends GPreferences epsRendering.addItem("Text"); epsRendering.setSelectedItem( Cache.getDefault("EPS_RENDERING", "Prompt each time")); + blcjv.setSelected( Cache.getDefault("BLC_JVSUFFIX", true) ); + clustaljv.setSelected( Cache.getDefault("CLUSTAL_JVSUFFIX", true) ); + fastajv.setSelected( Cache.getDefault("FASTA_JVSUFFIX", true) ); + msfjv.setSelected( Cache.getDefault("MSF_JVSUFFIX", true) ); + pfamjv.setSelected( Cache.getDefault("PFAM_JVSUFFIX", true) ); + pileupjv.setSelected( Cache.getDefault("PILEUP_JVSUFFIX", true) ); + pirjv.setSelected( Cache.getDefault("PIR_JVSUFFIX", true) ); + /**************************************************** * Set up Connections */ @@ -181,7 +189,7 @@ public class Preferences extends GPreferences public void ok_actionPerformed(ActionEvent e) { - Cache.applicationProperties.setProperty("SHOW_FULL_ID", Boolean.toString(fullID.isSelected())); + Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean.toString(seqLimit.isSelected())); Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean.toString(fullScreen.isSelected())); Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean.toString(annotations.isSelected())); @@ -257,6 +265,14 @@ public class Preferences extends GPreferences } + Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean.toString(blcjv.isSelected()) ); + Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean.toString(clustaljv.isSelected()) ); + Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean.toString(fastajv.isSelected()) ); + Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean.toString(msfjv.isSelected()) ); + Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean.toString(pfamjv.isSelected()) ); + Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean.toString(pileupjv.isSelected()) ); + Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean.toString(pirjv.isSelected()) ); + Cache.saveProperties(); try diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 92abbf6..fc72b4b 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -303,9 +303,13 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @param g DOCUMENT ME! */ - public void paintComponent(Graphics g) + public void paintComponent(Graphics g1) { + Graphics2D g = (Graphics2D) g1; + + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); if(points==null) { g.setFont(new Font("Verdana", Font.PLAIN, 18)); @@ -345,12 +349,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @param g DOCUMENT ME! */ - public void drawAxes(Graphics g1) + public void drawAxes(Graphics g) { - Graphics2D g = (Graphics2D) g1; - - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.yellow); @@ -486,8 +486,6 @@ public class RotatableCanvas extends JPanel implements MouseListener, */ public void keyPressed(KeyEvent evt) { - requestFocus(); - if (evt.getKeyCode() == KeyEvent.VK_UP) { scalefactor = (float) (scalefactor * 1.1); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 7f9ee97..42424d9 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -24,6 +24,7 @@ import java.awt.*; import java.awt.image.*; import javax.swing.*; +import jalview.schemes.*; /** @@ -47,8 +48,6 @@ public class SeqCanvas extends JComponent int LABEL_WEST; int LABEL_EAST; - boolean isOverview = false; - /** * Creates a new SeqCanvas object. * @@ -64,6 +63,28 @@ public class SeqCanvas extends JComponent setBackground(Color.white); } + MCview.PDBCanvas pdbCanvas; + public SequenceRenderer getSequenceRenderer() + { + return sr; + } + + public FeatureRenderer getFeatureRenderer() + { + return fr; + } + + public void setPDBCanvas(MCview.PDBCanvas pc) + { + pdbCanvas = pc; + } + + public AlignViewport getViewport() + { + return av; + } + + /** * DOCUMENT ME! * @@ -258,18 +279,20 @@ public class SeqCanvas extends JComponent // Set this to false to force a full panel paint public void paintComponent(Graphics g) { + super.paintComponent(g); + sr.renderGaps(av.renderGaps); - if ((img != null) && - (fastPaint || (getWidth() != g.getClipBounds().width) || - (getHeight() != g.getClipBounds().height))) + if ( img != null && (fastPaint + || (getVisibleRect().width != g.getClipBounds().width) + || (getVisibleRect().height != g.getClipBounds().height))) { g.drawImage(img, 0, 0, this); fastPaint = false; - return; } + // this draws the whole of the alignment imgWidth = getWidth(); imgHeight = getHeight(); @@ -282,7 +305,6 @@ public class SeqCanvas extends JComponent return; } - img = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); gg = (Graphics2D) img.getGraphics(); gg.setFont(av.getFont()); @@ -304,6 +326,12 @@ public class SeqCanvas extends JComponent } g.drawImage(img, 0, 0, this); + + if (pdbCanvas != null) + { + pdbCanvas.updateSeqColours(); + } + } /** @@ -510,36 +538,83 @@ public class SeqCanvas extends JComponent repaint(); } + synchronized public void drawPanel(Graphics g1, int x1, int x2, int y1, int y2, int startx, int starty, int offset) { - Graphics2D g = (Graphics2D) g1; - g.setFont(av.getFont()); + Graphics2D g = (Graphics2D) g1; + g.setFont(av.getFont()); + SequenceI nextSeq, dna = null; + int aaHeight = av.charHeight, dnaHeight = av.charHeight; + Font dnafont = null, aafont = av.getFont(); - SequenceI nextSeq; + /* if (av.getShowTranslation()) + { + aaHeight = (int) (av.getCharHeight() * aaRatio); + dnaHeight = (int) (av.getCharHeight() * (1 - aaRatio)); + java.awt.geom.AffineTransform transform = new java.awt.geom.AffineTransform(); + transform.scale(1f / 3f, 1); + dnafont = new Font(av.getFont().getName(), av.getFont().getStyle(), + dnaHeight); + dnafont = dnafont.deriveFont(transform); + + aafont = new Font(av.getFont().getName(), av.getFont().getStyle(), + aaHeight); + transform = new java.awt.geom.AffineTransform(); + transform.scale(1 / aaRatio, 1); + aafont = aafont.deriveFont(transform); + } +*/ + ColourSchemeI cs = av.getGlobalColourScheme(); /// First draw the sequences ///////////////////////////// for (int i = y1; i < y2; i++) { nextSeq = av.alignment.getSequenceAt(i); - g.setFont(av.getFont()); - + g.setFont(aafont); + /* if(av.getShowTranslation()) + { + dna = nextSeq; + StringBuffer sb = new StringBuffer(); + for(int r = 0; r 0)) + if ((group == null) && (av.alignment.getGroups().size() > 0)) { - group = (SequenceGroup) groups.elementAt(0); + group = (SequenceGroup) av.alignment.getGroups().elementAt(0); groupIndex = 0; } - - if (group != null && !isOverview) + if (group != null) { do { @@ -701,14 +774,14 @@ public class SeqCanvas extends JComponent groupIndex++; - if (groupIndex >= groups.size()) + if (groupIndex >= av.alignment.getGroups().size()) { break; } - group = (SequenceGroup) groups.elementAt(groupIndex); + group = (SequenceGroup) av.alignment.getGroups().elementAt(groupIndex); } - while (groupIndex < groups.size()); + while (groupIndex < av.alignment.getGroups().size()); } /// Highlight search Results once all sequences have been drawn diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index a68b226..3209960 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -89,21 +89,31 @@ public class SeqPanel extends JPanel ap = p; + addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent evt) { doMouseMoved(evt); + if (editingSeqs) + { + // This is because MacOSX creates a mouseMoved + // If control is down + if(!av.isDataset()) + doMouseDragged(evt); + } } public void mouseDragged(MouseEvent evt) { if (editingSeqs) { + if(!av.isDataset()) doMouseDragged(evt); } else { + if(!av.isDataset()) doMouseDraggedDefineMode(evt); } } @@ -118,7 +128,7 @@ public class SeqPanel extends JPanel { Font font = av.getFont(); int fontSize = font.getSize(); - if (e.getWheelRotation() > 0 && fontSize < 30) + if (e.getWheelRotation() > 0 && fontSize < 51) fontSize++; else if (fontSize > 1) fontSize--; @@ -138,67 +148,71 @@ public class SeqPanel extends JPanel }); - addMouseListener(new MouseAdapter() - { - public void mouseReleased(MouseEvent evt) - { - mouseWheelPressed = false; - - if (editingSeqs) - { - doMouseReleased(evt); - } - else - { - doMouseReleasedDefineMode(evt); - } - } - - public void mousePressed(MouseEvent evt) - { - if( javax.swing.SwingUtilities.isMiddleMouseButton(evt)) - { - mouseWheelPressed = true; - return; - } + if(!av.isDataset()) + { + addMouseListener(new MouseAdapter() + { + public void mouseReleased(MouseEvent evt) + { + mouseWheelPressed = false; - if (evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) - { - if (evt.isAltDown() || evt.isControlDown()) - { - groupEditing = true; - } + if (editingSeqs) + { + doMouseReleased(evt); + } + else + { + doMouseReleasedDefineMode(evt); + } + } - editingSeqs = true; - doMousePressed(evt); - } - else - { - doMousePressedDefineMode(evt); - } - } + public void mousePressed(MouseEvent evt) + { + if (javax.swing.SwingUtilities.isMiddleMouseButton(evt)) + { + mouseWheelPressed = true; + return; + } + + if (evt.isShiftDown() || evt.isAltDown() || + evt.isControlDown()) + { + if (evt.isAltDown() || evt.isControlDown()) + { + groupEditing = true; + + } + + editingSeqs = true; + doMousePressed(evt); + } + else + { + doMousePressedDefineMode(evt); + } + } - public void mouseExited(MouseEvent evt) - { - if (editingSeqs) - { - return; - } + public void mouseExited(MouseEvent evt) + { + if (editingSeqs) + { + return; + } - doMouseExitedDefineMode(evt); - } + doMouseExitedDefineMode(evt); + } - public void mouseEntered(MouseEvent evt) - { - if (editingSeqs) - { - return; - } + public void mouseEntered(MouseEvent evt) + { + if (editingSeqs) + { + return; + } - doMouseEnteredDefineMode(evt); - } - }); + doMouseEnteredDefineMode(evt); + } + }); + } } int startWrapBlock=-1; @@ -343,6 +357,12 @@ public class SeqPanel extends JPanel return; } + if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence) + { + seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res)); + } + + StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + sequence.getName()); @@ -376,32 +396,54 @@ public class SeqPanel extends JPanel // use aa to see if the mouse pointer is on a if (av.showSequenceFeatures) { - Vector features = sequence.getSequenceFeatures(); - Enumeration e = features.elements(); - StringBuffer sbuffer = new StringBuffer(); - - while (e.hasMoreElements()) + Vector features = sequence.getDatasetSequence().getSequenceFeatures(); + if(features!=null) { - SequenceFeature sf = (SequenceFeature) e.nextElement(); + StringBuffer sbuffer = new StringBuffer(""); - if ((sf.getStart() <= sequence.findPosition(res)) && - (sf.getEnd() >= sequence.findPosition(res))) + for (int i = 0; i < features.size(); i++) + { + SequenceFeature sf = (SequenceFeature) features.elementAt(i); + + if ( (sf.getBegin() <= sequence.findPosition(res)) && + (sf.getEnd() >= sequence.findPosition(res))) { - if (sbuffer.length() > 0) + if (sf.getType().equals("disulfide bond")) + { + if (sf.getBegin() == sequence.findPosition(res) + || sf.getEnd() == sequence.findPosition(res)) { - sbuffer.append("; "); + if (sbuffer.length() > 6) + sbuffer.append("
"); + sbuffer.append("disulfide bond " + sf.getBegin() + ":" + + sf.getEnd()); } + } + else + { + if (sbuffer.length() > 6) + sbuffer.append("
"); + sbuffer.append(sf.getType()); + if (sf.getDescription() != null) + sbuffer.append(" " + sf.getDescription()); - sbuffer.append(sf.getType() + " " + sf.getDescription()); - - if (sf.getStatus().length() > 0) + if (sf.getStatus() != null) { - sbuffer.append(" (" + sf.getStatus() + ")"); + sbuffer.append(" (" + sf.getStatus() + ")"); } + } } - } - this.setToolTipText(sbuffer.toString()); + } + + sbuffer.append(""); + if(sbuffer.length()==13) // + setToolTipText(""); + else + setToolTipText(sbuffer.toString()); + } + else + setToolTipText(""); } } @@ -967,7 +1009,7 @@ public class SeqPanel extends JPanel try { - Thread.sleep(75); + Thread.sleep(20); } catch (Exception ex) { diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java new file mode 100755 index 0000000..fc3bd41 --- /dev/null +++ b/src/jalview/gui/SequenceFetcher.java @@ -0,0 +1,347 @@ +package jalview.gui; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import jalview.io.EBIFetchClient; +import MCview.*; +import jalview.datamodel.*; +import jalview.analysis.AlignSeq; +import java.io.File; +import jalview.io.*; +import java.util.*; + + +public class SequenceFetcher + extends JPanel implements Runnable +{ + JInternalFrame frame; + AlignFrame alignFrame; + StringBuffer result; + public SequenceFetcher(AlignFrame af) + { + alignFrame = af; + database.addItem("-- Select Database --"); + database.addItem("Uniprot"); + database.addItem("EMBL"); + database.addItem("EMBLCDS"); + database.addItem("PDB"); + + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + frame = new JInternalFrame(); + frame.setContentPane(this); + if(System.getProperty("os.name").startsWith("Mac")) + Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 400, 140); + else + Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 400, 120); + } + + private void jbInit() + throws Exception + { + this.setLayout(gridBagLayout1); + + database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + database.setMinimumSize(new Dimension(160, 21)); + database.setPreferredSize(new Dimension(160, 21)); + jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); + jLabel1.setText( + "Separate multiple accession ids with semi colon \";\""); + ok.setText("OK"); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText("Cancel"); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + textfield.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + jPanel1.add(ok); + jPanel1.add(cancel); + this.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0 + , GridBagConstraints.WEST, + GridBagConstraints.NONE, + new Insets(7, 4, 0, 6), 77, 6)); + this.add(jPanel1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0 + , GridBagConstraints.WEST, + GridBagConstraints.BOTH, + new Insets(7, -2, 7, 12), 241, -2)); + this.add(database, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 + , GridBagConstraints.WEST, + GridBagConstraints.NONE, + new Insets(0, 4, 0, 0), 1, 0)); + this.add(textfield, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 + , GridBagConstraints.CENTER, + GridBagConstraints.HORIZONTAL, + new Insets(0, 0, 0, 6), 200, 1)); + } + + JComboBox database = new JComboBox(); + JLabel jLabel1 = new JLabel(); + JButton ok = new JButton(); + JButton cancel = new JButton(); + JPanel jPanel1 = new JPanel(); + JTextField textfield = new JTextField(); + GridBagLayout gridBagLayout1 = new GridBagLayout(); + public void cancel_actionPerformed(ActionEvent e) + { + try + { + frame.setClosed(true); + } + catch (Exception ex) + {} + } + + public void ok_actionPerformed(ActionEvent e) + { + frame.setTitle("Sequence Fetcher (WSDBfetch@EBI) - Fetching Sequence..."); + database.setEnabled(false); + textfield.setEnabled(false); + ok.setEnabled(false); + cancel.setEnabled(false); + + Thread worker = new Thread(this); + worker.start(); + } + + public void run() + { + result = new StringBuffer(); + if (database.getSelectedItem().equals("Uniprot")) + { + getUniprotFile(textfield.getText()); + } + else if (database.getSelectedItem().equals("EMBL") + || database.getSelectedItem().equals("EMBLCDS")) + { + EBIFetchClient dbFetch = new EBIFetchClient(); + String[] reply = dbFetch.fetchData( + database.getSelectedItem().toString().toLowerCase( + ) + ":" + textfield.getText(), + "fasta", "raw"); + + for (int i = 0; i < reply.length; i++) + result.append(reply[i] + "\n"); + + parseResult(result.toString()); + } + else if (database.getSelectedItem().equals("PDB")) + { + result = getPDBFile(textfield.getText().toUpperCase()); + parseResult(result.toString()); + } + + + if (result == null || result.length() == 0) + showErrorMessage("Error retrieving " + textfield.getText() + + " from " + database.getSelectedItem()); + + + database.setEnabled(true); + textfield.setEnabled(true); + ok.setEnabled(true); + cancel.setEnabled(true); + frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)"); + } + + void getUniprotFile(String id) + { + EBIFetchClient ebi = new EBIFetchClient(); + File file = ebi.fetchDataAsFile("uniprot:"+id,"xml", null); + SequenceFeatureFetcher sff = new SequenceFeatureFetcher(); + Vector entries = sff.getUniprotEntries(file); + + if(entries!=null) + { + //First, make the new sequences + Enumeration en = entries.elements(); + while (en.hasMoreElements()) + { + UniprotEntry entry = (UniprotEntry) en.nextElement(); + StringBuffer name = new StringBuffer( ">Uniprot/Swiss-Prot" ); + Enumeration en2 = entry.getAccession().elements(); + while(en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + en2 = entry.getName().elements(); + while(en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + + if(entry.getProteinName()!=null) + name.append(" "+entry.getProteinName().elementAt(0)); + + result.append(name +"\n"+entry.getUniprotSequence().getContent()); + + } + + //Then read in the features and apply them to the dataset + SequenceI [] sequence = parseResult(result.toString()); + for(int i=0; i -1) + { + chain = id.substring(id.indexOf(":") + 1); + id = id.substring(0, id.indexOf(":")); + } + + EBIFetchClient ebi = new EBIFetchClient(); + String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); + try + { + PDBfile pdbfile = new PDBfile(reply); + for (int i = 0; i < pdbfile.chains.size(); i++) + { + if (chain == null || + ( (PDBChain) pdbfile.chains.elementAt(i)).id. + toUpperCase().equals(chain)) + result.append("\n>PDB|" + id + "|" + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. + getName() + + "\n" + + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. + getSequence()); + } + } + catch (Exception ex) // Problem parsing PDB file + { + showErrorMessage("Error retrieving " + textfield.getText() + " from " + + database.getSelectedItem()); + return null; + } + + return result; + } + + SequenceI[] parseResult(String result) + { + String format = IdentifyFile.Identify(result, "Paste"); + SequenceI[] sequences = null; + + if (FormatAdapter.formats.contains(format)) + { + sequences = new FormatAdapter().readFile(result.toString(), "Paste", format); + if (sequences != null && sequences.length>0) + { + if(alignFrame==null) + { + AlignFrame af = new AlignFrame(new Alignment(sequences)); + af.currentFileFormat = format; + Desktop.addInternalFrame(af, "Retrieved from "+database.getSelectedItem(), + AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + af.statusBar.setText("Successfully pasted alignment file"); + try + { + af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); + } + catch (Exception ex) + {} + } + else + { + for (int i = 0; i < sequences.length; i++) + { + alignFrame.viewport.alignment.addSequence(sequences[i]); + + //////////////////////////// + //Datset needs extension; + ///////////////////////////// + Sequence ds = new Sequence(sequences[i].getName(), + AlignSeq.extractGaps("-. ", + sequences[i].getSequence()), + sequences[i].getStart(), + sequences[i].getEnd()); + sequences[i].setDatasetSequence(ds); + alignFrame.viewport.alignment.getDataset().addSequence(ds); + } + alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. + getHeight()); + alignFrame.viewport.alignment.getWidth(); + alignFrame.viewport.firePropertyChange("alignment", null, + alignFrame.viewport.getAlignment().getSequences()); + + } + + if (database.getSelectedItem().equals("PDB")) + { + for (int i = 0; i < sequences.length; i++) + { + PDBEntry entry = new PDBEntry(); + entry.setId(textfield.getText()); + sequences[i].getDatasetSequence().addPDBId(entry); + } + } + + } + else + showErrorMessage( "Error retrieving "+textfield.getText() + +" from "+database.getSelectedItem()); + } + + return sequences; + + } + + void showErrorMessage(String error) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + error, "Error Retrieving Data", JOptionPane.WARNING_MESSAGE); + } +} + + + + diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 6bf4d40..57cd0fc 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -24,7 +24,6 @@ import jalview.schemes.*; import java.awt.*; - /** * DOCUMENT ME! * @@ -61,22 +60,27 @@ public class SequenceRenderer renderGaps = b; } - /** - * DOCUMENT ME! - * - * @param cs DOCUMENT ME! - * @param seq DOCUMENT ME! - * @param i DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) + + public Color getResidueBoxColour(SequenceI seq, int i) { - getBoxColour(cs, seq, i); + allGroups = av.alignment.findAllGroups(seq); - return resBoxColour; + if (inCurrentSequenceGroup(i)) + { + if (currentSequenceGroup.getDisplayBoxes()) + { + getBoxColour(currentSequenceGroup.cs, seq, i); + } + } + else if (av.getShowBoxes()) + { + getBoxColour(av.globalColourScheme, seq, i); + } + + return resBoxColour; } + /** * DOCUMENT ME! * @@ -116,10 +120,10 @@ public class SequenceRenderer graphics = g; - drawBoxes(seq, start, end, x1, y1, width, height); + drawBoxes(seq, start, end, x1, y1, (int) width, height); fm = g.getFontMetrics(); - drawText(seq, start, end, x1, y1, width, height); + drawText(seq, start, end, x1, y1, (int) width, height); } /** @@ -133,61 +137,62 @@ public class SequenceRenderer * @param width DOCUMENT ME! * @param height DOCUMENT ME! */ - public void drawBoxes(SequenceI seq, int start, int end, int x1, int y1, + public synchronized void drawBoxes(SequenceI seq, int start, int end, int x1, int y1, int width, int height) { - int i = start; - int length = seq.getLength(); + int i = start; + int length = seq.getLength(); - int curStart = -1; - int curWidth = width; + int curStart = -1; + int curWidth = width; - Color tempColour = null; + Color tempColour = null; - while (i <= end) - { - resBoxColour = Color.white; + while (i <= end) + { + resBoxColour = Color.white; - if (i < length) + if (i < length) + { + if (inCurrentSequenceGroup(i)) { - if (inCurrentSequenceGroup(i)) - { - if (currentSequenceGroup.getDisplayBoxes()) - { - getBoxColour(currentSequenceGroup.cs, seq, i); - } - } - else if (av.getShowBoxes()) + if (currentSequenceGroup.getDisplayBoxes()) { - getBoxColour(av.getGlobalColourScheme(), seq, i); + getBoxColour(currentSequenceGroup.cs, seq, i); } - + } + else if (av.getShowBoxes()) + { + getBoxColour(av.globalColourScheme, seq, i); } - if (resBoxColour != tempColour) - { - if (tempColour != null) - { - graphics.fillRect(x1 + (width * (curStart - start)), y1, - curWidth, height); - } + } - graphics.setColor(resBoxColour); + if (resBoxColour != tempColour) + { + if (tempColour != null) + { + graphics.fillRect(x1 + (width * (curStart - start)), y1, + curWidth, height); + } - curStart = i; - curWidth = width; - tempColour = resBoxColour; - } - else - { - curWidth += width; - } + graphics.setColor(resBoxColour); - i++; - } + curStart = i; + curWidth = width; + tempColour = resBoxColour; + } + else + { + curWidth += width; + } + + i++; + } + + graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth, + height); - graphics.fillRect(x1 + (width * (curStart - start)), y1, curWidth, - height); } /** @@ -208,6 +213,7 @@ public class SequenceRenderer int charOffset = 0; char s; + // Need to find the sequence position here. String sequence = seq.getSequence(); @@ -247,7 +253,7 @@ public class SequenceRenderer if (av.getColourText()) { - getBoxColour(av.getGlobalColourScheme(), seq, i); + getBoxColour(av.globalColourScheme, seq, i); if (av.getShowBoxes()) { @@ -263,6 +269,7 @@ public class SequenceRenderer charOffset = (width - fm.charWidth(s)) / 2; graphics.drawString(String.valueOf(s), charOffset + x1 + (int)(width * (i - start)), (y1 + height) - pady); + } } diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 20624af..05f412f 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -127,11 +127,13 @@ public class SplashScreen extends JPanel implements Runnable int y = yoffset; - g.drawString("Jalview 2005 ", 50, y); + g.drawString("Jalview "+jalview.bin.Cache.getProperty("VERSION"), 50, y); + + FontMetrics fm = g.getFontMetrics(); + int vwidth = fm.stringWidth("Jalview "+jalview.bin.Cache.getProperty("VERSION")); g.setFont(new Font("Verdana", Font.BOLD, fontSize + 2)); - g.drawString("Version " + jalview.bin.Cache.getProperty("VERSION") + - "; Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"), - 180, y); + g.drawString("Last updated: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"), + 50 + vwidth +5, y); if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals("Checking")) {