Skip to content

Commit

Permalink
Merged in the cdk-1.4.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed Dec 10, 2011
2 parents d8d6eee + 1142dc6 commit 46f2ad0
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 30 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -33,6 +33,7 @@ Jonty Lawson
Daniel Leidert
Edgar Luttmann
Todd Martin
John May
Nathanaël Mazuir
Stephan Michels
Scooter Morris
Expand Down
82 changes: 63 additions & 19 deletions src/main/org/openscience/cdk/controller/IMouseEventRelay.java
@@ -1,6 +1,5 @@
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 2007 Niels Out <nielsout@users.sf.net>
/* Copyright (C) 2007 Niels Out <nielsout@users.sf.net>
* 2011 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net or nout@science.uva.nl
*
Expand All @@ -25,54 +24,99 @@
package org.openscience.cdk.controller;

/**
* Widget toolkit-independent interface to relay for mouse events.
*
* @cdk.module control
*/
public interface IMouseEventRelay {

/**
* Event to signal that the left mouse button has been released.
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX the x part of the screen coordinate where the event happened.
* @param screenCoordY the y part of the screen coordinate where the event happened.
*/
public abstract void mouseClickedUp(int screenCoordX, int screenCoordY);

/**
* Event to signal that the left mouse button has been pushed but not released yet.
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX the x part of the screen coordinate where the event happened.
* @param screenCoordY the y part of the screen coordinate where the event happened.
*/
public abstract void mouseClickedDown(int screenCoordX, int screenCoordY);

/**
* Event to signal that the right mouse button has been pushed but not released yet.
*
* @param screenCoordX the x part of the screen coordinate where the event happened.
* @param screenCoordY the y part of the screen coordinate where the event happened.
*/
public abstract void mouseClickedDownRight(int x, int y);

/**
* Event to signal that the right mouse button has been released.
*
* @param screenCoordX the x part of the screen coordinate where the event happened.
* @param screenCoordY the y part of the screen coordinate where the event happened.
*/
public abstract void mouseClickedUpRight(int x, int y);

/**
* Event to signal that a mouse button has been double clicked.
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX the x part of the screen coordinate where the event happened.
* @param screenCoordY the y part of the screen coordinate where the event happened.
*/
public abstract void mouseClickedDouble(int screenCoordX, int screenCoordY);

/**
* Event to signal that a mouse has been moved to the new coordinates.
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX the x part of the latest screen coordinate.
* @param screenCoordY the y part of the latest screen coordinate.
*/
public abstract void mouseMove(int screenCoordX, int screenCoordY);

/**
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX
* @param screenCoordY
*/
public abstract void mouseEnter(int screenCoordX, int screenCoordY);

/**
*
* @param screenCoordX
* @param screenCoordY
* @param screenCoordX
* @param screenCoordY
*/
public abstract void mouseExit(int screenCoordX, int screenCoordY);

/**
* Event to signal that a mouse has been dragged from one point to
* a next.
*
* @param screenCoordXFrom
* @param screenCoordYFrom
* @param screenCoordXTo
* @param screenCoordYTo
* @param screenCoordXFrom the x part of the screen coordinate dragged from.
* @param screenCoordYFrom the y part of the screen coordinate dragged from.
* @param screenCoordXTo the x part of the screen coordinate dragged to.
* @param screenCoordYTo the y part of the screen coordinate dragged to.
*/
public abstract void mouseDrag(int screenCoordXFrom, int screenCoordYFrom, int screenCoordXTo, int screenCoordYTo);

/**
* Event to signal that the mouse wheel has been rotated a certain amount forward.
*
* @param rotation an platform-specific amount of rotation of the wheel
* @see #mouseWheelMovedBackward(int)
*/
public abstract void mouseWheelMovedForward(int rotation);

/**
* Event to signal that the mouse wheel has been rotated a certain amount backward.
*
* @param rotation an platform-specific amount of rotation of the wheel
* @see #mouseWheelMovedForward(int)
*/
public abstract void mouseWheelMovedBackward(int rotation);

}
9 changes: 8 additions & 1 deletion src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -752,12 +752,19 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce
int aliasAtomNumber = Integer.parseInt(line.replaceFirst("A\\s{1,4}", "")) - RGroupCounter;
line = input.readLine(); linecount++;
String[] aliasArray = line.split("\\\\");
// name of the alias atom like R1 odr R2 etc.
// name of the alias atom like R1 or R2 etc.
String alias = "";
for (int i = 0; i < aliasArray.length; i++) {
alias += aliasArray[i];
}
IAtom aliasAtom = outputContainer.getAtom(aliasAtomNumber);

// skip if already a pseudoatom
if(aliasAtom instanceof IPseudoAtom){
((IPseudoAtom) aliasAtom).setLabel(alias);
continue;
}

IAtom newPseudoAtom = molecule.getBuilder().newInstance(IPseudoAtom.class,alias);
if(aliasAtom.getPoint2d() != null) {
newPseudoAtom.setPoint2d(aliasAtom.getPoint2d());
Expand Down
34 changes: 32 additions & 2 deletions src/main/org/openscience/cdk/renderer/visitor/AWTDrawVisitor.java
Expand Up @@ -85,13 +85,43 @@ public class AWTDrawVisitor extends AbstractAWTDrawVisitor {

private final Map<Integer, BasicStroke> strokeMap =
new HashMap<Integer, BasicStroke>();


/**
* Returns the current {@link RendererModel}.
*
* @return the current model
*/
@TestMethod("testGetRendererModel")
public RendererModel getRendererModel() {
return rendererModel;
}

/**
* Returns the current stroke map.
*
* @return a {@link Map} with Integer as keys and {@link BasicStroke}s.
*/
@TestMethod("testGetStrokeMap")
public Map<Integer, BasicStroke> getStrokeMap() {
return strokeMap;
}

private final Map<TextAttribute, Object> map =
new Hashtable<TextAttribute, Object>();

private final Graphics2D graphics;

/**
/**
* Returns the {@link Graphics2D} for for this visitor.
*
* @return the {@link Graphics2D} object
*/
@TestMethod("testGetGraphics")
public Graphics2D getGraphics() {
return graphics;
}

/**
* Constructs a new {@link IDrawVisitor} using the AWT widget toolkit,
* taking a {@link Graphics2D} object to which the chemical content
* is drawn.
Expand Down
20 changes: 15 additions & 5 deletions src/main/org/openscience/cdk/tools/AtomicProperties.java
Expand Up @@ -27,6 +27,9 @@
import java.util.Hashtable;
import java.util.Map;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;

/**
* Provides atomic property values for descriptor calculations.
*
Expand All @@ -37,6 +40,7 @@
* @cdk.module qsar
* @cdk.githash
*/
@TestClass("org.openscience.cdk.tools.AtomicPropertiesTest")
public class AtomicProperties {

private static AtomicProperties ap=null;
Expand Down Expand Up @@ -72,41 +76,47 @@ private AtomicProperties() throws IOException {
bufferedReader.close();
}



@TestMethod("testGetVdWVolume")
public double getVdWVolume(String symbol) {
return htVdWVolume.get(symbol);
}

@TestMethod("testGetNormalizedVdWVolume")
public double getNormalizedVdWVolume(String symbol) {
return this.getVdWVolume(symbol)/this.getVdWVolume("C");
}

@TestMethod("testGetElectronegativity")
public double getElectronegativity(String symbol) {
return htElectronegativity.get(symbol);
}

@TestMethod("testGetNormalizedElectronegativity")
public double getNormalizedElectronegativity(String symbol) {
return this.getElectronegativity(symbol)/this.getElectronegativity("C");
}
public double getPolarizability(String symbol) {

@TestMethod("testGetPolarizability")
public double getPolarizability(String symbol) {
return htPolarizability.get(symbol);
}

@TestMethod("testGetNormalizedPolarizability")
public double getNormalizedPolarizability(String symbol) {
return this.getPolarizability(symbol)/this.getPolarizability("C");
}

@TestMethod("testGetMass")
public double getMass(String symbol) {
return htMass.get(symbol);
}

@TestMethod("testGetNormalizedMass")
public double getNormalizedMass(String symbol) {
return this.getMass(symbol)/this.getMass("C");
}



@TestMethod("testGetInstance")
public static AtomicProperties getInstance() throws IOException
{
if (ap == null) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/data/mdl/mol_testAliasAtomNaming.mol
@@ -0,0 +1,16 @@
"a carbonyl group"
biocyc 0628111714

4 3 0 0 0 0 0 0 0 0999 V2000
332.4620 333.2690 0.0000 R# 0 0 0 0 0 0 0
-999.0000 333.2690 0.0000 R# 0 0 0 0 0 0 0
-333.2690 333.2690 0.0000 C 0 0 0 0 0 0 0
-333.2690 999.0000 0.0000 O 0 0 0 0 0 0 0
3 1 1 0 0 0 0
3 2 1 0 0 0 0
3 4 2 0 0 0 0
A 2
R1
A 1
R1
M END
21 changes: 20 additions & 1 deletion src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
Expand Up @@ -925,6 +925,25 @@ public void testQueryBondType6() throws Exception {
MDLV2000Reader reader = new MDLV2000Reader(in);
IMolecule molecule = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
reader.read(molecule);
Assert.assertEquals("R", molecule.getAtom(55).getSymbol() );
Assert.assertEquals("R", molecule.getAtom(55).getSymbol());
}

@Test
public void testAliasAtomNaming() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/mol_testAliasAtomNaming.mol");
MDLV2000Reader reader = new MDLV2000Reader(in);
IMolecule molecule = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
reader.read(molecule);

IAtom[] atoms = AtomContainerManipulator.getAtomArray(molecule);

int r1Count = 0;
for (IAtom atom : atoms) {
if (atom instanceof IPseudoAtom) {
Assert.assertEquals("R1", ((IPseudoAtom) atom).getLabel());
r1Count++;
}
}
Assert.assertEquals(2, r1Count);
}
}
4 changes: 3 additions & 1 deletion src/test/org/openscience/cdk/modulesuites/MqsarTests.java
Expand Up @@ -23,6 +23,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.QsarCoverageTest;
import org.openscience.cdk.qsar.DescriptorExceptionTest;
import org.openscience.cdk.tools.AtomicPropertiesTest;

/**
* TestSuite that runs all the sample tests.
Expand All @@ -34,6 +35,7 @@
@RunWith(value=Suite.class)
@SuiteClasses(value={
QsarCoverageTest.class,
DescriptorExceptionTest.class
DescriptorExceptionTest.class,
AtomicPropertiesTest.class
})
public class MqsarTests {}
Expand Up @@ -71,7 +71,29 @@ public void testSetRendererModel() {
Assert.assertNotNull(visitor);
}

@Test
@Test
public void testGetRendererModel() {
Image image = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB
);
Graphics2D g2d = (Graphics2D)image.getGraphics();
AWTDrawVisitor visitor = new AWTDrawVisitor(g2d);
RendererModel model = new RendererModel();
visitor.setRendererModel(model);
Assert.assertEquals(model, visitor.getRendererModel());
}

@Test
public void testGetStrokeMap() {
Image image = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB
);
Graphics2D g2d = (Graphics2D)image.getGraphics();
AWTDrawVisitor visitor = new AWTDrawVisitor(g2d);
Assert.assertNotNull(visitor.getStrokeMap());
}

@Test
public void testVisit() {
Image image = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB
Expand All @@ -84,4 +106,14 @@ public void testVisit() {
// at least we now know it did not crash...
Assert.assertNotNull(visitor);
}

@Test
public void testGetGraphics() {
Image image = new BufferedImage(
100, 100, BufferedImage.TYPE_INT_RGB
);
Graphics2D g2d = (Graphics2D)image.getGraphics();
AWTDrawVisitor visitor = new AWTDrawVisitor(g2d);
Assert.assertEquals(g2d, visitor.getGraphics());
}
}

0 comments on commit 46f2ad0

Please sign in to comment.