Permalink
Browse files

Removed scale and zoom form renderer and replaced with values form th…

…e generator parameters
  • Loading branch information...
1 parent 3d8b420 commit 8b97071ed9e2cbb22446bfa611d4bf2074dce8d5 Arvid Berg committed with egonw Jun 8, 2010
Showing with 17 additions and 23 deletions.
  1. +17 −23 src/main/org/openscience/cdk/renderer/Renderer.java
@@ -182,13 +182,6 @@ public void setup(IReaction reaction, Rectangle screen) {
this.setup();
}
- public void reset() {
- modelCenter = new Point2d(0, 0);
- drawCenter = new Point2d(200, 200);
- zoom = 1.0;
- setup();
- }
-
/**
* Determine the overlap of the diagram with the screen, and shift (if
* necessary) the diagram draw center. It returns a rectangle only because
@@ -249,7 +242,7 @@ public Rectangle shift(Rectangle screenBounds, Rectangle diagramBounds) {
*/
public void setScale(IChemModel chemModel) {
double bondLength = Renderer.calculateAverageBondLength(chemModel);
- this.scale = this.calculateScaleForBondLength(bondLength);
+ double scale = this.calculateScaleForBondLength(bondLength);
// store the scale so that other components can access it
this.rendererModel.getRenderingParameter(Scale.class).setValue(scale);
@@ -264,7 +257,7 @@ public void setScale(IChemModel chemModel) {
*/
public void setScale(IReactionSet reactionSet) {
double bondLength = Renderer.calculateAverageBondLength(reactionSet);
- this.scale = this.calculateScaleForBondLength(bondLength);
+ double scale = this.calculateScaleForBondLength(bondLength);
// store the scale so that other components can access it
this.rendererModel.getRenderingParameter(Scale.class).setValue(scale);
@@ -278,7 +271,7 @@ public void setScale(IReactionSet reactionSet) {
*/
public void setScale(IReaction reaction) {
double bondLength = Renderer.calculateAverageBondLength(reaction);
- this.scale = this.calculateScaleForBondLength(bondLength);
+ double scale = this.calculateScaleForBondLength(bondLength);
// store the scale so that other components can access it
this.rendererModel.getRenderingParameter(Scale.class).setValue(scale);
@@ -292,7 +285,7 @@ public void setScale(IReaction reaction) {
*/
public void setScale(IMoleculeSet moleculeSet) {
double bondLength = Renderer.calculateAverageBondLength(moleculeSet);
- this.scale = this.calculateScaleForBondLength(bondLength);
+ double scale = this.calculateScaleForBondLength(bondLength);
// store the scale so that other components can access it
this.rendererModel.getRenderingParameter(Scale.class).setValue(scale);
@@ -728,7 +721,6 @@ public void setDrawCenter(double x, double y) {
public void setZoom(double z) {
getRenderer2DModel().getRenderingParameter(
ZoomFactor.class).setValue( z );
- zoom = z;
setup();
}
@@ -772,7 +764,7 @@ public void setZoomToFit(double drawWidth,
double widthRatio = drawWidth / (diagramWidth + (2 * m));
double heightRatio = drawHeight / (diagramHeight + (2 * m));
- this.zoom = Math.min(widthRatio, heightRatio);
+ double zoom = Math.min(widthRatio, heightRatio);
this.fontManager.setFontForZoom(zoom);
@@ -818,7 +810,7 @@ private void paint(IDrawVisitor drawVisitor,
* the bounding box of the model
*/
private void setupTransformNatural(Rectangle2D modelBounds) {
- this.zoom = this.rendererModel.getRenderingParameter(
+ double zoom = this.rendererModel.getRenderingParameter(
ZoomFactor.class).getValue();
this.fontManager.setFontForZoom(zoom);
this.setup();
@@ -848,7 +840,7 @@ private void setupTransformToFit(Rectangle2D screenBounds,
this.setDrawCenter(
screenBounds.getCenterX(), screenBounds.getCenterY());
- this.scale = this.calculateScaleForBondLength(bondLength);
+ double scale = this.calculateScaleForBondLength(bondLength);
double drawWidth = screenBounds.getWidth();
double drawHeight = screenBounds.getHeight();
@@ -866,9 +858,7 @@ private void setupTransformToFit(Rectangle2D screenBounds,
}
// set the scale in the renderer model for the generators
- if (reset) {
this.rendererModel.getRenderingParameter(Scale.class).setValue(scale);
- }
this.setup();
}
@@ -883,7 +873,7 @@ private void setupTransformToFit(Rectangle2D screenBounds,
*/
private double calculateScaleForBondLength(double modelBondLength) {
if (Double.isNaN(modelBondLength) || modelBondLength == 0) {
- return Renderer.DEFAULT_SCALE;
+ return rendererModel.getRenderingParameter(Scale.class).getDefault();
} else {
return this.rendererModel.getRenderingParameter(BondLength.class)
.getValue() / modelBondLength;
@@ -904,6 +894,9 @@ private Rectangle convertToDiagramBounds(Rectangle2D modelBounds) {
double mw = modelBounds.getWidth();
double mh = modelBounds.getHeight();
+ double scale = rendererModel.getRenderingParameter(Scale.class).getValue();
+ double zoom = rendererModel.getRenderingParameter(ZoomFactor.class).getValue();
+
Point2d mc = this.toScreenCoordinates(cx, cy);
// special case for 0 or 1 atoms
@@ -922,13 +915,14 @@ private Rectangle convertToDiagramBounds(Rectangle2D modelBounds) {
}
private void setup() {
-
+ double scale = rendererModel.getRenderingParameter(Scale.class).getValue();
+ double zoom = rendererModel.getRenderingParameter(ZoomFactor.class).getValue();
// set the transform
try {
this.transform = new AffineTransform();
this.transform.translate(this.drawCenter.x, this.drawCenter.y);
- this.transform.scale(this.scale, this.scale);
- this.transform.scale(this.zoom, this.zoom);
+ this.transform.scale(scale, scale);
+ this.transform.scale(zoom, zoom);
this.transform.translate(-this.modelCenter.x, -this.modelCenter.y);
// System.err.println(String.format(
// "drawCenter=%s scale=%s zoom=%s modelCenter=%s",
@@ -942,8 +936,8 @@ private void setup() {
"null pointer when setting transform: " +
"drawCenter=%s scale=%s zoom=%s modelCenter=%s",
this.drawCenter,
- this.scale,
- this.zoom,
+ scale,
+ zoom,
this.modelCenter));
}
}

0 comments on commit 8b97071

Please sign in to comment.