diff --git a/config/preferences.yaml b/config/preferences.yaml index 574093c..185e8b6 100644 --- a/config/preferences.yaml +++ b/config/preferences.yaml @@ -2,11 +2,11 @@ GOlrURL: http://golr.geneontology.org/solr bpPaintColor: !color '138, 190, 204, 255' ccPaintColor: !color '138, 204, 177, 255' -collapse_no_exp: false +collapse_no_exp: true curatedPaintColor: !color '255, 204, 0, 255' expPaintColor: !color '61, 153, 61, 255' full_msa: false -gafdir: /Users/suzi/projects/go/gene-associations/submission/paint/PTHR32175/ +gafdir: /Users/suzi/projects/go/gene-associations/submission/paint/PTHR18896/ inferPaintColor: !color '61, 100, 153, 255' mfPaintColor: !color '177, 204, 138, 255' msa_colors: @@ -23,7 +23,7 @@ msa_weighted_colors: msa_weighted_threshold: - 90.0 - 75.0 -tree_distance_scaling: 50.0 +tree_distance_scaling: 25.0 treedir: /Users/suzi/projects/go/data/trees/panther/ use_distances: true weighted: true diff --git a/resources/org/paint/resources/VERSION b/resources/org/paint/resources/VERSION index 6f2ff79..d527e14 100755 --- a/resources/org/paint/resources/VERSION +++ b/resources/org/paint/resources/VERSION @@ -1 +1 @@ -v2.22 \ No newline at end of file +v2.23 \ No newline at end of file diff --git a/src/org/paint/dialog/TaxonDialog.java b/src/org/paint/dialog/TaxonDialog.java new file mode 100644 index 0000000..5146b4a --- /dev/null +++ b/src/org/paint/dialog/TaxonDialog.java @@ -0,0 +1,144 @@ +/* + * + * Copyright (c) 2010, Regents of the University of California + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Neither the name of the Lawrence Berkeley National Lab nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.paint.dialog; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; + +import org.bbop.phylo.util.OWLutil; +import org.paint.util.RenderUtil; + +import owltools.gaf.species.TaxonFinder; + +public class TaxonDialog extends JDialog { + /** + * + */ + private static final long serialVersionUID = 1L; + + Map selections; + boolean loss; + + /** Creates the GUI shown inside the frame's content pane. */ + public TaxonDialog(Frame frame, String go_id, List invalids) { + super(frame, true); + setLayout(new BorderLayout()); + setContentPane(taxonPane(go_id, invalids)); + pack(); + setLocationRelativeTo(frame); + setVisible(true); + } + + public boolean isLost() { + // this.paintComponents(this.getGraphics()); + return loss; + } + + private JPanel taxonPane (String go_id, List invalids) { + JPanel qualify = new JPanel(); + qualify.setLayout(new BoxLayout(qualify, BoxLayout.PAGE_AXIS)); + + //Create the components. + JPanel selectionPane = createTaxaListPane(go_id, invalids); + + //Lay them out. + + JPanel buttonPane = new JPanel(); + buttonPane.setOpaque(true); + buttonPane.setBackground(RenderUtil.getAspectColor()); + JButton lossButton = null; + lossButton = new JButton("Set as loss"); + lossButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + loss = true; + TaxonDialog.this.dispose(); + } + } ); + JButton cancelButton = null; + cancelButton = new JButton("Cancel"); + getRootPane().setDefaultButton(cancelButton); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + loss = false; + TaxonDialog.this.dispose(); + } + } ); + + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(lossButton); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPane.add(cancelButton); + buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); + + qualify.add(selectionPane); + qualify.add(buttonPane); + return qualify; + } + + /** Creates the panel shown by the first tab. */ + private JPanel createTaxaListPane(String go_id, List invalids) { + String description; + description = "Do you intend the evolutionary loss of " + OWLutil.inst().getTermLabel(go_id) + " in these taxa?"; + + JPanel box = new JPanel(); + JLabel label = new JLabel(description); + label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); + box.setOpaque(true); + box.setBackground(RenderUtil.getAspectColor()); + + box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS)); + box.add(label); + + for (String taxon : invalids) { + label = new JLabel(TaxonFinder.getSpecies(taxon)); + label.setBackground(Color.white); + label.setOpaque(true); + box.add(label); + } + JPanel pane = new JPanel(new BorderLayout()); + pane.add(box, BorderLayout.PAGE_START); + Border padding = BorderFactory.createEmptyBorder(20,20,5,20); + pane.setBorder(padding); + pane.setOpaque(true); + pane.setBackground(RenderUtil.getAspectColor()); + return pane; + } + +} diff --git a/src/org/paint/displaymodel/DisplayTree.java b/src/org/paint/displaymodel/DisplayTree.java index 92d067a..1d7f372 100644 --- a/src/org/paint/displaymodel/DisplayTree.java +++ b/src/org/paint/displaymodel/DisplayTree.java @@ -31,8 +31,6 @@ import org.apache.log4j.Logger; import org.bbop.phylo.annotate.AnnotationUtil; import org.bbop.phylo.model.Tree; -import org.paint.gui.event.EventManager; -import org.paint.gui.event.NodeReorderEvent; import org.paint.main.PaintManager; import org.paint.util.DuplicationColor; @@ -147,13 +145,13 @@ private void resetExpansion(Bioentity dsn){ */ private void expandAllNodes(Bioentity dsn){ resetExpansion(dsn); - nodesReordered(); + initCurrentNodes(); } public void collapseNonExperimental() { resetExpansion(root); collapseMRC (root); - nodesReordered(); + initCurrentNodes(); } private void collapseMRC(Bioentity mrc) { @@ -181,14 +179,6 @@ public Bioentity getCurrentRoot(){ return currentRoot; } - // Method to set number of leaves in tree - public void nodesReordered() { - initCurrentNodes(); - NodeReorderEvent event = new NodeReorderEvent(this); - event.setNodes(getTerminusNodes()); - EventManager.inst().fireNodeReorderEvent(event); - } - private void setDupColorIndex(Bioentity node, int color_index) { ((DisplayBioentity) node).setDupColorIndex(color_index); if (!node.isLeaf()) { @@ -246,7 +236,7 @@ public void handleCollapseExpand(DisplayBioentity node) { boolean change = (node != null && !node.isLeaf() && !node.isPruned()); if (change) { setNodeExpanded(node); - nodesReordered(); + initCurrentNodes(); } } @@ -264,7 +254,7 @@ public void handleCollapseExpand(List nodes) { public boolean handlePruning(DisplayBioentity node) { boolean change = (node != null && !node.isLeaf()); if (change) { - nodesReordered(); + initCurrentNodes(); } return change; } @@ -277,7 +267,7 @@ protected boolean resetToRoot(Bioentity dsn){ // If it is not the current root, make it the current root if (currentRoot != dsn){ currentRoot = dsn; - nodesReordered(); + initCurrentNodes(); return true; } else return false; @@ -299,7 +289,7 @@ public void speciesOrder() { bioentities.clear(); addChildNodesInOrder(currentRoot, bioentities); // Save new ordering that are visible as well - nodesReordered(); + initCurrentNodes(); } public void descendentCountLadder(boolean most_leaves_at_top) { @@ -315,7 +305,7 @@ public void descendentCountLadder(boolean most_leaves_at_top) { bioentities.clear(); addChildNodesInOrder(currentRoot, bioentities); // Save new ordering that are visible as well - nodesReordered(); + initCurrentNodes(); } /** diff --git a/src/org/paint/gui/association/AssociationsTable.java b/src/org/paint/gui/association/AssociationsTable.java index 7500c45..050a556 100644 --- a/src/org/paint/gui/association/AssociationsTable.java +++ b/src/org/paint/gui/association/AssociationsTable.java @@ -263,7 +263,7 @@ else if (String.class == assoc_model.getColumnClass(column)) { /* * This ought to be a regain */ - log.debug("Association table value = " + value.toString()); + log.info("Association table value = " + value.toString()); } } else if (GeneAnnotation.class == assoc_model.getColumnClass(column)) { GeneAnnotation assoc = (GeneAnnotation) assoc_model.getValueAt(row, column); diff --git a/src/org/paint/gui/association/TrashCellRenderer.java b/src/org/paint/gui/association/TrashCellRenderer.java index c727798..ead7718 100644 --- a/src/org/paint/gui/association/TrashCellRenderer.java +++ b/src/org/paint/gui/association/TrashCellRenderer.java @@ -53,7 +53,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole text = ""; break; case DEPENDENCIES: - text = "Loss is contraindicated by exp. annotations"; + text = "Loss would be contraindicated by exp. annotations"; break; } setText(text); diff --git a/src/org/paint/gui/matrix/AnnotMatrix.java b/src/org/paint/gui/matrix/AnnotMatrix.java index ce3cb19..082e47f 100644 --- a/src/org/paint/gui/matrix/AnnotMatrix.java +++ b/src/org/paint/gui/matrix/AnnotMatrix.java @@ -23,6 +23,9 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.HashMap; @@ -30,6 +33,8 @@ import java.util.Map; import java.util.Set; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.TransferHandler; @@ -38,6 +43,15 @@ import javax.swing.table.TableColumnModel; import org.apache.log4j.Logger; +import org.bbop.framework.GUIManager; +import org.bbop.phylo.annotate.PaintAction; +import org.bbop.phylo.annotate.WithEvidence; +import org.bbop.phylo.model.Tree; +import org.bbop.phylo.tracking.LogEntry; +import org.bbop.phylo.util.OWLutil; +import org.bbop.phylo.util.TaxonChecker; +import org.paint.dialog.QualifierDialog; +import org.paint.dialog.TaxonDialog; import org.paint.displaymodel.DisplayBioentity; import org.paint.gui.AspectSelector; import org.paint.gui.FamilyViews; @@ -60,6 +74,7 @@ import org.paint.gui.tree.TreePanel; import org.paint.main.PaintManager; import org.paint.util.GuiConstant; +import org.paint.util.RenderUtil; import owltools.gaf.Bioentity; import owltools.gaf.GeneAnnotation; @@ -231,7 +246,7 @@ public void handleChallengeEvent(ChallengeEvent event) { models.put(aspect_name, annot_model); setModel(annot_model); annot_model.fireTableStructureChanged(); -// repaint(); + // repaint(); } public void handleTermEvent(TermSelectEvent e) { @@ -355,57 +370,60 @@ public void mousePressed(MouseEvent event) { Point point = event.getPoint(); int row = rowAtPoint(point); if (row >= 0 && row < getRowCount()) { - List previous_genes = EventManager.inst().getCurrentGeneSelection(); - List selected_genes = null; - if (!event.isMetaDown() && !event.isShiftDown() && !event.isAltDown() && !event.isControlDown()) { - int column = columnAtPoint(point); - String term = ((AnnotMatrixModel)getModel()).getTermForColumn(column); + int modifiers = event.getModifiers(); + /* + * Left mouse button selects the column/term and all genes annotated to that term + */ + if ((InputEvent.BUTTON1_MASK == (modifiers & InputEvent.BUTTON1_MASK)) && + (!event.isMetaDown() && !event.isShiftDown() && !event.isAltDown() && !event.isControlDown())) { + String term = getTermAtPoint(event.getPoint()); if (term != null) { - AnnotMatrixModel model = (AnnotMatrixModel) this.getModel(); - TermSelectEvent term_event = new TermSelectEvent (this, term, model.getNode(row)); + List selected_genes = null; + List previous_genes = EventManager.inst().getCurrentGeneSelection(); + TermSelectEvent term_event = new TermSelectEvent (this, term); selected_genes = EventManager.inst().fireTermEvent(term_event); - setSelectedColumn(column); + setSelectedColumn(columnAtPoint(event.getPoint())); if (previous_genes != null) { for (Bioentity node : previous_genes) { ((DisplayBioentity) node).setSelected(false); } } + if (selected_genes != null) { + if (previous_genes == null) { + updateRows(selected_genes); + } + else if (previous_genes.size() != selected_genes.size()) { + updateRows(previous_genes); + updateRows(selected_genes); + } + else { + boolean need_update = false; + for (Bioentity node : previous_genes) { + need_update |= !selected_genes.contains(node); + } + if (need_update) { + updateRows(previous_genes); + updateRows(selected_genes); + } + } + GeneSelectEvent ge = new GeneSelectEvent (this, selected_genes, EventManager.inst().getAncestralSelection()); + EventManager.inst().fireGeneEvent(ge); + } + annot_handler.exportAsDrag(this, event, TransferHandler.COPY); } } - - if (event.isMetaDown() && !event.isShiftDown() && !event.isAltDown() && !event.isControlDown()) { - int col = columnAtPoint(point); - setSelectedColumn(col); - String term = ((AnnotMatrixModel)getModel()).getTermForColumn(col); - if (term != null) { - TermSelectEvent term_event = new TermSelectEvent (this, term); - selected_genes = EventManager.inst().fireTermEvent(term_event); - } - } - - if (selected_genes != null) { - if (previous_genes == null) { - updateRows(selected_genes); - } - else if (previous_genes.size() != selected_genes.size()) { - updateRows(previous_genes); - updateRows(selected_genes); - } - else { - boolean need_update = false; - for (Bioentity gene : previous_genes) { - need_update |= !selected_genes.contains(gene); - } - if (need_update) { - updateRows(previous_genes); - updateRows(selected_genes); - } + /* + * Right mouse button or left mouse button and the meta-key then show popup to make an annotation + */ + else if (InputEvent.BUTTON3_MASK == (modifiers & InputEvent.BUTTON3_MASK) || + ((InputEvent.BUTTON1_MASK == (modifiers & InputEvent.BUTTON1_MASK)) && + (event.isMetaDown()))) { + JPopupMenu popup = createPopupMenu(event); + if (popup != null) { + RenderUtil.showPopup(popup, event.getComponent(), new Point(event.getX(), event.getY())); } - GeneSelectEvent ge = new GeneSelectEvent (this, selected_genes, EventManager.inst().getAncestralSelection()); - EventManager.inst().fireGeneEvent(ge); } } - annot_handler.exportAsDrag(this, event, TransferHandler.COPY); } public void mouseReleased(MouseEvent arg0) { @@ -448,4 +466,66 @@ public void addAnnotatedColumn(String term, List with_terms) { log.debug("Annotated to " + term + ", but can't find original evidence"); } } + + private JPopupMenu createPopupMenu(MouseEvent e) { + JPopupMenu popup = null; + Bioentity ancestor = EventManager.inst().getAncestralSelection(); + String term = getTermAtPoint(e.getPoint()); + Tree tree = PaintManager.inst().getTree().getTreeModel(); + if (ancestor != null && !ancestor.isLeaf() && !ancestor.isPruned() && term != null) { + popup = new JPopupMenu(); + LogEntry.LOG_ENTRY_TYPE because = PaintAction.inst().isValidTerm(term, ancestor, tree); + if (because != null) { + String invalid_item; + if (because != LogEntry.LOG_ENTRY_TYPE.WRONG_TAXA) + invalid_item = "Annotation of " + ancestor.getSymbol() + " to " + OWLutil.inst().getTermLabel(term) + " " + because; + else + invalid_item = TaxonChecker.getTaxonError(); + popup.add(new JMenuItem(invalid_item)); + } else { + JMenuItem menuItem; + menuItem = new JMenuItem("Annotate " + ancestor.getSymbol() + " to " + OWLutil.inst().getTermLabel(term)); + menuItem.addActionListener(new AnnotateActionListener(ancestor, term)); + popup.add(menuItem); + } + } + return popup; + } + + private class AnnotateActionListener implements ActionListener{ + Bioentity ancestor; + String term; + + AnnotateActionListener(Bioentity node, String term){ + this.ancestor = node; + this.term = term; + } + + public void actionPerformed(ActionEvent e){ + Tree tree = PaintManager.inst().getTree().getTreeModel(); + boolean valid_for_all_descendents = TaxonChecker.checkTaxons(tree, ancestor, term, false); + if (!valid_for_all_descendents) { + List invalid_taxa = TaxonChecker.getInvalidTaxa(ancestor, term); + TaxonDialog taxon_dialog = new TaxonDialog(GUIManager.getManager().getFrame(), term, invalid_taxa); + valid_for_all_descendents = taxon_dialog.isLost(); + } + if (valid_for_all_descendents) { + WithEvidence withs = new WithEvidence(tree, ancestor, term); + int qualifiers = withs.getWithQualifiers(); + if (qualifiers > 0) { + QualifierDialog qual_dialog = new QualifierDialog(GUIManager.getManager().getFrame(), qualifiers); + qualifiers = qual_dialog.getQualifiers(); + } + PaintAction.inst().propagateAssociation(PaintManager.inst().getFamily(), ancestor, term, withs, null, qualifiers); + EventManager.inst().fireAnnotationChangeEvent(new AnnotationChangeEvent(ancestor)); + } + } + + } + + private String getTermAtPoint(Point point) { + int column = columnAtPoint(point); + String term = ((AnnotMatrixModel)getModel()).getTermForColumn(column); + return term; + } } \ No newline at end of file diff --git a/src/org/paint/gui/matrix/AnnotationTransferHandler.java b/src/org/paint/gui/matrix/AnnotationTransferHandler.java index dfc7839..c4f5773 100644 --- a/src/org/paint/gui/matrix/AnnotationTransferHandler.java +++ b/src/org/paint/gui/matrix/AnnotationTransferHandler.java @@ -44,6 +44,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.swing.Icon; @@ -60,6 +61,7 @@ import org.bbop.phylo.util.OWLutil; import org.bbop.phylo.util.TaxonChecker; import org.paint.dialog.QualifierDialog; +import org.paint.dialog.TaxonDialog; import org.paint.displaymodel.DisplayBioentity; import org.paint.gui.event.AnnotationChangeEvent; import org.paint.gui.event.EventManager; @@ -130,14 +132,8 @@ public boolean canImport(TransferHandler.TransferSupport support) { drop_color = Color.red; } else { // see what other implications there may be - boolean valid_for_all_descendents = TaxonChecker.checkTaxons(tree, node, go_id, false); - if (valid_for_all_descendents) { - drop_label = node.getLocalId(); - drop_color = Color.black; - } else { - drop_label = "Not found in all descendents: " + node.getLocalId(); - drop_color = Color.yellow; - } + drop_label = node.getLocalId(); + drop_color = Color.black; } } catch (UnsupportedFlavorException e) { canImport = false; @@ -260,18 +256,23 @@ public boolean importData(TransferHandler.TransferSupport support) { Point p = support.getDropLocation().getDropPoint(); DisplayBioentity node = tree.getClickedInNodeArea(p); - WithEvidence withs = new WithEvidence(tree.getTreeModel(), node, term); - int qualifiers = withs.getWithQualifiers(); - if (qualifiers > 0) { - QualifierDialog qual_dialog = new QualifierDialog(GUIManager.getManager().getFrame(), qualifiers); - qualifiers = qual_dialog.getQualifiers(); + boolean valid_for_all_descendents = TaxonChecker.checkTaxons(tree.getTreeModel(), node, term, false); + if (!valid_for_all_descendents) { + List invalid_taxa = TaxonChecker.getInvalidTaxa(node, term); + TaxonDialog taxon_dialog = new TaxonDialog(GUIManager.getManager().getFrame(), term, invalid_taxa); + valid_for_all_descendents = taxon_dialog.isLost(); + } + if (valid_for_all_descendents) { + WithEvidence withs = new WithEvidence(tree.getTreeModel(), node, term); + int qualifiers = withs.getWithQualifiers(); + if (qualifiers > 0) { + QualifierDialog qual_dialog = new QualifierDialog(GUIManager.getManager().getFrame(), qualifiers); + qualifiers = qual_dialog.getQualifiers(); + } + PaintAction.inst().propagateAssociation(PaintManager.inst().getFamily(), node, term, withs, null, qualifiers); + EventManager.inst().fireAnnotationChangeEvent(new AnnotationChangeEvent(node)); } - PaintAction.inst().propagateAssociation(PaintManager.inst().getFamily(), node, term, withs, null, qualifiers); - clearVisitedNodes(tree); - - EventManager.inst().fireAnnotationChangeEvent(new AnnotationChangeEvent(node)); - return true; } @@ -380,7 +381,7 @@ public void dragGestureRecognized(DragGestureEvent dge) log.error("Unable to get term name, io problem"); } catch (Exception e) { th.exportDone(c, t, TransferHandler.NONE); -// log.error(e.getMessage()); + // log.error(e.getMessage()); } } else { diff --git a/src/org/paint/gui/menu/TreeMenu.java b/src/org/paint/gui/menu/TreeMenu.java index 885018f..133c447 100644 --- a/src/org/paint/gui/menu/TreeMenu.java +++ b/src/org/paint/gui/menu/TreeMenu.java @@ -160,7 +160,7 @@ public void actionPerformed(ActionEvent e) { switch (action) { case TREE_USE_DISTANCES: PaintConfig.inst().use_distances = ((JCheckBoxMenuItem) e.getSource()).isSelected(); - tree.adjustTree(); + tree.rescaleTree(); break; case TREE_EXPAND_ALL_NODES: PaintConfig.inst().collapse_no_exp = false; @@ -170,7 +170,7 @@ public void actionPerformed(ActionEvent e) { case TREE_COLLAPSE_NONEXP_NODES: PaintConfig.inst().collapse_no_exp = ((JCheckBoxMenuItem) e.getSource()).isSelected(); if (PaintConfig.inst().collapse_no_exp) { - tree.collapseNonExperimental(); + tree.collapseNonExperimental(true); } else { tree.expandAllNodes(); } diff --git a/src/org/paint/gui/table/GeneTable.java b/src/org/paint/gui/table/GeneTable.java index 9342f25..aef68c7 100644 --- a/src/org/paint/gui/table/GeneTable.java +++ b/src/org/paint/gui/table/GeneTable.java @@ -155,7 +155,7 @@ public void mouseClicked(MouseEvent e) { else if (InputEvent.BUTTON3_MASK == (modifiers & InputEvent.BUTTON3_MASK) || (((modifiers & InputEvent.BUTTON1_MASK) != 0 && (modifiers & InputEvent.BUTTON3_MASK) == 0) && - (true == e.isMetaDown()))) { + (true == e.isMetaDown()))) { ListSelectionModel lsm = this.getSelectionModel(); int min = lsm.getMinSelectionIndex(); @@ -342,9 +342,11 @@ private void setSelectedRows(ListSelectionModel lsm, TreePanel tree, Bioentity n } public void handleNodeReorderEvent(NodeReorderEvent e) { - GeneTableModel model = (GeneTableModel) this.getModel(); - model.reorderRows(e.getNodes()); - model.fireTableDataChanged(); + if (this.getModel().getClass() == GeneTableModel.class) { + GeneTableModel model = (GeneTableModel) this.getModel(); + model.reorderRows(e.getNodes()); + model.fireTableDataChanged(); + } } public void handleAspectChangeEvent(AspectChangeEvent event) { @@ -392,7 +394,7 @@ public Dimension getPreferredSize() { d.height += pad; return d; } - + private void setColumnWidths(PaintTable grid, int col_count, FontMetrics fm, TableColumnModel colModel) { Insets insets = new DefaultTableCellRenderer().getInsets(); for (int i = 0; i < col_count; i++) { @@ -404,7 +406,7 @@ private void setColumnWidths(PaintTable grid, int col_count, FontMetrics fm, Tab if (grid.isSquare(i)) { optimalColumnWidth = fm.getHeight(); } -// Set column width to max size required to fit text + // Set column width to max size required to fit text else { for (int j = 0; j < grid.getRowCount(); j++) { String value = grid.getTextAt(j, i); diff --git a/src/org/paint/gui/tree/TreePanel.java b/src/org/paint/gui/tree/TreePanel.java index 384f745..eb2aac9 100644 --- a/src/org/paint/gui/tree/TreePanel.java +++ b/src/org/paint/gui/tree/TreePanel.java @@ -21,13 +21,11 @@ package org.paint.gui.tree; import java.awt.Color; -import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; -import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -49,14 +47,12 @@ import javax.swing.JCheckBoxMenuItem; import javax.swing.JFileChooser; -import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JViewport; import javax.swing.Scrollable; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; import javax.swing.UIManager; import javax.swing.plaf.ColorUIResource; @@ -82,11 +78,13 @@ import org.paint.gui.event.EventManager; import org.paint.gui.event.GeneSelectEvent; import org.paint.gui.event.GeneSelectListener; +import org.paint.gui.event.NodeReorderEvent; import org.paint.gui.event.TermSelectEvent; import org.paint.gui.event.TermSelectionListener; import org.paint.gui.table.GeneTable; import org.paint.main.PaintManager; import org.paint.util.GuiConstant; +import org.paint.util.RenderUtil; import owltools.gaf.Bioentity; @@ -159,9 +157,12 @@ public TreePanel() { ToolTipManager.sharedInstance().registerComponent(this); } - public void setTreeModel(DisplayTree tree2) { - this.tree = tree2; - setNeedPositionUpdate(); + public void setTreeModel(DisplayTree tree) { + this.tree = tree; + // set the dang rectangle now! + boolean use_distances = PaintConfig.inst().use_distances; + updateNodePositions(tree.getRoot(), this.getGraphics(), PaintManager.inst().getRowHeight(), use_distances); +// setNeedPositionUpdate(false); } public DisplayTree getTreeModel() { @@ -192,7 +193,7 @@ public List getAllNodes() { public void scaleTree(double scale){ if (this.getDistanceScaling() != scale) { this.setDistance(scale); - setNeedPositionUpdate(); + setNeedPositionUpdate(true); PaintConfig.inst().tree_distance_scaling = scale; } } @@ -200,14 +201,14 @@ public void scaleTree(double scale){ public void speciesOrder() { if (tree != null) { tree.speciesOrder(); - setNeedPositionUpdate(); + setNeedPositionUpdate(true); } } public void descendentCountLadder(boolean most_leaves_at_top) { if (tree != null) { tree.descendentCountLadder(most_leaves_at_top); - setNeedPositionUpdate(); + setNeedPositionUpdate(true); } } @@ -230,28 +231,28 @@ public void getLeafDescendants(Bioentity node, List leafList){ } } - public void adjustTree() { - setNeedPositionUpdate(); + public void rescaleTree() { + setNeedPositionUpdate(false); } public void expandAllNodes() { if (tree != null) { tree.expandAllNodes(); - setNeedPositionUpdate(); + setNeedPositionUpdate(true); } } - public void collapseNonExperimental() { + public void collapseNonExperimental(boolean notify) { if (tree != null) { tree.collapseNonExperimental(); - setNeedPositionUpdate(); + setNeedPositionUpdate(notify); } } public void resetRootToMain() { if (tree != null) { if (tree.resetRootToMain()) - setNeedPositionUpdate(); + setNeedPositionUpdate(true); } } @@ -279,7 +280,7 @@ public Bioentity getBottomLeafNode(Bioentity node) { public void handlePruning(DisplayBioentity node) { boolean shift = tree.handlePruning(node); if (shift) { - setNeedPositionUpdate(); + setNeedPositionUpdate(true); } } @@ -380,13 +381,19 @@ private void updateNodePositions(Bioentity current_root, Graphics g, int row_hei int x = TreePanel.LEFTMARGIN + getNodeWidth(g, current_root); setNodeRectangle(current_root, row_height, x, 0, use_distances, g); tree_rect = calcTreeSize(g); -// revalidate(); -// repaint(); need_update = false; } - protected void setNeedPositionUpdate() { + protected void setNeedPositionUpdate(boolean notify) { + // Method to set number of leaves in tree need_update = true; + revalidate(); + repaint(); + if (notify) { + NodeReorderEvent event = new NodeReorderEvent(this); + event.setNodes(getTerminusNodes()); + EventManager.inst().fireNodeReorderEvent(event); + } } /** @@ -420,12 +427,12 @@ private Rectangle calcTreeSize(Graphics g) { } private Rectangle getTreeSize(Graphics g) { - if (tree != null) { - if (need_update) { - tree.nodesReordered(); - updateNodePositions(getCurrentRoot(), g, PaintManager.inst().getRowHeight(), PaintConfig.inst().use_distances); - } - } +// if (tree != null) { +// if (need_update) { +// tree.nodesReordered(); +// updateNodePositions(getCurrentRoot(), g, PaintManager.inst().getRowHeight(), PaintConfig.inst().use_distances); +// } +// } return tree_rect; } @@ -584,54 +591,13 @@ public void mouseClicked(MouseEvent e) { } } if (InputEvent.BUTTON3_MASK == (modifiers & InputEvent.BUTTON3_MASK) || - (((modifiers & InputEvent.BUTTON1_MASK) != 0 && (modifiers & InputEvent.BUTTON3_MASK) == 0) && (true == e.isMetaDown())) ){ + (((modifiers & InputEvent.BUTTON1_MASK) != 0 && + (modifiers & InputEvent.BUTTON3_MASK) == 0) && + (e.isMetaDown()))) { JPopupMenu popup = createPopupMenu(e); if (popup != null) - showPopup(popup, e.getComponent(), new Point(e.getX(), e.getY())); - } - } - - /** - * Method declaration - * - * - * @param popup - * @param comp - * @param position - * - * @see - */ - private void showPopup(JPopupMenu popup, Component comp, Point position){ - - // Get root frame - Component root = comp; - - while ((root != null) && (false == (root instanceof JFrame))){ - root = root.getParent(); - } - if (root != null){ - SwingUtilities.convertPointToScreen(position, comp); - Point rootPos = root.getLocationOnScreen(); - Dimension rootSize = root.getSize(); - Dimension popSize = popup.getPreferredSize(); - int x = position.x; - int y = position.y; - Insets insets = popup.getInsets(); - - if (position.x + popSize.width + (insets.left + insets.right) > rootPos.x + rootSize.width){ - x = rootPos.x + rootSize.width - popSize.width - insets.left; - } - if (position.y + popSize.height + (insets.top + insets.bottom) > rootPos.y + rootSize.height){ - y = rootPos.y + rootSize.height - popSize.height - insets.top; - } - if (x >= rootPos.x + insets.left && y >= rootPos.y + insets.top){ - position.setLocation(x, y); - } - SwingUtilities.convertPointFromScreen(position, comp); + RenderUtil.showPopup(popup, e.getComponent(), new Point(e.getX(), e.getY())); } - - // Show popup menu. - popup.show(comp, position.x, position.y); } private DisplayBioentity getPopupNode(MouseEvent e) { @@ -804,9 +770,7 @@ private class InternalRerootActionListener implements ActionListener{ */ public void actionPerformed(ActionEvent e) { tree.nodeReroot(node); - setNeedPositionUpdate(); - revalidate(); - repaint(); + setNeedPositionUpdate(true); } } @@ -836,9 +800,7 @@ private class CollapseExpandNodeActionListener implements ActionListener{ */ public void actionPerformed(ActionEvent e){ tree.handleCollapseExpand(node); - setNeedPositionUpdate(); - revalidate(); - repaint(); + setNeedPositionUpdate(true); } } diff --git a/src/org/paint/main/PaintManager.java b/src/org/paint/main/PaintManager.java index de480f2..ee37b99 100644 --- a/src/org/paint/main/PaintManager.java +++ b/src/org/paint/main/PaintManager.java @@ -211,7 +211,7 @@ private void openFamily(String family_name, boolean existing) { fireProgressChange("Collapsing branches lacking experimental data", progress, ProgressEvent.Status.START); progress += progress_increment; - tree_pane.collapseNonExperimental(); + tree_pane.collapseNonExperimental(false); } fireProgressChange("Notifying displays of new family", progress, ProgressEvent.Status.START); diff --git a/src/org/paint/util/RenderUtil.java b/src/org/paint/util/RenderUtil.java index dc74480..dc8bc2e 100644 --- a/src/org/paint/util/RenderUtil.java +++ b/src/org/paint/util/RenderUtil.java @@ -21,14 +21,21 @@ package org.paint.util; import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Insets; +import java.awt.Point; import java.awt.Rectangle; import java.util.HashMap; import java.util.List; +import javax.swing.JFrame; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; + import org.apache.log4j.Logger; import org.bbop.phylo.annotate.AnnotationUtil; import org.paint.config.PaintConfig; @@ -229,5 +236,40 @@ public static Color getOrthoColor(String ortho_name) { } return color; } + + public static void showPopup(JPopupMenu popup, Component comp, Point position){ + + // Get root frame + Component root = comp; + + while ((root != null) && (false == (root instanceof JFrame))){ + root = root.getParent(); + } + if (root != null){ + SwingUtilities.convertPointToScreen(position, comp); + Point rootPos = root.getLocationOnScreen(); + Dimension rootSize = root.getSize(); + Dimension popSize = popup.getPreferredSize(); + int x = position.x; + int y = position.y; + Insets insets = popup.getInsets(); + + if (position.x + popSize.width + (insets.left + insets.right) > rootPos.x + rootSize.width){ + x = rootPos.x + rootSize.width - popSize.width - insets.left; + } + if (position.y + popSize.height + (insets.top + insets.bottom) > rootPos.y + rootSize.height){ + y = rootPos.y + rootSize.height - popSize.height - insets.top; + } + if (x >= rootPos.x + insets.left && y >= rootPos.y + insets.top){ + position.setLocation(x, y); + } + SwingUtilities.convertPointFromScreen(position, comp); + } + + // Show popup menu. + popup.show(comp, position.x, position.y); + } + + }