Skip to content

Commit

Permalink
fix border thickness
Browse files Browse the repository at this point in the history
  • Loading branch information
Exslims committed Aug 5, 2017
1 parent 631f3d8 commit 5438d23
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,29 @@ protected void paintString(Graphics g, int x, int y, int width, int height, int
g2.setFont(tracker.getFont());
Point renderLocation = getStringPlacement(g2, progressString,
x, y, width, height);
if (value >= descriptor.getDefaultValueTextThreshold()) {
g2.setColor(this.descriptor.getDefaultValueTextColor());
} else if (value >= this.descriptor.getMediumValueTextThreshold()) {
g2.setColor(this.descriptor.getMediumValueTextColor());
} else {
g2.setColor(this.descriptor.getLowValueTextColor());
}
g2.setColor(this.getColorByValue());
SwingUtilities2.drawString(tracker, g2, progressString,
renderLocation.x, renderLocation.y);
if(this.descriptor.getOutlineThickness() > 0) {
FontRenderContext frc = g2.getFontRenderContext();
TextLayout textTl = new TextLayout(progressString, tracker.getFont(), frc);
Shape outline = textTl.getOutline(null);
g2.translate(renderLocation.x, renderLocation.y);
Stroke oldStroke = g2.getStroke();
g2.setStroke(new BasicStroke(this.descriptor.getOutlineThickness()));
Color oldColor = g2.getColor();
g2.setColor(this.descriptor.getOutlineColor());
g2.draw(outline);
g2.setColor(oldColor);
g2.setStroke(oldStroke);
}
}
}
protected void paintBorder(Graphics g){
int thickness = descriptor.getThickness();
if(thickness > 0) {
Graphics2D g2 = (Graphics2D) g;
Graphics2D g2 = this.prepareAdapter(g);
g2.setColor(getColorByValue());
Stroke oldStroke = g2.getStroke();
if(!descriptor.isBindToTextColor()) {
g2.setPaint(this.descriptor.getBorderColor());
Expand All @@ -85,6 +84,16 @@ protected void paintBorder(Graphics g){
g2.setStroke(oldStroke);
}
}
private Color getColorByValue(){
float value = tracker.getValue() / 1000f;
if (value >= descriptor.getDefaultValueTextThreshold()) {
return this.descriptor.getDefaultValueTextColor();
} else if (value >= this.descriptor.getMediumValueTextThreshold()) {
return this.descriptor.getMediumValueTextColor();
} else {
return this.descriptor.getLowValueTextColor();
}
}

protected Point getStringPlacement(Graphics g, String progressString,
int x,int y,int width,int height) {
Expand Down

0 comments on commit 5438d23

Please sign in to comment.