Permalink
Browse files

No longer caches the background color, fixing that when the value in …

…the model changes *after* passing it to the visitor it is not updated too
  • Loading branch information...
1 parent c4067cd commit e4786fa02889c14f7bf8da452333b7af05a70d7d @egonw egonw committed Aug 26, 2011
Showing with 10 additions and 12 deletions.
  1. +10 −12 src/main/org/openscience/cdk/renderer/visitor/AWTDrawVisitor.java
@@ -57,7 +57,6 @@
import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.Scale;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.UseAntiAliasing;
-import org.openscience.cdk.renderer.generators.IGeneratorParameter;
/**
@@ -90,8 +89,6 @@
private final Graphics2D graphics;
- private Color backgroundColor;
-
/**
* Constructs a new {@link IDrawVisitor} using the AWT widget toolkit,
* taking a {@link Graphics2D} object to which the chemical content
@@ -106,12 +103,6 @@ public AWTDrawVisitor(Graphics2D graphics) {
this.rendererModel = null;
map.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
-
- for (IGeneratorParameter<?> param :
- new BasicSceneGenerator().getParameters()) {
- if (param instanceof BasicSceneGenerator.BackgroundColor)
- this.backgroundColor = (Color)param.getDefault();
- }
}
private void visit(ElementGroup elementGroup) {
@@ -175,14 +166,21 @@ private int transformY(double yCoord) {
return result;
}
+ private Color getBackgroundColor() {
+ if (rendererModel == null)
+ return new BasicSceneGenerator.BackgroundColor().getDefault();
+
+ return rendererModel.getParameter(BasicSceneGenerator.BackgroundColor.class).getValue();
+ }
+
private void visit(TextElement textElement) {
this.graphics.setFont(this.fontManager.getFont());
Point point = this.getTextBasePoint(
textElement.text, textElement.xCoord, textElement.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(
textElement.text, textElement.xCoord, textElement.yCoord, graphics);
- this.graphics.setColor(backgroundColor);
+ this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(textElement.color);
this.graphics.drawString(textElement.text, point.x, point.y);
@@ -260,7 +258,7 @@ private void visit(AtomSymbolElement atomSymbol) {
atomSymbol.text, atomSymbol.xCoord, atomSymbol.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(atomSymbol.text, atomSymbol.xCoord, atomSymbol.yCoord, graphics);
- this.graphics.setColor(backgroundColor);
+ this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(atomSymbol.color);
this.graphics.drawString(atomSymbol.text, point.x, point.y);
@@ -384,7 +382,7 @@ private void visit(TextGroupElement textGroup) {
textGroup.text, textGroup.xCoord, textGroup.yCoord, graphics);
Rectangle2D textBounds =
this.getTextBounds(textGroup.text, textGroup.xCoord, textGroup.yCoord, graphics);
- this.graphics.setColor(backgroundColor);
+ this.graphics.setColor(getBackgroundColor());
this.graphics.fill(textBounds);
this.graphics.setColor(textGroup.color);
this.graphics.drawString(textGroup.text, point.x, point.y);

0 comments on commit e4786fa

Please sign in to comment.