@Test public void testRender() { TextComponent textComponent = new TextComponent(); textComponent.setText("test"); textComponent.setColor(Color.RED); textComponent.render(graphics); verify(graphics, times(2)).drawString(eq("test"), anyInt(), anyInt()); verify(graphics, atLeastOnce()).setColor(Color.RED); }
@Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); 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); 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.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); 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); 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.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); 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); 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.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); 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); 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()); }  static String textWithoutColTags(String text); @Override Dimension render(Graphics2D graphics); }
TextComponent implements RenderableEntity { @Override public Dimension render(Graphics2D graphics) { final FontMetrics fontMetrics = graphics.getFontMetrics(); if (COL_TAG_PATTERN.matcher(text).find()) { final String[] parts = COL_TAG_PATTERN_W_LOOKAHEAD.split(text); int x = position.x; for (String textSplitOnCol : parts) { final String textWithoutCol = textWithoutColTags(textSplitOnCol); final String colColor = textSplitOnCol.substring(textSplitOnCol.indexOf("=") + 1, textSplitOnCol.indexOf(">")); graphics.setColor(Color.BLACK); 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); 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()); }  static String textWithoutColTags(String text); @Override Dimension render(Graphics2D graphics);  }