Author: mes Date: 2009-11-07 11:32:28 -0800 (Sat, 07 Nov 2009) New Revision: 18394
Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DashDotStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DotStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DoubleStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/EqualDashStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/LongDashStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ShapeStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/SolidStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/WidthStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ZigzagStroke.java Removed: cytoscape/branches/new_edge_types/src/cytoscape/visual/DoubleStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/ShapeStroke.java cytoscape/branches/new_edge_types/src/cytoscape/visual/ZigzagStroke.java Modified: cytoscape/branches/new_edge_types/src/cytoscape/visual/LineStyle.java cytoscape/branches/new_edge_types/src/cytoscape/visual/LineType.java cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/EdgeLineWidthProp.java cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/NodeLineWidthProp.java Log: more edge type changes, but edge width still doesn't work Deleted: cytoscape/branches/new_edge_types/src/cytoscape/visual/DoubleStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/DoubleStroke.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/DoubleStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -1,34 +0,0 @@ - -package cytoscape.visual; - -import java.awt.BasicStroke; -import java.awt.Stroke; -import java.awt.Shape; - -/* - * Copyright (c) 2000 David Flanagan. All rights reserved. - * This code is from the book Java Examples in a Nutshell, 2nd Edition. - * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. - * You may study, use, and modify it for any non-commercial purpose. - * You may distribute it non-commercially as long as you retain this notice. - * For a commercial use license, or to purchase the book (recommended), - * visit http://www.davidflanagan.com/javaexamples2. - */ -class DoubleStroke implements Stroke { - BasicStroke stroke1, stroke2; // the two strokes to use - - public DoubleStroke(float width1, float width2) { - stroke1 = new BasicStroke(width1); // Constructor arguments specify - stroke2 = new BasicStroke(width2); // the line widths for the strokes - } - - public Shape createStrokedShape(Shape s) { - // Use the first stroke to create an outline of the shape - Shape outline = stroke1.createStrokedShape(s); - // Use the second stroke to create an outline of that outline. - // It is this outline of the outline that will be filled in - return stroke2.createStrokedShape(outline); - } -} - - Modified: cytoscape/branches/new_edge_types/src/cytoscape/visual/LineStyle.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/LineStyle.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/LineStyle.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -46,31 +46,29 @@ import java.util.regex.Pattern; import java.util.regex.Matcher; import cytoscape.visual.ui.icon.*; +import cytoscape.visual.strokes.*; /** - * * Define line stroke. * - * TODO: need to modify rendering engine to fully support dash lines. - * * @author kono - * */ public enum LineStyle { - SOLID("line"), - LONG_DASH( "dash"), - DOUBLE("double"), - SHAPE("shape"), - ZIGZAG("zigzag"), + SOLID("line", new SolidStroke(1.0f,"line")), + LONG_DASH( "dash", new LongDashStroke(1.0f,"dash")), + EQUAL( "equal", new EqualDashStroke(1.0f,"equal")), + UNEVEN( "uneven", new DashDotStroke(1.0f,"uneven")), + DOUBLE("double", new DoubleStroke(1.0f,"double")), + DOT("dot", new DotStroke(1.0f,"dot")), + ZIGZAG("zigzag", new ZigzagStroke(1.0f,"zigzag")), ; - // DASH("4.0f,4.0f"), - // DASH_DOT("12.0f,3.0f,3.0f,3.0f"), - private String regex; + private WidthStroke stroke; - private LineStyle(String regex) { + private LineStyle(String regex, WidthStroke stroke) { this.regex = regex; + this.stroke = stroke; } private String getRegex() { @@ -116,42 +114,26 @@ } /** - * A method that attempts to figure out if a stroke is dashed - * or not. If the Stroke object is not a BasicStroke, it will - * return SOLID by default. - * @return the LineStyle guessed based on the BasicStroke dash array. + * Will attempt to find the LineStyle based on the type of stroke. + * If it doesn't match a known stroke, it will return SOLID. + * @return the LineStyle guessed from the stroke. */ - public static LineStyle extractLineStyle(Stroke stroke) { - if ( stroke instanceof BasicStroke ) { - final float[] dash = ((BasicStroke)stroke).getDashArray(); - if ( dash == null ) - return SOLID; - else - return LONG_DASH; + public static LineStyle extractLineStyle(Stroke s) { + if ( s instanceof WidthStroke ) { + System.out.println("extracted line style " + ((WidthStroke)s).getName()); + return LineStyle.parse( ((WidthStroke)s).getName() ); } + System.out.println("extracted line style line"); return SOLID; } public Stroke getStroke(float width) { - // OH God! - if ( regex.equals("dash") ) - return new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, - new float[]{10.0f,4.0f}, 0.0f); - else if ( regex.equals("double") ) - return new DoubleStroke(width,width); - else if ( regex.equals("shape") ) - return new ShapeStroke( new Shape[] { new Ellipse2D.Float(0, 0, 4, 4) }, 15.0f ); - ///return new ShapStroke( new Shape[] { new Star( 5, 0, 0, 0, 0.5f, 6.0f), new Ellipse2D.Float(0, 0, 4, 4) }, 15.0f ); - else if ( regex.equals("zigzag") ) - return new ZigzagStroke(new BasicStroke(2.0f),5.0f,10.0f); - - else - return new BasicStroke(width); + System.out.println("getting stroke for " + regex); + return stroke.newInstanceForWidth( width ); } public static Map<Object,Icon> getIconSet() { - System.out.println("in getIconSet"); Map<Object,Icon> icons = new HashMap<Object,Icon>(); for (LineStyle def : values()) { @@ -159,11 +141,9 @@ VisualPropertyIcon.DEFAULT_ICON_SIZE * 4, VisualPropertyIcon.DEFAULT_ICON_SIZE, def.name()); - System.out.println("created icon " + def); icons.put(def, icon); } - System.out.println("about to return icons"); return icons; } } Modified: cytoscape/branches/new_edge_types/src/cytoscape/visual/LineType.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/LineType.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/LineType.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -42,7 +42,6 @@ //---------------------------------------------------------------------------- package cytoscape.visual; -import java.awt.BasicStroke; import java.awt.Stroke; import java.awt.Shape; Deleted: cytoscape/branches/new_edge_types/src/cytoscape/visual/ShapeStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/ShapeStroke.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/ShapeStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -1,109 +0,0 @@ -/* -Copyright 2006 Jerry Huxtable - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cytoscape.visual; - -import java.awt.*; -import java.awt.geom.*; - -public class ShapeStroke implements Stroke { - private Shape shapes[]; - private float advance; - private boolean stretchToFit = false; - private boolean repeat = true; - private AffineTransform t = new AffineTransform(); - private static final float FLATNESS = 1; - - public ShapeStroke( Shape shapes, float advance ) { - this( new Shape[] { shapes }, advance ); - } - - public ShapeStroke( Shape shapes[], float advance ) { - this.advance = advance; - this.shapes = new Shape[shapes.length]; - - for ( int i = 0; i < this.shapes.length; i++ ) { - Rectangle2D bounds = shapes[i].getBounds2D(); - t.setToTranslation( -bounds.getCenterX(), -bounds.getCenterY() ); - this.shapes[i] = t.createTransformedShape( shapes[i] ); - } - } - - public Shape createStrokedShape( Shape shape ) { - GeneralPath result = new GeneralPath(); - PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS ); - float points[] = new float[6]; - float moveX = 0, moveY = 0; - float lastX = 0, lastY = 0; - float thisX = 0, thisY = 0; - int type = 0; - boolean first = false; - float next = 0; - int currentShape = 0; - int length = shapes.length; - - float factor = 1; - - while ( currentShape < length && !it.isDone() ) { - type = it.currentSegment( points ); - switch( type ){ - case PathIterator.SEG_MOVETO: - moveX = lastX = points[0]; - moveY = lastY = points[1]; - result.moveTo( moveX, moveY ); - first = true; - next = 0; - break; - - case PathIterator.SEG_CLOSE: - points[0] = moveX; - points[1] = moveY; - // Fall into.... - - case PathIterator.SEG_LINETO: - thisX = points[0]; - thisY = points[1]; - float dx = thisX-lastX; - float dy = thisY-lastY; - float distance = (float)Math.sqrt( dx*dx + dy*dy ); - if ( distance >= next ) { - float r = 1.0f/distance; - float angle = (float)Math.atan2( dy, dx ); - while ( currentShape < length && distance >= next ) { - float x = lastX + next*dx*r; - float y = lastY + next*dy*r; - t.setToTranslation( x, y ); - t.rotate( angle ); - result.append( t.createTransformedShape( shapes[currentShape] ), false ); - next += advance; - currentShape++; - if ( repeat ) - currentShape %= length; - } - } - next -= distance; - first = false; - lastX = thisX; - lastY = thisY; - break; - } - it.next(); - } - - return result; - } - -} Deleted: cytoscape/branches/new_edge_types/src/cytoscape/visual/ZigzagStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/ZigzagStroke.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/ZigzagStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -1,100 +0,0 @@ -/* -Copyright 2006 Jerry Huxtable - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cytoscape.visual; - -import java.awt.*; -import java.awt.geom.*; - -public class ZigzagStroke implements Stroke { - private float amplitude = 10.0f; - private float wavelength = 10.0f; - private Stroke stroke; - private static final float FLATNESS = 1; - - public ZigzagStroke( Stroke stroke, float amplitude, float wavelength ) { - this.stroke = stroke; - this.amplitude = amplitude; - this.wavelength = wavelength; - } - - public Shape createStrokedShape( Shape shape ) { - GeneralPath result = new GeneralPath(); - PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS ); - float points[] = new float[6]; - float moveX = 0, moveY = 0; - float lastX = 0, lastY = 0; - float thisX = 0, thisY = 0; - int type = 0; - boolean first = false; - float next = 0; - int phase = 0; - - float factor = 1; - - while ( !it.isDone() ) { - type = it.currentSegment( points ); - switch( type ){ - case PathIterator.SEG_MOVETO: - moveX = lastX = points[0]; - moveY = lastY = points[1]; - result.moveTo( moveX, moveY ); - first = true; - next = wavelength/2; - break; - - case PathIterator.SEG_CLOSE: - points[0] = moveX; - points[1] = moveY; - // Fall into.... - - case PathIterator.SEG_LINETO: - thisX = points[0]; - thisY = points[1]; - float dx = thisX-lastX; - float dy = thisY-lastY; - float distance = (float)Math.sqrt( dx*dx + dy*dy ); - if ( distance >= next ) { - float r = 1.0f/distance; - float angle = (float)Math.atan2( dy, dx ); - while ( distance >= next ) { - float x = lastX + next*dx*r; - float y = lastY + next*dy*r; - float tx = amplitude*dy*r; - float ty = amplitude*dx*r; - if ( (phase & 1) == 0 ) - result.lineTo( x+amplitude*dy*r, y-amplitude*dx*r ); - else - result.lineTo( x-amplitude*dy*r, y+amplitude*dx*r ); - next += wavelength; - phase++; - } - } - next -= distance; - first = false; - lastX = thisX; - lastY = thisY; - if ( type == PathIterator.SEG_CLOSE ) - result.closePath(); - break; - } - it.next(); - } - - return stroke.createStrokedShape( result ); - } - -} Modified: cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/EdgeLineWidthProp.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/EdgeLineWidthProp.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/EdgeLineWidthProp.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -93,15 +93,13 @@ if ((o == null) || (ev == null)) return; - if (ev.getStrokeWidth() != ((Number)o).floatValue()) { - final BasicStroke oldValue = (BasicStroke) ev.getStroke(); - final Stroke newLine = new BasicStroke(((Number)o).floatValue(), oldValue.getEndCap(), oldValue.getLineJoin(), - oldValue.getMiterLimit(), oldValue.getDashArray(), oldValue.getDashPhase() ); - - //CyLogger.getLogger().info("*** o = " + o + ", new w = " + ev.getStrokeWidth()); - - ev.setStroke(newLine); - //CyLogger.getLogger().info("Changed w = " + ev.getStrokeWidth()); + float width = ((Number)o).floatValue(); + if (ev.getStrokeWidth() != width) { + final Stroke oldStroke = ev.getStroke(); + System.out.println("ELW oldStroke " + oldStroke.toString() + " for " + ev.toString()); + final Stroke newStroke = LineStyle.extractLineStyle(oldStroke).getStroke(width); + System.out.println("ELW setting stroke " + newStroke.toString() + " for " + ev.toString()); + ev.setStroke(newStroke); } } Modified: cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/NodeLineWidthProp.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/NodeLineWidthProp.java 2009-11-07 02:31:58 UTC (rev 18393) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/properties/NodeLineWidthProp.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -39,6 +39,7 @@ import cytoscape.visual.parsers.FloatParser; import cytoscape.visual.ui.icon.NodeIcon; +import cytoscape.visual.LineStyle; import giny.view.NodeView; @@ -100,13 +101,11 @@ if ((o == null) || (nv == null)) return; - if (nv.getBorderWidth() != ((Number) o).floatValue()) { - final BasicStroke oldValue = (BasicStroke) nv.getBorder(); - final Stroke newLine = new BasicStroke(((Number) o).floatValue(), oldValue.getEndCap(), - oldValue.getLineJoin(), - oldValue.getMiterLimit(), - oldValue.getDashArray(), oldValue.getDashPhase()); - nv.setBorder(newLine); + float width =((Number) o).floatValue(); + if (nv.getBorderWidth() != width ) { + final Stroke oldStroke = nv.getBorder(); + final Stroke newStroke = LineStyle.extractLineStyle(oldStroke).getStroke(width); + nv.setBorder(newStroke); } } Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DashDotStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DashDotStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DashDotStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,34 @@ + + + +package cytoscape.visual.strokes; + +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.Shape; + +public class DashDotStroke extends BasicStroke implements WidthStroke { + + String name; + float width; + + public DashDotStroke(float width, String name) { + super(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, + 10.0f, new float[]{12.0f,3.0f,3.0f,3.0f}, 0.0f); + + this.name = name; + this.width = width; + } + + public WidthStroke newInstanceForWidth(float w) { + return new DashDotStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DotStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DotStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DotStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,30 @@ + +package cytoscape.visual.strokes; + +import java.awt.Shape; +import java.awt.geom.Ellipse2D; + +public class DotStroke extends ShapeStroke implements WidthStroke { + + String name; + float width; + + // TODO width isn't doing anything here! + public DotStroke(float width, String name) { + super( new Shape[] { new Ellipse2D.Float(0, 0, 4, 4) }, 15.0f ); + this.name = name; + this.width = width; + } + + public WidthStroke newInstanceForWidth(float w) { + return new DotStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DoubleStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DoubleStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/DoubleStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,49 @@ + +package cytoscape.visual.strokes; + +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.Shape; + +/* + * Copyright (c) 2000 David Flanagan. All rights reserved. + * This code is from the book Java Examples in a Nutshell, 2nd Edition. + * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. + * You may study, use, and modify it for any non-commercial purpose. + * You may distribute it non-commercially as long as you retain this notice. + * For a commercial use license, or to purchase the book (recommended), + * visit http://www.davidflanagan.com/javaexamples2. + */ +public class DoubleStroke implements WidthStroke { + BasicStroke stroke1, stroke2; // the two strokes to use + + String name; + float width; + + public DoubleStroke(float width, String name) { + this.name = name; + this.width = width; + stroke1 = new BasicStroke(width); + stroke2 = new BasicStroke(width * 2); + } + + public Shape createStrokedShape(Shape s) { + // Use the first stroke to create an outline of the shape + Shape outline = stroke1.createStrokedShape(s); + // Use the second stroke to create an outline of that outline. + // It is this outline of the outline that will be filled in + return stroke2.createStrokedShape(outline); + } + + public WidthStroke newInstanceForWidth(float w) { + return new DoubleStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/EqualDashStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/EqualDashStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/EqualDashStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,33 @@ + + +package cytoscape.visual.strokes; + +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.Shape; + +public class EqualDashStroke extends BasicStroke implements WidthStroke { + + String name; + float width; + + public EqualDashStroke(float width, String name) { + super(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, + 10.0f, new float[]{4.0f,4.0f}, 0.0f); + + this.name = name; + this.width = width; + } + + public WidthStroke newInstanceForWidth(float w) { + return new EqualDashStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/LongDashStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/LongDashStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/LongDashStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,32 @@ + + +package cytoscape.visual.strokes; + +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.Shape; + +public class LongDashStroke extends BasicStroke implements WidthStroke { + + String name; + float width; + + public LongDashStroke(float width, String name) { + super(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, + 10.0f, new float[]{10.0f,4.0f}, 0.0f); + this.name = name; + this.width = width; + } + + public WidthStroke newInstanceForWidth(float w) { + return new LongDashStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ShapeStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ShapeStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ShapeStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,109 @@ +/* +Copyright 2006 Jerry Huxtable + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cytoscape.visual.strokes; + +import java.awt.*; +import java.awt.geom.*; + +public class ShapeStroke implements Stroke { + private Shape shapes[]; + private float advance; + private boolean stretchToFit = false; + private boolean repeat = true; + private AffineTransform t = new AffineTransform(); + private static final float FLATNESS = 1; + + public ShapeStroke( Shape shapes, float advance ) { + this( new Shape[] { shapes }, advance ); + } + + public ShapeStroke( Shape shapes[], float advance ) { + this.advance = advance; + this.shapes = new Shape[shapes.length]; + + for ( int i = 0; i < this.shapes.length; i++ ) { + Rectangle2D bounds = shapes[i].getBounds2D(); + t.setToTranslation( -bounds.getCenterX(), -bounds.getCenterY() ); + this.shapes[i] = t.createTransformedShape( shapes[i] ); + } + } + + public Shape createStrokedShape( Shape shape ) { + GeneralPath result = new GeneralPath(); + PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS ); + float points[] = new float[6]; + float moveX = 0, moveY = 0; + float lastX = 0, lastY = 0; + float thisX = 0, thisY = 0; + int type = 0; + boolean first = false; + float next = 0; + int currentShape = 0; + int length = shapes.length; + + float factor = 1; + + while ( currentShape < length && !it.isDone() ) { + type = it.currentSegment( points ); + switch( type ){ + case PathIterator.SEG_MOVETO: + moveX = lastX = points[0]; + moveY = lastY = points[1]; + result.moveTo( moveX, moveY ); + first = true; + next = 0; + break; + + case PathIterator.SEG_CLOSE: + points[0] = moveX; + points[1] = moveY; + // Fall into.... + + case PathIterator.SEG_LINETO: + thisX = points[0]; + thisY = points[1]; + float dx = thisX-lastX; + float dy = thisY-lastY; + float distance = (float)Math.sqrt( dx*dx + dy*dy ); + if ( distance >= next ) { + float r = 1.0f/distance; + float angle = (float)Math.atan2( dy, dx ); + while ( currentShape < length && distance >= next ) { + float x = lastX + next*dx*r; + float y = lastY + next*dy*r; + t.setToTranslation( x, y ); + t.rotate( angle ); + result.append( t.createTransformedShape( shapes[currentShape] ), false ); + next += advance; + currentShape++; + if ( repeat ) + currentShape %= length; + } + } + next -= distance; + first = false; + lastX = thisX; + lastY = thisY; + break; + } + it.next(); + } + + return result; + } + +} Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/SolidStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/SolidStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/SolidStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,30 @@ + +package cytoscape.visual.strokes; + +import java.awt.BasicStroke; +import java.awt.Stroke; +import java.awt.Shape; + +public class SolidStroke extends BasicStroke implements WidthStroke { + + String name; + float width; + + public SolidStroke(float width, String name) { + super(width); + this.name = name; + this.width = width; + } + + public WidthStroke newInstanceForWidth(float w) { + return new SolidStroke(w,name); + } + + public String getName() { + return name; + } + + public String toString() { return name + " " + Float.toString(width); } +} + + Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/WidthStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/WidthStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/WidthStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,9 @@ + +package cytoscape.visual.strokes; + +import java.awt.Stroke; + +public interface WidthStroke extends Stroke { + WidthStroke newInstanceForWidth(float width); + String getName(); +} Added: cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ZigzagStroke.java =================================================================== --- cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ZigzagStroke.java (rev 0) +++ cytoscape/branches/new_edge_types/src/cytoscape/visual/strokes/ZigzagStroke.java 2009-11-07 19:32:28 UTC (rev 18394) @@ -0,0 +1,116 @@ +/* +Copyright 2006 Jerry Huxtable + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cytoscape.visual.strokes; + +import java.awt.*; +import java.awt.geom.*; + +public class ZigzagStroke implements WidthStroke { + private float amplitude = 10.0f; + private float wavelength = 10.0f; + private Stroke stroke; + private static final float FLATNESS = 1; + private String name; + private float width; + + // TODO we can do fancier stuff if we pass in Stroke, amplitude and wavelength + // as params + public ZigzagStroke( float width, String name ) { + this.name = name; + this.width = width; + this.stroke = new BasicStroke(width); + } + + public Shape createStrokedShape( Shape shape ) { + GeneralPath result = new GeneralPath(); + PathIterator it = new FlatteningPathIterator( shape.getPathIterator( null ), FLATNESS ); + float points[] = new float[6]; + float moveX = 0, moveY = 0; + float lastX = 0, lastY = 0; + float thisX = 0, thisY = 0; + int type = 0; + boolean first = false; + float next = 0; + int phase = 0; + + float factor = 1; + + while ( !it.isDone() ) { + type = it.currentSegment( points ); + switch( type ){ + case PathIterator.SEG_MOVETO: + moveX = lastX = points[0]; + moveY = lastY = points[1]; + result.moveTo( moveX, moveY ); + first = true; + next = wavelength/2; + break; + + case PathIterator.SEG_CLOSE: + points[0] = moveX; + points[1] = moveY; + // Fall into.... + + case PathIterator.SEG_LINETO: + thisX = points[0]; + thisY = points[1]; + float dx = thisX-lastX; + float dy = thisY-lastY; + float distance = (float)Math.sqrt( dx*dx + dy*dy ); + if ( distance >= next ) { + float r = 1.0f/distance; + float angle = (float)Math.atan2( dy, dx ); + while ( distance >= next ) { + float x = lastX + next*dx*r; + float y = lastY + next*dy*r; + float tx = amplitude*dy*r; + float ty = amplitude*dx*r; + if ( (phase & 1) == 0 ) + result.lineTo( x+amplitude*dy*r, y-amplitude*dx*r ); + else + result.lineTo( x-amplitude*dy*r, y+amplitude*dx*r ); + next += wavelength; + phase++; + } + } + next -= distance; + first = false; + lastX = thisX; + lastY = thisY; + if ( type == PathIterator.SEG_CLOSE ) + result.closePath(); + break; + } + it.next(); + } + + return stroke.createStrokedShape( result ); + } + + public String getName() { + return getName(); + } + + public WidthStroke newInstanceForWidth(float w) { + return new ZigzagStroke(w,name); + } + + public String toString() { + return name + " " + Float.toString(width); + } + +} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cytoscape-cvs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cytoscape-cvs?hl=en -~----------~----~----~----~------~----~------~--~---
