From: Renia Correya Date: Fri, 18 Oct 2024 11:58:14 +0000 (+0100) Subject: Merge branch 'feature/JAL-4386_JAL-4435_coloured_lines_for_providers' into feature... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=87ad04639b5b83d8c9e32c38ec75c481530dda3b;p=jalview.git Merge branch 'feature/JAL-4386_JAL-4435_coloured_lines_for_providers' into feature/JAL-4386_JAL-4435_reformat_node_labels --- 87ad04639b5b83d8c9e32c38ec75c481530dda3b diff --cc src/jalview/gui/TreeCanvas.java index 33f8c6d,c42546c..4efedc3 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@@ -448,46 -449,23 +451,66 @@@ public class TreeCanvas extends JPanel nodeLabel = nodeLabel + String.valueOf(node.bootstrap); } - if (node.hasLabel()) ++ ++ boolean showColouredLinesForSSProviders = true; ++ + //Display secondary structure providers as labels only if: + // ~ node has Label assigned (Secondary structure providers) + // ~ node count is greater than 3 + // ~ showSecondaryStructureProvider option is set to true by the user - if ( node.hasLabel() && showSecondaryStructureProvider && node.count > 3) ++ if ( node.hasLabel() && showSecondaryStructureProvider && showColouredLinesForSSProviders) { ++ + drawLinesAndLabelsForSecondaryStructureProvider(g, node, xstart, xend, ypos, nodeLabel); + + int labelWidth = 20; + int labelHeight = fm.getHeight(); + + // Calculate the bounding box of the string + int xLabelPos = xstart + 2; + int yLabelPos = ypos - 2; + Rectangle labelBounds = new Rectangle(xLabelPos, yLabelPos - labelHeight, labelWidth, labelHeight); + + // Add the bounding box to the map for this node (list allows multiple bounding boxes) - labelBoundsMap.computeIfAbsent(node, k -> new ArrayList<>()).add(labelBounds); ++ labelBoundsMap.computeIfAbsent(node, k -> new ArrayList<>()).add(labelBounds); + + } ++ else if ( node.hasLabel() && showSecondaryStructureProvider && node.count > 3) ++ { ++ + String label = node.getLabel(); + + if(label.length() > labelLengthThreshold) { + + //label = AlignmentUtils.reduceLabelLength(label); + } + + nodeLabel = label + " | " + nodeLabel; + + // Split the nodeLabel by "|" + String[] lines = nodeLabel.split("\\|"); + + // Iterate over the lines and draw each string separately + String longestLabelString = ""; + int i = 0; + for (i = 0; i < lines.length; i++) { + g.drawString(lines[i].trim(), xstart + 2, ypos - 2 - (i * fm.getHeight())); + if(longestLabelString.length() < lines[i].trim().length()) { + longestLabelString = lines[i].trim(); + } + } + + int labelWidth = fm.stringWidth(longestLabelString); + int labelHeight = fm.getHeight() * (i-1); + + // Calculate the bounding box of the string + int xLabelPos = xstart + 2; + int yLabelPos = ypos - 2; + Rectangle labelBounds = new Rectangle(xLabelPos, yLabelPos - labelHeight, labelWidth, labelHeight); + // Add the bounding box to the map for this node (list allows multiple bounding boxes) + labelBoundsMap.computeIfAbsent(node, k -> new ArrayList<>()).add(labelBounds); + } - else if (!nodeLabel.equals("")) { g.drawString(nodeLabel, xstart + 2, ypos - 2);