Skip to content

Commit

Permalink
Merged in cdk-1.4.x with the 1.4.3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Sep 18, 2011
2 parents a1894f2 + f5f9d23 commit 191ea5d
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/main/org/openscience/cdk/ReactionScheme.java
Expand Up @@ -25,7 +25,10 @@
package org.openscience.cdk;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IReaction;
Expand Down Expand Up @@ -125,6 +128,18 @@ public Object clone() throws CloneNotSupportedException {
for (IReaction reaction : reactions()) {
clone.addReaction((IReaction)reaction.clone());
}
// clone the properties
if (getProperties() != null) {
Map<Object, Object> properties = getProperties();
Map<Object, Object> clonedHashtable = new HashMap<Object, Object>();
Iterator<Object> keys = properties.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
Object value = properties.get(key);
clonedHashtable.put(key, value);
}
clone.setProperties(clonedHashtable);
}

return clone;
}
Expand Down
66 changes: 66 additions & 0 deletions src/main/org/openscience/cdk/renderer/elements/ArrowElement.java
@@ -0,0 +1,66 @@
/* Copyright (C) 2009 Stefan Kuhn <shk3@users.sf.net>
* 2011 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@list.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.renderer.elements;

import java.awt.Color;

/**
* {@link IRenderingElement} for linear arrows.
*
* @cdk.module renderbasic
*/
public class ArrowElement implements IRenderingElement {

public final double startX;
public final double startY;
public final double endX;
public final double endY;
public final double width;
public final Color color;
public final boolean direction;

/**
* Constructor for an arrow element, based on starting point, end point, width,
* direction, and color.
*
* @param startX X coordinate of the point where the arrow starts.
* @param startY Y coodrinate of the point where the arrow starts.
* @param endX X coordinate of the point where the arrow ends.
* @param endY Y coordinate of the point where the arrow ends.
* @param width width of the arrow line.
* @param direction true is the arrow points from start to end, false if from end to start
* @param color {@link Color} of the arrow
*/
public ArrowElement(double startX, double startY, double endX, double endY,
double width, boolean direction, Color color) {
this.endX = startX;
this.endY = startY;
this.startX = endX;
this.startY = endY;
this.width = width;
this.color = color;
this.direction = direction;
}

/** {@inheritDoc} */
public void accept(IRenderingVisitor v) {
v.visit(this);
}
}
Expand Up @@ -42,6 +42,22 @@
@TestClass("org.openscience.cdk.renderer.generators.BasicSceneGeneratorTest")
public class BasicSceneGenerator implements IGenerator<IAtomContainer> {

/**
* The width of the head of arrows.
*
* @author egonw
*/
public static class ArrowHeadWidth extends
AbstractGeneratorParameter<Double> {
/** Returns the default arrow head width.
* @return 10.0 */
public Double getDefault() {
return 10.0;
}
}
private IGeneratorParameter<Double> arrowHeadWidth =
new ArrowHeadWidth();

/**
* Determines if tooltips are to be shown.
*/
Expand Down Expand Up @@ -216,7 +232,8 @@ public List<IGeneratorParameter<?>> getParameters() {
scale,
fitToScreen,
showMoleculeTitle,
showTooltip
showTooltip,
arrowHeadWidth
}
);
}
Expand Down
39 changes: 39 additions & 0 deletions src/main/org/openscience/cdk/renderer/visitor/AWTDrawVisitor.java
Expand Up @@ -39,6 +39,7 @@
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.ArrowElement;
import org.openscience.cdk.renderer.elements.AtomSymbolElement;
import org.openscience.cdk.renderer.elements.ElementGroup;
import org.openscience.cdk.renderer.elements.GeneralPath;
Expand All @@ -55,6 +56,7 @@
import org.openscience.cdk.renderer.font.IFontManager;
import org.openscience.cdk.renderer.generators.BasicBondGenerator.WedgeWidth;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.ArrowHeadWidth;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.Scale;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator.UseAntiAliasing;

Expand Down Expand Up @@ -375,6 +377,41 @@ public int currentSegment( float[] coords ) {
};
}

private void visit(ArrowElement line) {
double scale = rendererModel.getParameter(
Scale.class).getValue();
Stroke savedStroke = graphics.getStroke();

int w = (int) (line.width * scale);
if (strokeMap.containsKey(w)) {
graphics.setStroke(strokeMap.get(w));
} else {
BasicStroke stroke = new BasicStroke(w);
graphics.setStroke(stroke);
strokeMap.put(w, stroke);
}

graphics.setColor(line.color);
int[] a = this.transformPoint(line.startX, line.startY);
int[] b = this.transformPoint(line.endX, line.endY);
graphics.drawLine(a[0], a[1], b[0], b[1]);
double aW = rendererModel.getParameter(
ArrowHeadWidth.class
).getValue() / scale;
if(line.direction){
int[] c = this.transformPoint(line.startX-aW, line.startY-aW);
int[] d = this.transformPoint(line.startX-aW, line.startY+aW);
graphics.drawLine(a[0], a[1], c[0], c[1]);
graphics.drawLine(a[0], a[1], d[0], d[1]);
}else{
int[] c = this.transformPoint(line.endX+aW, line.endY-aW);
int[] d = this.transformPoint(line.endX+aW, line.endY+aW);
graphics.drawLine(b[0], b[1], c[0], c[1]);
graphics.drawLine(b[0], b[1], d[0], d[1]);
}
graphics.setStroke(savedStroke);
}

private void visit(TextGroupElement textGroup) {
this.graphics.setFont(this.fontManager.getFont());
Point point =
Expand Down Expand Up @@ -476,6 +513,8 @@ else if (element instanceof PathElement)
visit((PathElement) element);
else if (element instanceof GeneralPath)
visit((GeneralPath)element);
else if (element instanceof ArrowElement)
visit((ArrowElement) element);
else
System.err.println("Visitor method for "
+ element.getClass().getName() + " is not implemented");
Expand Down
15 changes: 15 additions & 0 deletions src/main/org/openscience/cdk/silent/ReactionScheme.java
Expand Up @@ -19,7 +19,10 @@
package org.openscience.cdk.silent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IReaction;
Expand Down Expand Up @@ -119,6 +122,18 @@ public Object clone() throws CloneNotSupportedException {
for (IReaction reaction : reactions()) {
clone.addReaction((IReaction)reaction.clone());
}
// clone the properties
if (getProperties() != null) {
Map<Object, Object> properties = getProperties();
Map<Object, Object> clonedHashtable = new HashMap<Object, Object>();
Iterator<Object> keys = properties.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
Object value = properties.get(key);
clonedHashtable.put(key, value);
}
clone.setProperties(clonedHashtable);
}

return clone;
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.RenderbasicCoverageTest;
import org.openscience.cdk.renderer.AtomContainerRendererTest;
import org.openscience.cdk.renderer.elements.ArrowElementTest;
import org.openscience.cdk.renderer.elements.AtomSymbolElementTest;
import org.openscience.cdk.renderer.elements.GeneralPathTest;
import org.openscience.cdk.renderer.elements.LineElementTest;
Expand Down Expand Up @@ -62,6 +63,7 @@
RingElementTest.class,
AtomSymbolElementTest.class,
RectangleElementTest.class,
ArrowElementTest.class,
GeneralPathTest.class,
AWTFontManagerTest.class,
LineToTest.class,
Expand Down
@@ -0,0 +1,41 @@
/* Copyright (C) 2011 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version. All we ask is that proper credit is given for our work,
* which includes - but is not limited to - adding the above copyright notice to
* the beginning of your source code files, and to any copyright notice that you
* may distribute with programs based on this work.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.renderer.elements;

import java.awt.Color;

import org.junit.BeforeClass;

/**
* @cdk.module test-renderbasic
*/
public class ArrowElementTest extends AbstractElementTest {

@BeforeClass
public static void setup() {
IRenderingElement element = new ArrowElement(
0, 0, 1, 1, 1.0, true, Color.orange
);
setRenderingElement(element);
}

}

0 comments on commit 191ea5d

Please sign in to comment.