Skip to content

Commit a35f3ca

Browse files
committed
Add stroke property to oval element.
1 parent 36f29ce commit a35f3ca

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

display/renderawt/src/main/java/org/openscience/cdk/renderer/visitor/AWTDrawVisitor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ private void visit(OvalElement oval) {
215215
this.graphics.fillOval(transformX(oval.xCoord) - radius, transformY(oval.yCoord) - radius, diameter,
216216
diameter);
217217
} else {
218+
Stroke savedStroke = this.graphics.getStroke();
219+
220+
// scale the stroke by zoom + scale (both included in the AffineTransform)
221+
float width = (float) (oval.stroke * transform.getScaleX());
222+
if (width < minStroke) width = minStroke;
223+
224+
int key = (int) (width * 4); // store 2.25, 2.5, 2.75 etc to separate keys
225+
226+
if (strokeCache && strokeMap.containsKey(key)) {
227+
this.graphics.setStroke(strokeMap.get(key));
228+
} else {
229+
BasicStroke stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
230+
this.graphics.setStroke(stroke);
231+
strokeMap.put(key, stroke);
232+
}
233+
218234
this.graphics.drawOval(transformX(oval.xCoord) - radius, transformY(oval.yCoord) - radius, diameter,
219235
diameter);
220236
}

display/renderbasic/src/main/java/org/openscience/cdk/renderer/elements/OvalElement.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public class OvalElement implements IRenderingElement {
3636
public final double yCoord;
3737

3838
/** The radius of the oval. **/
39-
public final double radius; // TODO : width AND height
39+
public final double radius;
40+
41+
/** The stroke width. */
42+
public final double stroke;
4043

4144
/** If true, draw the oval as filled. **/
4245
public final boolean fill;
@@ -76,10 +79,22 @@ public OvalElement(double xCoord, double yCoord, double radius, Color color) {
7679
* @param fill if true, fill the oval when drawing
7780
* @param color the color of the oval
7881
*/
79-
public OvalElement(double xCoord, double yCoord, double radius, boolean fill, Color color) {
82+
public OvalElement(double xCoord, double yCoord, double radius, double stroke,
83+
boolean fill, Color color) {
84+
this.xCoord = xCoord;
85+
this.yCoord = yCoord;
86+
this.radius = radius;
87+
this.stroke = stroke;
88+
this.fill = fill;
89+
this.color = color;
90+
}
91+
92+
public OvalElement(double xCoord, double yCoord, double radius,
93+
boolean fill, Color color) {
8094
this.xCoord = xCoord;
8195
this.yCoord = yCoord;
8296
this.radius = radius;
97+
this.stroke = 1;
8398
this.fill = fill;
8499
this.color = color;
85100
}

display/renderbasic/src/main/java/org/openscience/cdk/renderer/generators/standard/StandardDonutGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ final class StandardDonutGenerator {
6767
private final boolean delocalisedDonuts;
6868
private final double dbSpacing;
6969
private final double scale;
70+
private final double stroke;
7071
private final Color fgColor;
7172
private final Font font;
7273
private final IAtomContainer mol;
@@ -77,13 +78,15 @@ final class StandardDonutGenerator {
7778
* @param font the font
7879
* @param model the rendering parameters
7980
*/
80-
StandardDonutGenerator(IAtomContainer mol, Font font, RendererModel model) {
81+
StandardDonutGenerator(IAtomContainer mol, Font font, RendererModel model,
82+
double stroke) {
8183
this.mol = mol;
8284
this.font = font;
8385
this.forceDelocalised = model.get(ForceDelocalisedBondDisplay.class);
8486
this.delocalisedDonuts = model.get(DelocalisedDonutsBondDisplay.class);
8587
this.dbSpacing = model.get(StandardGenerator.BondSeparation.class);
8688
this.scale = model.get(BasicSceneGenerator.Scale.class);
89+
this.stroke = stroke;
8790
this.fgColor = model.get(StandardGenerator.AtomColor.class).getAtomColor(
8891
mol.getBuilder().newInstance(IAtom.class, "C"));
8992
}
@@ -150,7 +153,7 @@ else if (charge > +1)
150153
double n = ring.getBondCount();
151154
double r = s / (2 * Math.tan(Math.PI / n));
152155
group.add(new OvalElement(p2.x, p2.y, r - 1.5*dbSpacing,
153-
false, fgColor));
156+
stroke, false, fgColor));
154157
}
155158
return group;
156159
}

display/renderbasic/src/main/java/org/openscience/cdk/renderer/generators/standard/StandardGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ public IRenderingElement generate(IAtomContainer container, RendererModel parame
212212
ElementGroup annotations = new ElementGroup();
213213

214214
StandardDonutGenerator donutGenerator;
215-
donutGenerator = new StandardDonutGenerator(container, font, parameters);
215+
donutGenerator = new StandardDonutGenerator(container, font, parameters,
216+
stroke);
216217
IRenderingElement donuts = donutGenerator.generate();
217218

218219
AtomSymbol[] symbols = generateAtomSymbols(container, symbolRemap,

0 commit comments

Comments
 (0)