X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=298688be727e55111dbeefc645a1a1fb162987cc;hb=0b0b3d3687479204da2d199042c7bc90f3a6fd43;hp=c78abdce73c30986a4fc5f80222a16988f07a374;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index c78abdc..298688b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -163,8 +163,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignViewport viewport; - ViewportRanges vpRanges; - public AlignViewControllerI avc; List alignPanels = new ArrayList<>(); @@ -336,7 +334,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, progressBar = new ProgressBar(this.statusPanel, this.statusBar); } - vpRanges = viewport.getRanges(); avc = new jalview.controller.AlignViewController(this, viewport, alignPanel); if (viewport.getAlignmentConservationAnnotation() == null) @@ -654,9 +651,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) { - alignPanel.getSeqPanel().seqCanvas.cursorX = vpRanges + ViewportRanges ranges = viewport.getRanges(); + alignPanel.getSeqPanel().seqCanvas.cursorX = ranges .getStartRes(); - alignPanel.getSeqPanel().seqCanvas.cursorY = vpRanges + alignPanel.getSeqPanel().seqCanvas.cursorY = ranges .getStartSeq(); } alignPanel.getSeqPanel().seqCanvas.repaint(); @@ -689,10 +687,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, break; } case KeyEvent.VK_PAGE_UP: - vpRanges.pageUp(); + viewport.getRanges().pageUp(); break; case KeyEvent.VK_PAGE_DOWN: - vpRanges.pageDown(); + viewport.getRanges().pageDown(); break; } } @@ -1711,7 +1709,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } synchronized void slideSequences(boolean right, int size) @@ -2147,7 +2145,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // propagate alignment changed. - vpRanges.setEndSeq(alignment.getHeight()); + viewport.getRanges().setEndSeq(alignment.getHeight()); if (annotationAdded) { // Duplicate sequence annotation in all views. @@ -2397,7 +2395,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -2423,7 +2421,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // JAL-2034 - should delegate to // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); } @@ -2444,12 +2442,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); - alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null); alignPanel.getIdPanel().getIdCanvas().searchResults = null; // JAL-2034 - should delegate to // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); viewport.sendSelection(); } @@ -2480,7 +2477,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); viewport.sendSelection(); } @@ -2489,7 +2486,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void invertColSel_actionPerformed(ActionEvent e) { viewport.invertColumnSelection(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); viewport.sendSelection(); } @@ -2549,7 +2546,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { trimRegion = new TrimRegionCommand("Remove Left", true, seqs, column, viewport.getAlignment()); - vpRanges.setStartRes(0); + viewport.getRanges().setStartRes(0); } else { @@ -2614,13 +2611,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(vpRanges.getStartRes()); + ViewportRanges ranges = viewport.getRanges(); + int startRes = seq.findPosition(ranges.getStartRes()); // ShiftList shifts; // viewport.getAlignment().removeGaps(shifts=new ShiftList()); // edit.alColumnChanges=shifts.getInverse(); // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); - vpRanges.setStartRes(seq.findIndex(startRes) - 1); + ranges.setStartRes(seq.findIndex(startRes) - 1); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); @@ -2653,12 +2651,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(vpRanges.getStartRes()); + int startRes = seq.findPosition(viewport.getRanges().getStartRes()); addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end, viewport.getAlignment())); - vpRanges.setStartRes(seq.findIndex(startRes) - 1); + viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); @@ -2714,8 +2712,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * Create a new AlignmentPanel (with its own, new Viewport) */ - AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel, - true); + AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel); if (!copyAnnotation) { /* @@ -2869,21 +2866,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.getIdPanel().getIdCanvas() .setPreferredSize(alignPanel.calculateIdWidth()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } @Override public void idRightAlign_actionPerformed(ActionEvent e) { viewport.setRightAlignIds(idRightAlign.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } @Override public void centreColumnLabels_actionPerformed(ActionEvent e) { viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /* @@ -2916,7 +2913,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void colourTextMenuItem_actionPerformed(ActionEvent e) { viewport.setColourText(colourTextMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -2945,7 +2942,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void showAllColumns_actionPerformed(ActionEvent e) { viewport.showAllHiddenColumns(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3049,7 +3046,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.expandColSelection(sg, false); viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3065,7 +3062,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.showAllHiddenColumns(); viewport.showAllHiddenSeqs(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3073,7 +3070,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideSelColumns_actionPerformed(ActionEvent e) { viewport.hideSelectedColumns(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3094,7 +3091,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleAbove_actionPerformed(ActionEvent e) { viewport.setScaleAboveWrapped(scaleAbove.isSelected()); - alignPanel.paintAlignment(true); + // TODO: do we actually need to update overview for scale above change ? + alignPanel.paintAlignment(true, false); } /** @@ -3107,7 +3105,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleLeft_actionPerformed(ActionEvent e) { viewport.setScaleLeftWrapped(scaleLeft.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3120,7 +3118,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleRight_actionPerformed(ActionEvent e) { viewport.setScaleRightWrapped(scaleRight.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3133,7 +3131,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -3146,7 +3144,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void viewTextMenuItem_actionPerformed(ActionEvent e) { viewport.setShowText(viewTextMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -3159,7 +3157,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void renderGapsMenuItem_actionPerformed(ActionEvent e) { viewport.setRenderGaps(renderGapsMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } public FeatureSettings featureSettings; @@ -3197,7 +3195,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void showSeqFeatures_actionPerformed(ActionEvent evt) { viewport.setShowSequenceFeatures(showSeqFeatures.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } /** @@ -3354,7 +3352,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setGlobalColourScheme(cs); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } /** @@ -3439,7 +3437,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment().getSequenceAt(0)); addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3455,7 +3453,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentSorter.sortByID(viewport.getAlignment()); addHistoryItem( new OrderCommand("ID Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3471,7 +3469,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentSorter.sortByLength(viewport.getAlignment()); addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3488,7 +3486,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3645,7 +3643,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } }); } @@ -3674,7 +3672,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment());// ,viewport.getSelectionGroup()); addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } }); } @@ -3789,7 +3787,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.getAlignment())); } - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); return true; } @@ -4387,7 +4385,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); - List files = new ArrayList<>(); + final AlignFrame thisaf = this; + final List files = new ArrayList<>(); List protocols = new ArrayList<>(); try @@ -4399,133 +4398,146 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (files != null) { - try + new Thread(new Runnable() { - // check to see if any of these files have names matching sequences in - // the alignment - SequenceIdMatcher idm = new SequenceIdMatcher( - viewport.getAlignment().getSequencesArray()); - /** - * Object[] { String,SequenceI} - */ - ArrayList filesmatched = new ArrayList<>(); - ArrayList filesnotmatched = new ArrayList<>(); - for (int i = 0; i < files.size(); i++) + @Override + public void run() { - String file = files.get(i).toString(); - String pdbfn = ""; - DataSourceType protocol = FormatAdapter.checkProtocol(file); - if (protocol == DataSourceType.FILE) - { - File fl = new File(file); - pdbfn = fl.getName(); - } - else if (protocol == DataSourceType.URL) - { - URL url = new URL(file); - pdbfn = url.getFile(); - } - if (pdbfn.length() > 0) + try { - // attempt to find a match in the alignment - SequenceI[] mtch = idm.findAllIdMatches(pdbfn); - int l = 0, c = pdbfn.indexOf("."); - while (mtch == null && c != -1) + // check to see if any of these files have names matching sequences + // in + // the alignment + SequenceIdMatcher idm = new SequenceIdMatcher( + viewport.getAlignment().getSequencesArray()); + /** + * Object[] { String,SequenceI} + */ + ArrayList filesmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); + for (int i = 0; i < files.size(); i++) { - do - { - l = c; - } while ((c = pdbfn.indexOf(".", l)) > l); - if (l > -1) + String file = files.get(i).toString(); + String pdbfn = ""; + DataSourceType protocol = FormatAdapter.checkProtocol(file); + if (protocol == DataSourceType.FILE) { - pdbfn = pdbfn.substring(0, l); + File fl = new File(file); + pdbfn = fl.getName(); } - mtch = idm.findAllIdMatches(pdbfn); - } - if (mtch != null) - { - FileFormatI type = null; - try - { - type = new IdentifyFile().identify(file, protocol); - } catch (Exception ex) + else if (protocol == DataSourceType.URL) { - type = null; + URL url = new URL(file); + pdbfn = url.getFile(); } - if (type != null && type.isStructureFile()) + if (pdbfn.length() > 0) { - filesmatched.add(new Object[] { file, protocol, mtch }); - continue; + // attempt to find a match in the alignment + SequenceI[] mtch = idm.findAllIdMatches(pdbfn); + int l = 0, c = pdbfn.indexOf("."); + while (mtch == null && c != -1) + { + do + { + l = c; + } while ((c = pdbfn.indexOf(".", l)) > l); + if (l > -1) + { + pdbfn = pdbfn.substring(0, l); + } + mtch = idm.findAllIdMatches(pdbfn); + } + if (mtch != null) + { + FileFormatI type = null; + try + { + type = new IdentifyFile().identify(file, protocol); + } catch (Exception ex) + { + type = null; + } + if (type != null && type.isStructureFile()) + { + filesmatched.add(new Object[] { file, protocol, mtch }); + continue; + } + } + // File wasn't named like one of the sequences or wasn't a PDB + // file. + filesnotmatched.add(file); } } - // File wasn't named like one of the sequences or wasn't a PDB file. - filesnotmatched.add(file); - } - } - int assocfiles = 0; - if (filesmatched.size() > 0) - { - if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) - || JvOptionPane.showConfirmDialog(this, - MessageManager.formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] - { Integer.valueOf(filesmatched.size()) - .toString() }), - MessageManager.getString( - "label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - - { - for (Object[] fm : filesmatched) + int assocfiles = 0; + if (filesmatched.size() > 0) { - // try and associate - // TODO: may want to set a standard ID naming formalism for - // associating PDB files which have no IDs. - for (SequenceI toassoc : (SequenceI[]) fm[2]) + if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) + || JvOptionPane.showConfirmDialog(thisaf, + MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }), + MessageManager.getString( + "label.automatically_associate_structure_files_by_name"), + JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) + { - PDBEntry pe = new AssociatePdbFileWithSeq() - .associatePdbWithSeq((String) fm[0], - (DataSourceType) fm[1], toassoc, false, - Desktop.instance); - if (pe != null) + for (Object[] fm : filesmatched) { - System.err.println("Associated file : " + ((String) fm[0]) - + " with " + toassoc.getDisplayId(true)); - assocfiles++; + // try and associate + // TODO: may want to set a standard ID naming formalism for + // associating PDB files which have no IDs. + for (SequenceI toassoc : (SequenceI[]) fm[2]) + { + PDBEntry pe = new AssociatePdbFileWithSeq() + .associatePdbWithSeq((String) fm[0], + (DataSourceType) fm[1], toassoc, false, + Desktop.instance); + if (pe != null) + { + System.err.println("Associated file : " + + ((String) fm[0]) + " with " + + toassoc.getDisplayId(true)); + assocfiles++; + } + } + // TODO: do we need to update overview ? only if features are + // shown I guess + alignPanel.paintAlignment(true, false); } } - alignPanel.paintAlignment(true); } - } - } - if (filesnotmatched.size() > 0) - { - if (assocfiles > 0 && (Cache.getDefault( - "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) - || JvOptionPane.showConfirmDialog(this, - "" + MessageManager.formatMessage( - "label.ignore_unmatched_dropped_files_info", - new Object[] - { Integer.valueOf(filesnotmatched.size()) - .toString() }) - + "", - MessageManager.getString( - "label.ignore_unmatched_dropped_files"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) - { - return; - } - for (String fn : filesnotmatched) + if (filesnotmatched.size() > 0) + { + if (assocfiles > 0 && (Cache.getDefault( + "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) + || JvOptionPane.showConfirmDialog(thisaf, + "" + MessageManager.formatMessage( + "label.ignore_unmatched_dropped_files_info", + new Object[] + { Integer.valueOf( + filesnotmatched.size()) + .toString() }) + + "", + MessageManager.getString( + "label.ignore_unmatched_dropped_files"), + JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) + { + return; + } + for (String fn : filesnotmatched) + { + loadJalviewDataFile(fn, null, null, null); + } + + } + } catch (Exception ex) { - loadJalviewDataFile(fn, null, null, null); + ex.printStackTrace(); } - } - } catch (Exception ex) - { - ex.printStackTrace(); - } + }).start(); } } @@ -4639,7 +4651,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (parseFeaturesFile(file, sourceType)) { - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } else @@ -4654,7 +4666,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.adjustAnnotationHeight(); viewport.updateSequenceIdColours(); buildSortByAnnotationScoresMenu(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } catch (Exception ex) { @@ -5179,7 +5191,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void showUnconservedMenuItem_actionPerformed(ActionEvent e) { viewport.setShowUnconserved(showNonconservedMenuItem.getState()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /* @@ -5268,7 +5280,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -5280,7 +5292,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment().setSeqrep(null); PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -5370,7 +5382,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder()); this.alignPanel.av .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /**