+ private final int paintSequenceRelation( final Graphics2D g,
+ final PhylogenyNode node,
+ int x,
+ final int half_box_size,
+ final float pos_x,
+ final float pos_y,
+ final String sb_str ) {
+ int nodeTextBoundsWidth = 0;
+ if ( sb_str.length() > 0 ) {
+ final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
+ nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
+ }
+ if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
+ if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
+ g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
+ g.setColor( getTreeColorSet().getBackgroundColor() );
+ }
+ }
+ else {
+ final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
+ for( final SequenceRelation seqRelation : seqRelations ) {
+ final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
+ || seqRelation.getRef1().isEqual( _query_sequence ) )
+ && seqRelation.getType()
+ .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
+ if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
+ final double linePosX = node.getXcoord() + 2 + half_box_size;
+ final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
+ || ( seqRelation.getConfidence() == null ) ) ? null
+ : " (" + seqRelation.getConfidence().getValue() + ")";
+ if ( sConfidence != null ) {
+ float confidenceX = pos_x;
+ if ( sb_str.length() > 0 ) {
+ confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
+ + CONFIDENCE_LEFT_MARGIN;
+ }
+ if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
+ final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
+ .getBounds().getWidth();
+ TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
+ x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
+ }
+ }
+ if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
+ {
+ if ( nodeTextBoundsWidth == 0 ) {
+ nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
+ }
+ else {
+ nodeTextBoundsWidth += 2;
+ }
+ g.drawLine( ( int ) linePosX + 1,
+ 3 + ( int ) pos_y,
+ ( int ) linePosX + x + nodeTextBoundsWidth,
+ 3 + ( int ) pos_y );
+ break;
+ }
+ }
+ }
+ }
+ return x;
+ }
+
+ private final void drawConnection( final float x1,
+ final float x2,
+ final float y,
+ final int dist_left,
+ final int dist_right,
+ final Graphics2D g,
+ final boolean pdf ) {
+ if ( ( ( x1 + dist_left ) < ( x2 - dist_right ) ) ) {
+ final Stroke strok = g.getStroke();
+ Color col = null;
+ if ( strok == STROKE_005 ) {
+ g.setStroke( STROKE_001_DASHED );
+ }
+ else if ( strok == STROKE_01 ) {
+ g.setStroke( STROKE_005_DASHED );
+ }
+ else {
+ g.setStroke( STROKE_01_DASHED );
+ }
+ if ( pdf ) {
+ col = g.getColor();
+ g.setColor( lighter( col ) );
+ }
+ drawLine( x1 + dist_left, y, x2 - dist_right, y, g );
+ g.setStroke( strok );
+ if ( pdf ) {
+ g.setColor( col );
+ }
+ }
+ }
+
+ public static Color lighter( final Color color ) {
+ if ( ( color.getRed() == 0 ) && ( color.getGreen() == 0 ) && ( color.getBlue() == 0 ) ) {
+ return new Color( 200, 200, 200 );
+ }
+ else {
+ return color;
+ }
+ }
+