From: <gil...@us...> - 2008-12-01 11:44:27
|
Revision: 13403 http://cdk.svn.sourceforge.net/cdk/?rev=13403&view=rev Author: gilleain Date: 2008-12-01 11:39:28 +0000 (Mon, 01 Dec 2008) Log Message: ----------- Added support for setting selection shapes as rectangles or circles. Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/Renderer2DModel.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/RenderingParameters.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/SelectionGenerator.java Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/Renderer2DModel.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/Renderer2DModel.java 2008-12-01 11:02:23 UTC (rev 13402) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/Renderer2DModel.java 2008-12-01 11:39:28 UTC (rev 13403) @@ -26,8 +26,6 @@ import java.awt.Color; import java.awt.Font; -import java.awt.Point; -import java.awt.Polygon; import java.io.Serializable; import java.util.ArrayList; import java.util.EventObject; @@ -86,12 +84,7 @@ private IAtomContainer clipboardContent = null; - private Polygon selectRect = null; - - private List<Point> lassoPoints = new ArrayList<Point>(); - private ShapeSelection shapeSelection = new LassoSelection(); -// private ShapeSelection shapeSelection = new RectangleSelection(); public Renderer2DModel() { this.parameters = new RenderingParameters(); @@ -108,6 +101,14 @@ public ShapeSelection getShapeSelection() { return this.shapeSelection; } + + public RenderingParameters.SelectionShape getSelectionShape() { + return this.parameters.getSelectionShape(); + } + + public void setSelectionShape(RenderingParameters.SelectionShape selectionShape) { + this.parameters.setSelectionShape(selectionShape); + } /** * @return null if no custom font set @@ -509,10 +510,6 @@ // "Background color atom according to hashing (substructure)"); atomColor = hashColor; } -// if (atom == this.getHighlightedAtom()) { -// // logger.debug("Background color atom according to highlighting"); -// atomColor = this.getHoverOverColor(); -// } // logger.debug("Color: " + atomColor.toString()); return atomColor; } @@ -548,25 +545,6 @@ } /** - * Returns selected rectangular - * - * @return the selection - */ - public Polygon getSelectRect() { - return this.selectRect; - } - - /** - * Sets a selected region - * - * @param selectRect - */ - public void setSelectRect(Polygon selectRect) { - this.selectRect = selectRect; - fireChange(); - } - - /** * Returns the atoms and bonds on the Renderer2D clipboard. If the clipboard * is empty it returns null. Primarily used for copy/paste. * @@ -618,26 +596,6 @@ } /** - * Returns a set of points constituating a selected region - * - * @return a vector with points - */ - public List<Point> getLassoPoints() { - return this.lassoPoints; - } - - /** - * Adds a point to the list of lasso points - * - * @param point - * Point to add to list - */ - public void addLassoPoint(Point point) { - this.lassoPoints.add(point); - fireChange(); - } - - /** * Adds a change listener to the list of listeners * * @param listener Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/RenderingParameters.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/RenderingParameters.java 2008-12-01 11:02:23 UTC (rev 13402) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/RenderingParameters.java 2008-12-01 11:39:28 UTC (rev 13403) @@ -46,6 +46,13 @@ private double margin = 0.05; private Color selectedPartColor = Color.lightGray; + + public enum SelectionShape { OVAL, SQUARE }; + + /** + * The shape to display over selected atoms + */ + private SelectionShape selectionShape = SelectionShape.SQUARE; /** * Determines whether rings should be drawn with a circle if they are @@ -80,6 +87,14 @@ private boolean useAntiAliasing = true; private boolean willDrawNumbers = false; + + public SelectionShape getSelectionShape() { + return this.selectionShape; + } + + public void setSelectionShape(SelectionShape selectionShape) { + this.selectionShape = selectionShape; + } public Font getCustomFont() { return customFont; Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/SelectionGenerator.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/SelectionGenerator.java 2008-12-01 11:02:23 UTC (rev 13402) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/renderer/generators/SelectionGenerator.java 2008-12-01 11:39:28 UTC (rev 13403) @@ -28,36 +28,54 @@ import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.renderer.Renderer2DModel; import org.openscience.cdk.renderer.ShapeSelection; +import org.openscience.cdk.renderer.RenderingParameters.SelectionShape; import org.openscience.cdk.renderer.elements.ElementGroup; import org.openscience.cdk.renderer.elements.IRenderingElement; +import org.openscience.cdk.renderer.elements.OvalElement; import org.openscience.cdk.renderer.elements.RectangleElement; /** * @cdk.module render */ public class SelectionGenerator implements IGenerator { - + private Renderer2DModel rendererModel; private Color selectionColor; private boolean autoUpdateSelection = true; + private SelectionShape shape; public SelectionGenerator(Renderer2DModel rendererModel) { this.rendererModel = rendererModel; this.selectionColor = rendererModel.getSelectedPartColor(); + this.shape = rendererModel.getSelectionShape(); } public IRenderingElement generate(IAtomContainer ac) { ElementGroup selectionElements = new ElementGroup(); ShapeSelection selection = this.rendererModel.getShapeSelection(); if (this.autoUpdateSelection || selection.isFilled()) { - double r = 0.1; + double r; + switch(this.shape) { + case SQUARE: r = 0.1; break; + + case OVAL: default: r = 1; break; + } double d = 2 * r; for (IAtom atom : selection.atoms) { Point2d p = atom.getPoint2d(); - - selectionElements.add( - new RectangleElement( - p.x - r, p.y - r, d, d, true, selectionColor)); + + switch (this.shape) { + case SQUARE: + selectionElements.add( + new RectangleElement( + p.x - r, p.y - r, d, d, true, selectionColor)); + break; + case OVAL: + default: + selectionElements.add( + new OvalElement( + p.x, p.y, d, false, selectionColor)); + } } } if (!selection.isFinished()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |