test_class.file: runelite-client/src/test/java/net/runelite/client/ui/overlay/components/TooltipComponentTest.java
test_class.identifier: TooltipComponentTest
test_case.body: @Test
  	public void testCalculateTextWidth()
  	{
  		FontMetrics fontMetics = mock(FontMetrics.class);
  		when(fontMetics.stringWidth(anyString())).thenAnswer((invocation) -> ((String) invocation.getArguments()[0]).length());
  
  		assertEquals(11, calculateTextWidth(fontMetics, "line1<col=ff0000>>line2"));
  	}
test_case.class_method_signature: TooltipComponentTest.testCalculateTextWidth()
test_case.full_signature: @Test public void testCalculateTextWidth()
test_case.identifier: testCalculateTextWidth
test_case.invocations: mock thenAnswer when stringWidth anyString length getArguments assertEquals calculateTextWidth
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCalculateTextWidth()
focal_class.declarator: BR = Pattern.compile("</br>")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern BR = Pattern.compile("</br>");
focal_class.type: Pattern
focal_class.var_name: BR
focal_class.declarator: OFFSET = 4
focal_class.modifier: private static final
focal_class.original_string: private static final int OFFSET = 4;
focal_class.type: int
focal_class.var_name: OFFSET
focal_class.declarator: MOD_ICON_WIDTH = 13
focal_class.modifier: private static final
focal_class.original_string: private static final int MOD_ICON_WIDTH = 13;
focal_class.type: int
focal_class.var_name: MOD_ICON_WIDTH
focal_class.declarator: text
focal_class.modifier: private
focal_class.original_string: private String text;
focal_class.type: String
focal_class.var_name: text
focal_class.declarator: backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR
focal_class.modifier: private
focal_class.original_string: private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
focal_class.type: Color
focal_class.var_name: backgroundColor
focal_class.declarator: position = new Point()
focal_class.modifier: private
focal_class.original_string: private Point position = new Point();
focal_class.type: Point
focal_class.var_name: position
focal_class.declarator: modIcons
focal_class.modifier: private
focal_class.original_string: private IndexedSprite[] modIcons;
focal_class.type: IndexedSprite[]
focal_class.var_name: modIcons
focal_class.file: runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TooltipComponent.java
focal_class.identifier: TooltipComponent
focal_class.interfaces: implements LayoutableRenderableEntity
focal_class.class_method_signature: TooltipComponent.render(Graphics2D graphics)
focal_class.full_signature: @Override public Dimension render(Graphics2D graphics)
focal_class.identifier: render
focal_class.modifiers: @Override public
focal_class.parameters: (Graphics2D graphics)
focal_class.return: Dimension
focal_class.signature: Dimension render(Graphics2D graphics)
focal_class.class_method_signature: TooltipComponent.calculateTextWidth(FontMetrics metrics, String line)
focal_class.full_signature: @VisibleForTesting static int calculateTextWidth(FontMetrics metrics, String line)
focal_class.identifier: calculateTextWidth
focal_class.modifiers: @VisibleForTesting static
focal_class.parameters: (FontMetrics metrics, String line)
focal_class.return: int
focal_class.signature: int calculateTextWidth(FontMetrics metrics, String line)
focal_class.class_method_signature: TooltipComponent.renderModIcon(Graphics2D graphics, int x, int y, IndexedSprite modIcon)
focal_class.full_signature: private void renderModIcon(Graphics2D graphics, int x, int y, IndexedSprite modIcon)
focal_class.identifier: renderModIcon
focal_class.modifiers: private
focal_class.parameters: (Graphics2D graphics, int x, int y, IndexedSprite modIcon)
focal_class.return: void
focal_class.signature: void renderModIcon(Graphics2D graphics, int x, int y, IndexedSprite modIcon)
focal_class.class_method_signature: TooltipComponent.getBounds()
focal_class.full_signature: @Override public Rectangle getBounds()
focal_class.identifier: getBounds
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Rectangle
focal_class.signature: Rectangle getBounds()
focal_class.class_method_signature: TooltipComponent.setPreferredLocation(Point position)
focal_class.full_signature: @Override public void setPreferredLocation(Point position)
focal_class.identifier: setPreferredLocation
focal_class.modifiers: @Override public
focal_class.parameters: (Point position)
focal_class.return: void
focal_class.signature: void setPreferredLocation(Point position)
focal_class.class_method_signature: TooltipComponent.setPreferredSize(Dimension dimension)
focal_class.full_signature: @Override public void setPreferredSize(Dimension dimension)
focal_class.identifier: setPreferredSize
focal_class.modifiers: @Override public
focal_class.parameters: (Dimension dimension)
focal_class.return: void
focal_class.signature: void setPreferredSize(Dimension dimension)
focal_method.body: @VisibleForTesting
  	static int calculateTextWidth(FontMetrics metrics, String line)
  	{
  		char[] chars = line.toCharArray();
  		int textWidth = 0;
  
  		int begin = 0;
  		boolean inTag = false;
  		for (int j = 0; j < chars.length; j++)
  		{
  			if (chars[j] == '<')
  			{
  				textWidth += metrics.stringWidth(line.substring(begin, j));
  
  				begin = j;
  				inTag = true;
  			}
  			else if (chars[j] == '>' && inTag)
  			{
  				String subLine = line.substring(begin + 1, j);
  
  				if (subLine.startsWith("img="))
  				{
  					textWidth += MOD_ICON_WIDTH;
  				}
  				else if (!subLine.startsWith("col=") && !subLine.startsWith("/col"))
  				{
  					textWidth += metrics.stringWidth(line.substring(begin, j + 1));
  				}
  
  				begin = j + 1;
  				inTag = false;
  			}
  		}
  
  		// Include trailing text (after last tag)
  		textWidth += metrics.stringWidth(line.substring(begin));
  
  		return textWidth;
  	}
focal_method.class_method_signature: TooltipComponent.calculateTextWidth(FontMetrics metrics, String line)
focal_method.full_signature: @VisibleForTesting static int calculateTextWidth(FontMetrics metrics, String line)
focal_method.identifier: calculateTextWidth
focal_method.invocations: toCharArray stringWidth substring substring startsWith startsWith startsWith stringWidth substring stringWidth substring
focal_method.modifiers: @VisibleForTesting static
focal_method.parameters: (FontMetrics metrics, String line)
focal_method.return: int
focal_method.signature: int calculateTextWidth(FontMetrics metrics, String line)