From: <gil...@us...> - 2009-03-16 13:26:00
|
Revision: 14495 http://cdk.svn.sourceforge.net/cdk/?rev=14495&view=rev Author: gilleain Date: 2009-03-16 13:25:33 +0000 (Mon, 16 Mar 2009) Log Message: ----------- Reverting the removal of the interface method 'public void select(IChemModel)' as it is needed for selecting outside the hub. Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/AbstractSelection.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IChemObjectSelection.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IncrementalSelection.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/MultiSelection.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/SingleSelection.java Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/AbstractSelection.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/AbstractSelection.java 2009-03-14 19:35:12 UTC (rev 14494) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/AbstractSelection.java 2009-03-16 13:25:33 UTC (rev 14495) @@ -26,6 +26,7 @@ import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemModel; import org.openscience.cdk.interfaces.IChemObject; /** @@ -33,40 +34,45 @@ * @cdk.module render */ public abstract class AbstractSelection implements IChemObjectSelection { - - public static IChemObjectSelection EMPTY_SELECTION = new AbstractSelection(){ - public IAtomContainer getConnectedAtomContainer() { - return null; - } + public static IChemObjectSelection EMPTY_SELECTION = new AbstractSelection() { - public boolean isFilled() { + public IAtomContainer getConnectedAtomContainer() { + return null; + } - return false; - } + public boolean isFilled() { - public boolean contains( IChemObject obj ) { - return false; - } - - public <E extends IChemObject> Collection<E> elements( Class<E> clazz ) { - - return Collections.emptySet(); - } - - }; + return false; + } - protected void addToAtomContainer( IAtomContainer ac, IChemObject item ) { - - if(item instanceof IAtomContainer) { - ac.add( (IAtomContainer) item ); - }else - if(item instanceof IAtom) { - ac.addAtom( (IAtom)item ); - }else - if(item instanceof IBond) { - ac.addBond( (IBond )item); - } - } + public boolean contains(IChemObject obj) { + return false; + } + public <E extends IChemObject> Collection<E> elements(Class<E> clazz) { + + return Collections.emptySet(); + } + + + }; + + @Override + public void select(IChemModel chemModel) { + // TODO Auto-generated method stub + + } + + protected void addToAtomContainer(IAtomContainer ac, IChemObject item) { + + if (item instanceof IAtomContainer) { + ac.add((IAtomContainer) item); + } else if (item instanceof IAtom) { + ac.addAtom((IAtom) item); + } else if (item instanceof IBond) { + ac.addBond((IBond) item); + } + } + } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IChemObjectSelection.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IChemObjectSelection.java 2009-03-14 19:35:12 UTC (rev 14494) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IChemObjectSelection.java 2009-03-16 13:25:33 UTC (rev 14495) @@ -3,14 +3,30 @@ import java.util.Collection; import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IChemModel; import org.openscience.cdk.interfaces.IChemObject; /** + * A selection of some atoms and bonds from an atom container or chem model. + * * @author maclean * @cdk.module render */ public interface IChemObjectSelection { + /** + * Perform a selection by some method. This is used for selecting outside + * the hub, for example: + * + * IChemModel model = createModelBySomeMethod(); + * selection.select(model); + * renderModel.setSelection(selection); + * + * @param chemModel an IChemModel to select from. + */ + public void select(IChemModel chemModel); + + /** * Make an IAtomContainer where all the bonds * only have atoms that are in the selection. @@ -27,6 +43,6 @@ public boolean isFilled(); public boolean contains(IChemObject obj); - + public <E extends IChemObject> Collection<E> elements(Class<E> clazz); } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IncrementalSelection.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IncrementalSelection.java 2009-03-14 19:35:12 UTC (rev 14494) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/IncrementalSelection.java 2009-03-16 13:25:33 UTC (rev 14495) @@ -30,14 +30,8 @@ * @cdk.module render */ public interface IncrementalSelection extends IChemObjectSelection{ - - /** - * Perform a selection by some method. - * - * @param chemModel an IChemModel to select from. - */ - public void select(IChemModel chemModel); + /** * Use this to check if the selection process has finished. * Some implementing classes may just choose to return 'true' Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/MultiSelection.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/MultiSelection.java 2009-03-14 19:35:12 UTC (rev 14494) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/MultiSelection.java 2009-03-16 13:25:33 UTC (rev 14495) @@ -32,56 +32,58 @@ * @cdk.module render */ public class MultiSelection<T extends IChemObject> extends AbstractSelection { - - Collection<T> selection; - - public MultiSelection(Collection<T> selection) { - this.selection = selection; - } - public IAtomContainer getConnectedAtomContainer() { - IAtomContainer atomContainer = null; - if(!selection.isEmpty()) { - for(T value:selection) { - if(atomContainer == null) - atomContainer = value.getBuilder().newAtomContainer(); - addToAtomContainer( atomContainer, value ); - } - } - return atomContainer; - } + Collection<T> selection; - public boolean isFilled() { + public MultiSelection(Collection<T> selection) { + this.selection = selection; + } - return !selection.isEmpty(); - } + public IAtomContainer getConnectedAtomContainer() { + IAtomContainer atomContainer = null; + if (!selection.isEmpty()) { + for (T value : selection) { + if (atomContainer == null) + atomContainer = value.getBuilder().newAtomContainer(); + addToAtomContainer(atomContainer, value); + } + } + return atomContainer; + } - public boolean contains( IChemObject obj ) { - if( obj == null) return false; - for(T selected:selection) { - if(selected == obj) - return true; - } - return false; - } - - /** - * Return elements in selection of type clazz - * @param clazz - * @return A collection containing clazz objects; - */ - @SuppressWarnings("unchecked") - public <E extends IChemObject> Collection<E> elements(Class<E> clazz){ - Set<E> set = new HashSet<E>(); - if(clazz.isAssignableFrom( IChemObject.class )) { - set.addAll( (Collection<E>) selection ); - return set; - } - for(IChemObject obj:selection) { - // Check if obj is assignable to E - if(clazz.isAssignableFrom( obj.getClass() )) - set.add( (E)obj ); - } - return set; - } + public boolean isFilled() { + + return !selection.isEmpty(); + } + + public boolean contains(IChemObject obj) { + if (obj == null) + return false; + for (T selected : selection) { + if (selected == obj) + return true; + } + return false; + } + + /** + * Return elements in selection of type clazz + * + * @param clazz + * @return A collection containing clazz objects; + */ + @SuppressWarnings("unchecked") + public <E extends IChemObject> Collection<E> elements(Class<E> clazz) { + Set<E> set = new HashSet<E>(); + if (clazz.isAssignableFrom(IChemObject.class)) { + set.addAll((Collection<E>) selection); + return set; + } + for (IChemObject obj : selection) { + // Check if obj is assignable to E + if (clazz.isAssignableFrom(obj.getClass())) + set.add((E) obj); + } + return set; + } } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/SingleSelection.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/SingleSelection.java 2009-03-14 19:35:12 UTC (rev 14494) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/selection/SingleSelection.java 2009-03-16 13:25:33 UTC (rev 14495) @@ -28,38 +28,41 @@ import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IChemObject; -/** Represents a single <code>ChemObject</code> +/** + * Represents a single <code>ChemObject</code> + * * @author Arvid * @cdk.module render */ -public class SingleSelection<T extends IChemObject> extends AbstractSelection - implements IChemObjectSelection { +public class SingleSelection<T extends IChemObject> extends AbstractSelection + implements IChemObjectSelection { - T selection; - - public SingleSelection(T item) { - selection = item; - } - - public IAtomContainer getConnectedAtomContainer() { - IAtomContainer ac = selection.getBuilder().newAtomContainer(); - addToAtomContainer( ac, selection ); - return ac; - } + T selection; - public boolean isFilled() { - return selection!=null; - } + public SingleSelection(T item) { + selection = item; + } - public boolean contains( IChemObject obj ) { - return selection == obj; - } - - @SuppressWarnings("unchecked") - public <E extends IChemObject> Collection<E> elements(Class<E> clazz){ - if(selection == null) return Collections.emptySet(); - Set<E> set = new HashSet<E>(); - set.add( (E) selection ); - return set; - } + public IAtomContainer getConnectedAtomContainer() { + IAtomContainer ac = selection.getBuilder().newAtomContainer(); + addToAtomContainer(ac, selection); + return ac; + } + + public boolean isFilled() { + return selection != null; + } + + public boolean contains(IChemObject obj) { + return selection == obj; + } + + @SuppressWarnings("unchecked") + public <E extends IChemObject> Collection<E> elements(Class<E> clazz) { + if (selection == null) + return Collections.emptySet(); + Set<E> set = new HashSet<E>(); + set.add((E) selection); + return set; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |