X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FNodePanel.java;h=ed7ed0b715a8a8482367754439717876fc7cb57b;hb=693353f5ea85d3e50a77f9b1cd9d87711d23412b;hp=37810c60a6799b2f32427ed2d0e35865086ec165;hpb=f4fb23cb07075ba87d6b812c3b6af92bb438dc59;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/NodePanel.java b/forester/java/src/org/forester/archaeopteryx/NodePanel.java index 37810c6..ed7ed0b 100644 --- a/forester/java/src/org/forester/archaeopteryx/NodePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/NodePanel.java @@ -21,15 +21,21 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/ +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx; + import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.List; -import java.util.SortedMap; +import java.util.Map; import java.util.SortedSet; +import javax.swing.BoxLayout; +import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -43,6 +49,7 @@ import javax.swing.tree.TreePath; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.data.Accession; import org.forester.phylogeny.data.Annotation; import org.forester.phylogeny.data.BinaryCharacters; import org.forester.phylogeny.data.BranchWidth; @@ -50,8 +57,9 @@ import org.forester.phylogeny.data.Date; import org.forester.phylogeny.data.Distribution; import org.forester.phylogeny.data.Event; import org.forester.phylogeny.data.PhylogenyData; +import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.data.Point; -import org.forester.phylogeny.data.PropertiesMap; +import org.forester.phylogeny.data.PropertiesList; import org.forester.phylogeny.data.Property; import org.forester.phylogeny.data.Reference; import org.forester.phylogeny.data.Sequence; @@ -61,58 +69,59 @@ import org.forester.util.ForesterUtil; class NodePanel extends JPanel implements TreeSelectionListener { - static final String DIST_ALTITUDE = "Altitude"; - static final String DIST_ALT_UNIT = "Altitude unit"; - static final String DIST_LONGITUDE = "Longitude"; - static final String DIST_LATITUDE = "Latitude"; - static final String DIST_GEODETIC_DATUM = "Geodetic datum"; - static final String DIST_DESCRIPTION = "Description"; - static final String DATE_UNIT = "Unit"; + static final String BASIC = "Basic"; + static final String BINARY_CHARACTERS = "Binary characters"; + static final String CONFIDENCE = "Confidence"; + static final String CONFIDENCE_TYPE = "type"; + static final String DATE = "Date"; + static final String DATE_DESCRIPTION = "Description"; static final String DATE_MAX = "Max"; static final String DATE_MIN = "Min"; + static final String DATE_UNIT = "Unit"; static final String DATE_VALUE = "Value"; - static final String DATE_DESCRIPTION = "Description"; - static final String TAXONOMY_IDENTIFIER = "Identifier"; - static final String SEQ_ACCESSION = "Accession"; - static final String CONFIDENCE = "Confidence"; - static final String PROP = "Properties"; - static final String BINARY_CHARACTERS = "Binary characters"; - static final String REFERENCE = "Reference"; + static final String DIST_ALT_UNIT = "Altitude unit"; + static final String DIST_ALTITUDE = "Altitude"; + static final String DIST_DESCRIPTION = "Description"; + static final String DIST_GEODETIC_DATUM = "Geodetic datum"; + static final String DIST_LATITUDE = "Latitude"; + static final String DIST_LONGITUDE = "Longitude"; + static final String DISTRIBUTION = "Distribution"; + static final String EVENTS = "Events"; + static final String EVENTS_DUPLICATIONS = "Duplications"; + static final String EVENTS_GENE_LOSSES = "Gene losses"; + static final String EVENTS_SPECIATIONS = "Speciations"; static final String LIT_REFERENCE = "Reference"; static final String LIT_REFERENCE_DESC = "Description"; static final String LIT_REFERENCE_DOI = "DOI"; - static final String DISTRIBUTION = "Distribution"; - static final String DATE = "Date"; - static final String EVENTS = "Events"; - static final String SEQUENCE = "Sequence"; - static final String TAXONOMY = "Taxonomy"; - static final String BASIC = "Basic"; - static final String TAXONOMY_SCIENTIFIC_NAME = "Scientific name"; - static final String SEQ_MOL_SEQ = "Mol seq"; - static final String SEQ_TYPE = "Type"; - static final String SEQ_LOCATION = "Location"; - static final String SEQ_SYMBOL = "Symbol"; - static final String SEQ_URI = "URI"; + static final String NODE_BRANCH_COLOR = "Branch color"; static final String NODE_BRANCH_LENGTH = "Branch length"; static final String NODE_BRANCH_WIDTH = "Branch width"; - static final String NODE_BRANCH_COLOR = "Branch color"; static final String NODE_NAME = "Name"; - static final String TAXONOMY_URI = "URI"; - static final String TAXONOMY_RANK = "Rank"; - static final String TAXONOMY_SYNONYM = "Synonym"; - static final String TAXONOMY_COMMON_NAME = "Common name"; + static final String PROP = "Properties"; + static final String REFERENCE = "Reference"; + static final String SEQ_ACCESSION = "Accession"; + static final String SEQ_LOCATION = "Location"; + static final String SEQ_MOL_SEQ = "Mol seq"; + static final String SEQ_NAME = "Name"; + static final String SEQ_SYMBOL = "Symbol"; + static final String SEQ_GENE_NAME = "Gene name"; + static final String SEQ_TYPE = "Type"; + static final String SEQ_URI = "URI"; + static final String SEQUENCE = "Sequence"; + static final String TAXONOMY = "Taxonomy"; static final String TAXONOMY_AUTHORITY = "Authority"; static final String TAXONOMY_CODE = "Code"; - static final String SEQ_NAME = "Name"; - static final String EVENTS_GENE_LOSSES = "Gene losses"; - static final String EVENTS_SPECIATIONS = "Speciations"; - static final String EVENTS_DUPLICATIONS = "Duplications"; + static final String TAXONOMY_COMMON_NAME = "Common name"; + static final String TAXONOMY_IDENTIFIER = "Identifier"; + static final String TAXONOMY_RANK = "Rank"; + static final String TAXONOMY_SCIENTIFIC_NAME = "Scientific name"; + static final String TAXONOMY_SYNONYM = "Synonym"; + static final String TAXONOMY_URI = "URI"; private static final long serialVersionUID = 5120159904388100771L; - static final String CONFIDENCE_TYPE = "type"; - private final JTree _tree; private final JEditorPane _pane; + private final JTree _tree; - public NodePanel( final PhylogenyNode phylogeny_node ) { + public NodePanel( final PhylogenyNode phylogeny_node, final NodeFrame parent ) { String node_name = ""; if ( !ForesterUtil.isEmpty( phylogeny_node.getName() ) ) { node_name = phylogeny_node.getName() + " "; @@ -127,17 +136,43 @@ class NodePanel extends JPanel implements TreeSelectionListener { expandPath( SEQUENCE ); expandPath( EVENTS ); final JScrollPane tree_view = new JScrollPane( getJTree() ); + + final JButton close_button = new JButton( "Close" ); + close_button.setEnabled( true ); + _pane = new JEditorPane(); _pane.setEditable( false ); + final JScrollPane data_view = new JScrollPane( _pane ); final JSplitPane split_pane = new JSplitPane( JSplitPane.VERTICAL_SPLIT ); split_pane.setTopComponent( tree_view ); + data_view.add( close_button ); split_pane.setBottomComponent( data_view ); - data_view.setMinimumSize( Constants.NODE_PANEL_SPLIT_MINIMUM_SIZE ); - tree_view.setMinimumSize( Constants.NODE_PANEL_SPLIT_MINIMUM_SIZE ); - split_pane.setDividerLocation( 400 ); - split_pane.setPreferredSize( Constants.NODE_PANEL_SIZE ); - add( split_pane ); + data_view.setMinimumSize( AptxConstants.NODE_PANEL_SPLIT_MINIMUM_SIZE ); + tree_view.setMinimumSize( AptxConstants.NODE_PANEL_SPLIT_MINIMUM_SIZE ); + split_pane.setDividerLocation( 300 ); + split_pane.setPreferredSize( AptxConstants.NODE_PANEL_SIZE ); + + + close_button.addActionListener( new ActionListener() { + public void actionPerformed( final ActionEvent e ) { + parent.close(); + } + } ); + + + close_button.setAlignmentX( Component.CENTER_ALIGNMENT ); + split_pane.setAlignmentX( Component.CENTER_ALIGNMENT ); + final JPanel panel = new JPanel(); + panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) ); + panel.add( split_pane ); + panel.add( close_button ); + add( panel ); + } + + @Override + public void valueChanged( final TreeSelectionEvent e ) { + // Do nothing. } private void expandPath( final String name ) { @@ -151,17 +186,10 @@ class NodePanel extends JPanel implements TreeSelectionListener { return _tree; } - @Override - public void valueChanged( final TreeSelectionEvent e ) { - // Do nothing. - } - private static void addAnnotation( final DefaultMutableTreeNode top, final Annotation ann, final String name ) { DefaultMutableTreeNode category; category = new DefaultMutableTreeNode( name ); top.add( category ); - addSubelement( category, REFERENCE, ann.getRef() ); - addSubelement( category, "Description", ann.getDesc() ); addSubelement( category, "Source", ann.getSource() ); addSubelement( category, "Type", ann.getType() ); addSubelement( category, "Evidence", ann.getEvidence() ); @@ -173,60 +201,14 @@ class NodePanel extends JPanel implements TreeSelectionListener { } } - private static void addUri( final DefaultMutableTreeNode top, final Uri uri, final String name ) { - DefaultMutableTreeNode category; - category = new DefaultMutableTreeNode( name ); - top.add( category ); - addSubelement( category, "Description", uri.getDescription() ); - addSubelement( category, "Type", uri.getType() ); - addSubelement( category, "URI", uri.getValue().toString() ); - } - private static void addAnnotations( final DefaultMutableTreeNode top, final SortedSet annotations, final DefaultMutableTreeNode category ) { if ( ( annotations != null ) && ( annotations.size() > 0 ) ) { category.add( new DefaultMutableTreeNode( "Annotations" ) ); final DefaultMutableTreeNode last = top.getLastLeaf(); - int i = 0; - for( final PhylogenyData ann : annotations ) { - addAnnotation( last, ( Annotation ) ann, "Annotation " + ( i++ ) ); - } - } - } - - private static void addUris( final DefaultMutableTreeNode top, - final List uris, - final DefaultMutableTreeNode category ) { - if ( ( uris != null ) && ( uris.size() > 0 ) ) { - category.add( new DefaultMutableTreeNode( "URIs" ) ); - final DefaultMutableTreeNode last = top.getLastLeaf(); - int i = 0; - for( final Uri uri : uris ) { - if ( uri != null ) { - addUri( last, uri, "URI " + ( i++ ) ); - } - } - } - } - - private static void addLineage( final DefaultMutableTreeNode top, - final List lineage, - final DefaultMutableTreeNode category ) { - if ( ( lineage != null ) && ( lineage.size() > 0 ) ) { - final StringBuilder sb = new StringBuilder(); - for( final String lin : lineage ) { - if ( !ForesterUtil.isEmpty( lin ) ) { - sb.append( lin ); - sb.append( " > " ); - } - } - String str = null; - if ( sb.length() > 1 ) { - str = sb.substring( 0, sb.length() - 3 ); - } - if ( !ForesterUtil.isEmpty( str ) ) { - addSubelement( category, "Lineage", str ); + for( final Annotation ann : annotations ) { + addAnnotation( last, ann, ann.asText().toString() ); } } } @@ -237,7 +219,7 @@ class NodePanel extends JPanel implements TreeSelectionListener { final DefaultMutableTreeNode category = new DefaultMutableTreeNode( name ); top.add( category ); addSubelement( category, NODE_NAME, phylogeny_node.getName() ); - if ( phylogeny_node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT ) { + if ( phylogeny_node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) { addSubelement( category, NODE_BRANCH_LENGTH, ForesterUtil.FORMATTER_6.format( phylogeny_node.getDistanceToParent() ) ); @@ -252,8 +234,7 @@ class NodePanel extends JPanel implements TreeSelectionListener { addSubelement( category, "External children", String.valueOf( phylogeny_node.getAllExternalDescendants().size() ) ); - final SortedMap distinct_tax = PhylogenyMethods - .obtainDistinctTaxonomyCounts( phylogeny_node ); + final Map distinct_tax = PhylogenyMethods.obtainDistinctTaxonomyCounts( phylogeny_node ); if ( distinct_tax != null ) { final int no_tax = PhylogenyMethods.calculateNumberOfExternalNodesWithoutTaxonomy( phylogeny_node ); final int tax_count = distinct_tax.size(); @@ -264,8 +245,8 @@ class NodePanel extends JPanel implements TreeSelectionListener { } } if ( !phylogeny_node.isRoot() ) { - addSubelement( category, "Depth", String.valueOf( PhylogenyMethods.calculateDepth( phylogeny_node ) ) ); - final double d = PhylogenyMethods.calculateDistanceToRoot( phylogeny_node ); + addSubelement( category, "Depth", String.valueOf( phylogeny_node.calculateDepth() ) ); + final double d = phylogeny_node.calculateDistanceToRoot(); if ( d > 0 ) { addSubelement( category, "Distance to root", String.valueOf( ForesterUtil.FORMATTER_6.format( d ) ) ); } @@ -298,6 +279,24 @@ class NodePanel extends JPanel implements TreeSelectionListener { addSubelement( chars, "Present", bc.getPresentCharactersAsStringBuffer().toString() ); } + private static void addCrossReference( final DefaultMutableTreeNode top, final Accession x, final String name ) { + DefaultMutableTreeNode category; + category = new DefaultMutableTreeNode( name ); + top.add( category ); + } + + private static void addCrossReferences( final DefaultMutableTreeNode top, + final SortedSet xs, + final DefaultMutableTreeNode category ) { + if ( ( xs != null ) && ( xs.size() > 0 ) ) { + category.add( new DefaultMutableTreeNode( "Cross references" ) ); + final DefaultMutableTreeNode last = top.getLastLeaf(); + for( final Accession x : xs ) { + addCrossReference( last, x, x.asText().toString() ); + } + } + } + private static void addDate( final DefaultMutableTreeNode top, final Date date, final String name ) { DefaultMutableTreeNode category; category = new DefaultMutableTreeNode( name ); @@ -316,7 +315,7 @@ class NodePanel extends JPanel implements TreeSelectionListener { addSubelement( category, DIST_DESCRIPTION, dist.getDesc() ); if ( ( dist.getPoints() != null ) && ( dist.getPoints().size() > 0 ) ) { final Point p0 = dist.getPoints().get( 0 ); - if ( p0 != null ) { + if ( ( p0 != null ) && !Point.isSeemsEmpty( p0 ) ) { addSubelement( category, DIST_GEODETIC_DATUM, p0.getGeodeticDatum() ); addSubelement( category, DIST_LATITUDE, String.valueOf( p0.getLatitude() ) ); addSubelement( category, DIST_LONGITUDE, String.valueOf( p0.getLongitude() ) ); @@ -348,14 +347,35 @@ class NodePanel extends JPanel implements TreeSelectionListener { } } + private static void addLineage( final DefaultMutableTreeNode top, + final List lineage, + final DefaultMutableTreeNode category ) { + if ( ( lineage != null ) && ( lineage.size() > 0 ) ) { + final StringBuilder sb = new StringBuilder(); + for( final String lin : lineage ) { + if ( !ForesterUtil.isEmpty( lin ) ) { + sb.append( lin ); + sb.append( " > " ); + } + } + String str = null; + if ( sb.length() > 1 ) { + str = sb.substring( 0, sb.length() - 3 ); + } + if ( !ForesterUtil.isEmpty( str ) ) { + addSubelement( category, "Lineage", str ); + } + } + } + private static void addProperties( final DefaultMutableTreeNode top, - final PropertiesMap properties, + final PropertiesList properties, final String string ) { - final SortedMap properties_map = properties.getProperties(); + final List properties_map = properties.getProperties(); final DefaultMutableTreeNode category = new DefaultMutableTreeNode( "Properties " ); top.add( category ); - for( final String key : properties_map.keySet() ) { - final Property prop = properties_map.get( key ); + for( final Property prop : properties_map ) { + category.add( new DefaultMutableTreeNode( prop.getRef() + "=" + prop.getValue() + " " + prop.getUnit() + " [" + prop.getAppliesTo().toString() + "]" ) ); } @@ -373,16 +393,22 @@ class NodePanel extends JPanel implements TreeSelectionListener { top.add( category ); addSubelement( category, SEQ_NAME, seq.getName() ); addSubelement( category, SEQ_SYMBOL, seq.getSymbol() ); + addSubelement( category, SEQ_GENE_NAME, seq.getGeneName() ); if ( seq.getAccession() != null ) { addSubelement( category, SEQ_ACCESSION, seq.getAccession().asText().toString() ); } addSubelement( category, SEQ_LOCATION, seq.getLocation() ); addSubelement( category, SEQ_TYPE, seq.getType() ); addSubelement( category, SEQ_MOL_SEQ, seq.getMolecularSequence() ); + if ( ( seq.getAnnotations() != null ) && !seq.getAnnotations().isEmpty() ) { + addAnnotations( top, seq.getAnnotations(), category ); + } + if ( ( seq.getCrossReferences() != null ) && !seq.getCrossReferences().isEmpty() ) { + addCrossReferences( top, seq.getCrossReferences(), category ); + } if ( ( seq.getUris() != null ) && !seq.getUris().isEmpty() ) { addUris( top, seq.getUris(), category ); } - addAnnotations( top, seq.getAnnotations(), category ); } private static void addSubelement( final DefaultMutableTreeNode node, final String name, final String value ) { @@ -413,6 +439,30 @@ class NodePanel extends JPanel implements TreeSelectionListener { } } + private static void addUri( final DefaultMutableTreeNode top, final Uri uri, final String name ) { + DefaultMutableTreeNode category; + category = new DefaultMutableTreeNode( name ); + top.add( category ); + addSubelement( category, "Description", uri.getDescription() ); + addSubelement( category, "Type", uri.getType() ); + addSubelement( category, "URI", uri.getValue().toString() ); + } + + private static void addUris( final DefaultMutableTreeNode top, + final List uris, + final DefaultMutableTreeNode category ) { + if ( ( uris != null ) && ( uris.size() > 0 ) ) { + category.add( new DefaultMutableTreeNode( "URIs" ) ); + final DefaultMutableTreeNode last = top.getLastLeaf(); + int i = 0; + for( final Uri uri : uris ) { + if ( uri != null ) { + addUri( last, uri, "URI " + ( i++ ) ); + } + } + } + } + private static void createNodes( final DefaultMutableTreeNode top, final PhylogenyNode phylogeny_node ) { addBasics( top, phylogeny_node, BASIC ); // Taxonomy