*/
package jalview.gui;
+import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
{
/** DOCUMENT ME!! */
public static final String PLACEHOLDER = " * ";
+
+ private static final int DASHED_LINE_Y_OFFSET = 5;
TreeModel tree;
nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
}
+
if (node.hasLabel())
{
- 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 line 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();
- }
- }
+ drawLinesAndLabelsForSecondaryStructureProvider(g, node, xstart, xend, ypos, nodeLabel);
- int labelWidth = fm.stringWidth(longestLabelString);
- int labelHeight = fm.getHeight() * (i-1);
+ int labelWidth = 20;
+ int labelHeight = fm.getHeight();
// Calculate the bounding box of the string
int xLabelPos = xstart + 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 (!nodeLabel.equals(""))
}
}
}
+
+
+ private void drawLinesAndLabelsForSecondaryStructureProvider(Graphics g, BinaryNode node,
+ int xstart, int xend, int ypos, String nodeLabel) {
+ // Cast the Graphics object to Graphics2D
+ Graphics2D g2d = (Graphics2D) g.create();
+
+ // Set dash pattern
+ float[] dashPattern = {2, 3};
+ g2d.setStroke(new BasicStroke(
+ 1.5f,
+ BasicStroke.CAP_BUTT,
+ BasicStroke.JOIN_ROUND,
+ 0.0f,
+ dashPattern,
+ 0.0f));
+
+ String label = node.getLabel();
+ String[] lines = label.split("\\|");
+
+ int mid = lines.length / 2;
+
+ // Draw lines for the first half
+ int firstHalfLinesCount = mid;
+
+ drawSecondaryStructureProviderLinesSection(g2d,
+ lines, 0, mid, xstart, xend,
+ ypos - DASHED_LINE_Y_OFFSET,
+ true);
+ drawVerticalLineAndLabel(g, xstart, ypos, firstHalfLinesCount, true, nodeLabel);
+
+ // Draw lines for the second half
+ int secondHalfLinesCount = lines.length - mid;
+ drawSecondaryStructureProviderLinesSection(g2d,
+ lines, mid, lines.length, xstart, xend,
+ ypos + DASHED_LINE_Y_OFFSET,
+ false);
+ drawVerticalLineAndLabel(g, xstart, ypos, secondHalfLinesCount, false, nodeLabel);
+
+ g2d.dispose();
+}
+
+ private void drawSecondaryStructureProviderLinesSection(Graphics2D g2d, String[] lines, int start, int end, int xstart, int xend, int baseY, boolean above) {
+ for (int i = start; i < end; i++) {
+ int adjustedY = above
+ ? baseY - ((i - start) * DASHED_LINE_Y_OFFSET)
+ : baseY +((i - start) * DASHED_LINE_Y_OFFSET);
+ Color providerColor = AlignmentUtils.getSecondaryStructureProviderColor(lines[i]);
+ g2d.setColor(providerColor);
+ g2d.drawLine(xstart, adjustedY, xend, adjustedY);
+ }
+ }
+
+ private void drawVerticalLineAndLabel(Graphics g, int xstart, int ypos,
+ int linesCount, boolean above, String nodeLabel) {
+ int adjustedY = above
+ ? ypos - (linesCount) * DASHED_LINE_Y_OFFSET
+ : ypos + (linesCount) * DASHED_LINE_Y_OFFSET;
+
+ // Draw vertical line
+ g.drawLine(xstart, ypos, xstart, adjustedY);
+
+ // Draw label
+ if(above && !nodeLabel.equals(""))
+ g.drawString(nodeLabel, xstart + 2, adjustedY - 2);
+}
+
/**
* DOCUMENT ME!