X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=b2fa937ab49feded54ba1865427440b82a718a38;hb=49722127cdfb9c1dc5b736733c4c5204941a4f84;hp=4afaf92e70e3e0680f82e745c4717b9a9fc42e1d;hpb=b21920d2355ae42bdada6dfc0c42614aa0539137;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 4afaf92..b2fa937 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -310,7 +310,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener SequenceGroup sg = viewport.getSelectionGroup(); if (toggleSeqs) { - if (sg != null && sg.getSize(false) != viewport.alignment.getHeight()) + if (sg != null && sg.getSize() != viewport.alignment.getHeight()) { hideSelSequences_actionPerformed(null); hide = true; @@ -592,7 +592,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener dset.deleteSequence(0); } - firePropertyChange("Alignment", null, null); + firePropertyChange("Alignment", null, viewport.alignment.getSequences()); updateEditMenuBar(); } @@ -618,7 +618,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener public void save_actionPerformed(ActionEvent e) { - if(fileName==null || currentFileFormat==null) + if(fileName==null + || currentFileFormat==null + || fileName.startsWith("http") + ) saveAs_actionPerformed(null); else saveAlignment(fileName, currentFileFormat); @@ -673,6 +676,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener public boolean saveAlignment(String file, String format) { + boolean success = true; + if (format.equalsIgnoreCase("Jalview")) { String shortName = title; @@ -683,15 +688,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener java.io.File.separatorChar) + 1); } - new Jalview2XML().SaveAlignment(this, file, shortName); + success = new Jalview2XML().SaveAlignment(this, file, shortName); statusBar.setText("Successfully saved to file: " +fileName+" in " +format +" format."); - - // USE Jalview2XML to save this file - return true; } else { @@ -717,28 +719,37 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener if (output == null) { - return false; - } - - try - { - java.io.PrintWriter out = new java.io.PrintWriter( - new java.io.FileWriter(file)); - - out.print(output); - out.close(); - this.setTitle(file); - statusBar.setText("Successfully saved to file: " - +fileName+" in " - +format +" format."); - return true; + success = false; } - catch (Exception ex) + else { - ex.printStackTrace(); + try + { + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter(file)); + + out.print(output); + out.close(); + this.setTitle(file); + statusBar.setText("Successfully saved to file: " + + fileName + " in " + + format + " format."); + } + catch (Exception ex) + { + success = false; + ex.printStackTrace(); + } } } - return false; + + if (!success) + JOptionPane.showInternalMessageDialog( + this, "Couldn't save file: " + fileName, + "Error Saving File", + JOptionPane.WARNING_MESSAGE); + + return success; } /** @@ -814,6 +825,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener alignPanel.makeEPS(f); } + + public void pageSetup_actionPerformed(ActionEvent e) + { + PrinterJob printJob = PrinterJob.getPrinterJob(); + PrintThread.pf = printJob.pageDialog(printJob.defaultPage()); + } + /** * DOCUMENT ME! * @@ -822,7 +840,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener public void printMenuItem_actionPerformed(ActionEvent e) { //Putting in a thread avoids Swing painting problems - PrintThread thread = new PrintThread(); + PrintThread thread = new PrintThread(alignPanel); thread.start(); } @@ -979,7 +997,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener if(originalSource!=null) { originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; - originalSource.firePropertyChange("alignment", null,null); + originalSource.firePropertyChange("alignment", + null, + originalSource.alignment.getSequences()); } } @@ -990,6 +1010,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener */ protected void redoMenuItem_actionPerformed(ActionEvent e) { + if(viewport.redoList.size()<1) + return; + CommandI command = (CommandI) viewport.redoList.pop(); viewport.historyList.push(command); command.doCommand(); @@ -1000,7 +1023,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener if(originalSource!=null) { originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; - originalSource.firePropertyChange("alignment", null,null); + originalSource.firePropertyChange("alignment", + null, + originalSource.alignment.getSequences()); } } @@ -1010,12 +1035,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener //For sequence removal and addition, we need to fire //the property change event FROM the viewport where the //original alignment was altered + AlignmentI al=null; if (command instanceof EditCommand) { EditCommand editCommand = (EditCommand) command; - AlignmentI al = editCommand.getAlignment(); + al = editCommand.getAlignment(); Vector comps = (Vector) PaintRefresher.components .get(viewport.getSequenceSetId()); + for (int i = 0; i < comps.size(); i++) { if (comps.elementAt(i) instanceof AlignmentPanel) @@ -1027,17 +1054,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener } } } - if (originalSource == null) - { - //The original view is closed, we must validate - //the current view against the closed view first + } + + if (originalSource == null) + { + //The original view is closed, we must validate + //the current view against the closed view first + if (al != null) PaintRefresher.validateSequences(al, viewport.alignment); - originalSource = viewport; - } + originalSource = viewport; } - return originalSource; } @@ -1061,14 +1089,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener { SequenceI seq = viewport.alignment.getSequenceAt(i); - if (!sg.getSequences(false).contains(seq)) + if (!sg.getSequences(null).contains(seq)) { continue; } SequenceI temp = viewport.alignment.getSequenceAt(i - 1); - if (sg.getSequences(false).contains(temp)) + if (sg.getSequences(null).contains(temp)) { continue; } @@ -1083,14 +1111,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener { SequenceI seq = viewport.alignment.getSequenceAt(i); - if (!sg.getSequences(false).contains(seq)) + if (!sg.getSequences(null).contains(seq)) { continue; } SequenceI temp = viewport.alignment.getSequenceAt(i + 1); - if (sg.getSequences(false).contains(temp)) + if (sg.getSequences(null).contains(temp)) { continue; } @@ -1135,6 +1163,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener try { + jalview.gui.Desktop.internalCopy = true; //Its really worth setting the clipboard contents //to empty before setting the large StringSelection!! Toolkit.getDefaultToolkit().getSystemClipboard() @@ -1262,7 +1291,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener } else { - sequences = new FormatAdapter().readFile(str, "Paste", format); + sequences = new FormatAdapter().readFile(str, "Paste", format).getSequencesArray(); } AlignmentI alignment = null; @@ -1414,7 +1443,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener Vector seqs = new Vector(); SequenceI seq; - for (int i = 0; i < sg.getSize(false); i++) + for (int i = 0; i < sg.getSize(); i++) { seq = sg.getSequenceAt(i); seqs.addElement(seq); @@ -1422,7 +1451,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener // If the cut affects all sequences, remove highlighted columns - if (sg.getSize(false) == viewport.alignment.getHeight()) + if (sg.getSize() == viewport.alignment.getHeight()) { viewport.getColumnSelection().removeElements(sg.getStartRes(), sg.getEndRes() + 1); @@ -1471,7 +1500,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener protected void deleteGroups_actionPerformed(ActionEvent e) { viewport.alignment.deleteAllGroups(); - viewport.sequenceColours.clear(); + viewport.sequenceColours = null; viewport.setSelectionGroup(null); PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.repaint(); @@ -1541,6 +1570,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false); } + alignPanel.repaint(); + PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); } @@ -1585,7 +1616,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener SequenceI [] seqs; if(viewport.getSelectionGroup()!=null) - seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences); else seqs = viewport.alignment.getSequencesArray(); @@ -1648,7 +1679,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener SequenceI[] seqs; if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences); start = viewport.getSelectionGroup().getStartRes(); end = viewport.getSelectionGroup().getEndRes(); } @@ -1692,7 +1723,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener SequenceI[] seqs; if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences); start = viewport.getSelectionGroup().getStartRes(); end = viewport.getSelectionGroup().getEndRes(); } @@ -2207,7 +2238,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener if (cs instanceof ClustalxColourScheme) { sg.cs = new ClustalxColourScheme( - sg.getSequences(true), sg.getWidth()); + sg.getSequences(viewport.hiddenRepSequences), sg.getWidth()); } else if (cs instanceof UserColourScheme) { @@ -2232,7 +2263,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener viewport.getIgnoreGapsConsensus()); sg.cs.setConsensus(AAFrequency.calculate( - sg.getSequences(true), sg.getStartRes(), + sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(), sg.getEndRes()+1)); } else @@ -2243,7 +2274,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener { Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, - sg.getSequences(true), + sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(), sg.getEndRes()+1); c.calculate(); @@ -2495,7 +2526,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { if ( (viewport.getSelectionGroup() == null) || - (viewport.getSelectionGroup().getSize(false) < 2)) + (viewport.getSelectionGroup().getSize() < 2)) { JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", @@ -2518,8 +2549,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener public void PCAMenuItem_actionPerformed(ActionEvent e) { if ( ( (viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize(false) < 4) && - (viewport.getSelectionGroup().getSize(false) > 0)) || + (viewport.getSelectionGroup().getSize() < 4) && + (viewport.getSelectionGroup().getSize() > 0)) || (viewport.getAlignment().getHeight() < 4)) { JOptionPane.showInternalMessageDialog(this, @@ -2599,7 +2630,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener TreePanel tp; if (viewport.getSelectionGroup() != null) { - if (viewport.getSelectionGroup().getSize(false) < 3) { + if (viewport.getSelectionGroup().getSize() < 3) { JOptionPane.showMessageDialog(Desktop.desktop, "You need to have more than two sequences selected to build a tree!", "Not enough sequences", @@ -2611,9 +2642,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener SequenceGroup sg = viewport.getSelectionGroup(); /* Decide if the selection is a column region */ - while (s < sg.getSize(false)) + while (s < sg.getSize()) { - if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() < + if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg.getEndRes()) { JOptionPane.showMessageDialog(Desktop.desktop, @@ -2651,9 +2682,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener tp = new TreePanel(alignPanel, type, pwType); } - title = title + " from " + this.title; + title += " from "; + if(viewport.viewName!=null) - title+= " ("+viewport.viewName+")"; + title+= viewport.viewName+" of "; + + title += this.title; Desktop.addInternalFrame(tp, title, 600, 500); } @@ -2753,7 +2787,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener AlignmentView msa = null; if ( (viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize(false) > 1)) + (viewport.getSelectionGroup().getSize() > 1)) { // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! /*SequenceGroup seqs = viewport.getSelectionGroup(); @@ -2795,7 +2829,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener AlignmentView seqs = null; if ( (viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize(false) > 0)) + (viewport.getSelectionGroup().getSize() > 0)) { seqs = viewport.getAlignmentView(true); } @@ -2905,28 +2939,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener return tp; } - class PrintThread - extends Thread - { - public void run() - { - PrinterJob printJob = PrinterJob.getPrinterJob(); - PageFormat pf = printJob.pageDialog(printJob.defaultPage()); - printJob.setPrintable(alignPanel, pf); - - if (printJob.printDialog()) - { - try - { - printJob.print(); - } - catch (Exception PrintException) - { - PrintException.printStackTrace(); - } - } - } - } /** * Generates menu items and listener event actions for web service clients @@ -3261,7 +3273,7 @@ public void drop(DropTargetDropEvent evt) } boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport. - alignment, file); + alignment, file, protocol); if (!isAnnotation) { @@ -3329,3 +3341,34 @@ public void drop(DropTargetDropEvent evt) return viewport; } } + +class PrintThread extends Thread +{ + AlignmentPanel ap; + public PrintThread(AlignmentPanel ap) + { + this.ap = ap; + } + static PageFormat pf; + public void run() + { + PrinterJob printJob = PrinterJob.getPrinterJob(); + + if (pf != null) + printJob.setPrintable(ap, pf); + else + printJob.setPrintable(ap); + + if (printJob.printDialog()) + { + try + { + printJob.print(); + } + catch (Exception PrintException) + { + PrintException.printStackTrace(); + } + } + } +}