@Test public void testRender3() { TextComponent textComponent = new TextComponent(); textComponent.setText("<col=0000ff>test<col=00ff00> test"); textComponent.render(graphics); verify(graphics, atLeastOnce()).drawString(eq("test"), anyInt(), anyInt()); verify(graphics, atLeastOnce()).drawString(eq(" test"), anyInt(), anyInt()); verify(graphics, atLeastOnce()).setColor(Color.BLUE); verify(graphics, atLeastOnce()).setColor(Color.GREEN); }
@Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = Text.removeTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(textWithoutCol, x, position.y + 1); graphics.drawString(textWithoutCol, x, position.y - 1); graphics.drawString(textWithoutCol, x + 1, position.y); graphics.drawString(textWithoutCol, x - 1, position.y); } else { graphics.drawString(textWithoutCol, x + 1, position.y + 1); } graphics.setColor(Color.decode("#" + colColor)); graphics.drawString(textWithoutCol, x, position.y); x += fontMetrics.stringWidth(textWithoutCol); } } else { graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(text, position.x, position.y + 1); graphics.drawString(text, position.x, position.y - 1); graphics.drawString(text, position.x + 1, position.y); graphics.drawString(text, position.x - 1, position.y); } else { graphics.drawString(text, position.x + 1, position.y + 1); } graphics.setColor(color); graphics.drawString(text, position.x, position.y); } return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); }
TextComponent implements RenderableEntity { @Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = Text.removeTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(textWithoutCol, x, position.y + 1); graphics.drawString(textWithoutCol, x, position.y - 1); graphics.drawString(textWithoutCol, x + 1, position.y); graphics.drawString(textWithoutCol, x - 1, position.y); } else { graphics.drawString(textWithoutCol, x + 1, position.y + 1); } graphics.setColor(Color.decode("#" + colColor)); graphics.drawString(textWithoutCol, x, position.y); x += fontMetrics.stringWidth(textWithoutCol); } } else { graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(text, position.x, position.y + 1); graphics.drawString(text, position.x, position.y - 1); graphics.drawString(text, position.x + 1, position.y); graphics.drawString(text, position.x - 1, position.y); } else { graphics.drawString(text, position.x + 1, position.y + 1); } graphics.setColor(color); graphics.drawString(text, position.x, position.y); } return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); } }
TextComponent implements RenderableEntity { @Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = Text.removeTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(textWithoutCol, x, position.y + 1); graphics.drawString(textWithoutCol, x, position.y - 1); graphics.drawString(textWithoutCol, x + 1, position.y); graphics.drawString(textWithoutCol, x - 1, position.y); } else { graphics.drawString(textWithoutCol, x + 1, position.y + 1); } graphics.setColor(Color.decode("#" + colColor)); graphics.drawString(textWithoutCol, x, position.y); x += fontMetrics.stringWidth(textWithoutCol); } } else { graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(text, position.x, position.y + 1); graphics.drawString(text, position.x, position.y - 1); graphics.drawString(text, position.x + 1, position.y); graphics.drawString(text, position.x - 1, position.y); } else { graphics.drawString(text, position.x + 1, position.y + 1); } graphics.setColor(color); graphics.drawString(text, position.x, position.y); } return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); }  }
TextComponent implements RenderableEntity { @Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = Text.removeTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(textWithoutCol, x, position.y + 1); graphics.drawString(textWithoutCol, x, position.y - 1); graphics.drawString(textWithoutCol, x + 1, position.y); graphics.drawString(textWithoutCol, x - 1, position.y); } else { graphics.drawString(textWithoutCol, x + 1, position.y + 1); } graphics.setColor(Color.decode("#" + colColor)); graphics.drawString(textWithoutCol, x, position.y); x += fontMetrics.stringWidth(textWithoutCol); } } else { graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(text, position.x, position.y + 1); graphics.drawString(text, position.x, position.y - 1); graphics.drawString(text, position.x + 1, position.y); graphics.drawString(text, position.x - 1, position.y); } else { graphics.drawString(text, position.x + 1, position.y + 1); } graphics.setColor(color); graphics.drawString(text, position.x, position.y); } return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); }  @Override Dimension render(Graphics2D graphics); }
TextComponent implements RenderableEntity { @Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN_W_LOOKAHEAD.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = Text.removeTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(textWithoutCol, x, position.y + 1); graphics.drawString(textWithoutCol, x, position.y - 1); graphics.drawString(textWithoutCol, x + 1, position.y); graphics.drawString(textWithoutCol, x - 1, position.y); } else { graphics.drawString(textWithoutCol, x + 1, position.y + 1); } graphics.setColor(Color.decode("#" + colColor)); graphics.drawString(textWithoutCol, x, position.y); x += fontMetrics.stringWidth(textWithoutCol); } } else { graphics.setColor(Color.BLACK); if (outline) { graphics.drawString(text, position.x, position.y + 1); graphics.drawString(text, position.x, position.y - 1); graphics.drawString(text, position.x + 1, position.y); graphics.drawString(text, position.x - 1, position.y); } else { graphics.drawString(text, position.x + 1, position.y + 1); } graphics.setColor(color); graphics.drawString(text, position.x, position.y); } return new Dimension(fontMetrics.stringWidth(text), fontMetrics.getHeight()); }  @Override Dimension render(Graphics2D graphics);  }