Author: mes
Date: 2009-11-20 17:07:53 -0800 (Fri, 20 Nov 2009)
New Revision: 18536
Added:
corelibs/trunk/render.stateful/lib/junit-3.8.1.jar
corelibs/trunk/render.stateful/tests/
corelibs/trunk/render.stateful/tests/cytoscape/
corelibs/trunk/render.stateful/tests/cytoscape/render/
corelibs/trunk/render.stateful/tests/cytoscape/render/stateful/
corelibs/trunk/render.stateful/tests/cytoscape/render/stateful/MeasuredLineCreatorTest.java
Modified:
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLine.java
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLineCreator.java
Log:
added initial set of unit tests for MeasuredLineCreator
Added: corelibs/trunk/render.stateful/lib/junit-3.8.1.jar
===================================================================
(Binary files differ)
Property changes on: corelibs/trunk/render.stateful/lib/junit-3.8.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified:
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLine.java
===================================================================
---
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLine.java
2009-11-21 01:08:43 UTC (rev 18535)
+++
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLine.java
2009-11-21 01:07:53 UTC (rev 18536)
@@ -65,6 +65,6 @@
}
public String toString() {
- return line + " w:" + width + " h:" + height;
+ return "'" + line + "' w:" + width + " h:" + height;
}
}
Modified:
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLineCreator.java
===================================================================
---
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLineCreator.java
2009-11-21 01:08:43 UTC (rev 18535)
+++
corelibs/trunk/render.stateful/src/cytoscape/render/stateful/MeasuredLineCreator.java
2009-11-21 01:07:53 UTC (rev 18536)
@@ -90,7 +90,7 @@
totalHeight = 0;
for ( String line : rawLines ) {
final Rectangle2D bounds = calcBounds(line);
- updateBounds(bounds.getWidth(),bounds.getHeight());
+
updateBounds(bounds.getWidth()*fontScaleFactor,bounds.getHeight()*fontScaleFactor);
}
}
@@ -99,8 +99,8 @@
* to make sure we do it consistently.
*/
private void updateBounds(final double newWidth, final double newHeight
) {
- maxLineWidth = Math.max( maxLineWidth, newWidth *
fontScaleFactor );
- totalHeight += newHeight * fontScaleFactor;
+ maxLineWidth = Math.max( maxLineWidth, newWidth );
+ totalHeight += newHeight;
}
/**
@@ -153,16 +153,19 @@
for (String w : words) {
String word = w + " ";
Rectangle2D bounds = calcBounds(word);
- wordWidth = bounds.getWidth();
- wordHeight = bounds.getHeight();
+ wordWidth = bounds.getWidth()*fontScaleFactor;
+ wordHeight = bounds.getHeight()*fontScaleFactor;
// If the current line width plus the new word
// width is >= than the label width save the
line
if (currentWidth + wordWidth >= labelWidth) {
- measuredLines.add( new
MeasuredLine(currentLine.toString(),
-
currentWidth,wordHeight) );
- updateBounds(currentWidth,wordHeight);
-
currentLine.delete(0,currentLine.length());
+ // only write the string if something
is there
+ if ( currentWidth > 0 ) {
+ measuredLines.add( new
MeasuredLine(currentLine.toString(),
+
currentWidth,wordHeight) );
+
updateBounds(currentWidth,wordHeight);
+
currentLine.delete(0,currentLine.length());
+ }
// if the word itself is >= the label
width,
// make the word itself a new line
@@ -184,10 +187,12 @@
}
}
- // add the last line
- measuredLines.add( new
MeasuredLine(currentLine.toString(),
- currentWidth,
wordHeight) );
- updateBounds(currentWidth,wordHeight);
+ // add the last line if there's anything there
+ if ( currentWidth > 0 ) {
+ measuredLines.add( new
MeasuredLine(currentLine.toString(),
+ currentWidth,
wordHeight) );
+ updateBounds(currentWidth,wordHeight);
+ }
}
}
Added:
corelibs/trunk/render.stateful/tests/cytoscape/render/stateful/MeasuredLineCreatorTest.java
===================================================================
---
corelibs/trunk/render.stateful/tests/cytoscape/render/stateful/MeasuredLineCreatorTest.java
(rev 0)
+++
corelibs/trunk/render.stateful/tests/cytoscape/render/stateful/MeasuredLineCreatorTest.java
2009-11-21 01:07:53 UTC (rev 18536)
@@ -0,0 +1,129 @@
+
+/*
+ Copyright (c) 2009, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library 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
+ any later version.
+
+ This library 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. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. 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 library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.render.stateful;
+
+import junit.framework.*;
+
+import java.awt.Font;
+import java.awt.font.*;
+import java.util.List;
+
+public class MeasuredLineCreatorTest extends TestCase {
+
+ Font serif;
+ Font sansSerif;
+ FontRenderContext frc;
+ MeasuredLineCreator mlc;
+
+
+ public void setUp() {
+ serif = new Font("Serif",Font.PLAIN,10);
+ sansSerif = new Font("SansSerif",Font.BOLD,12);
+ frc = new FontRenderContext(null,true,true);
+ }
+
+ public void testOneLine() {
+ mlc = new MeasuredLineCreator("homer",serif,frc,2.0,true,100);
+ printLines("one line",mlc);
+ assertTrue(mlc.getMeasuredLines().size() == 1);
+ }
+
+ public void testOneNewLine() {
+ mlc = new
MeasuredLineCreator("homer\nmarge",serif,frc,2.0,true,100);
+ printLines("one newline",mlc);
+ assertTrue(mlc.getMeasuredLines().size() == 2);
+ }
+
+ public void testLongLine() {
+ mlc = new MeasuredLineCreator("homer bart lisa
marge",serif,frc,2.0,true,10);
+ printLines("long line",mlc);
+ assertTrue(mlc.getMeasuredLines().size() > 1);
+ }
+
+ public void testLongLineAndNewLines() {
+ mlc = new MeasuredLineCreator("homer bart lisa
marge\nmaggie\nsmithers",serif,frc,2.0,false,10);
+ printLines("long line and newlines",mlc);
+ assertTrue(mlc.getMeasuredLines().size() > 3);
+ }
+
+ public void testLongLineAndSpaces() {
+ mlc = new MeasuredLineCreator("homer bart lisa marge
smithers",serif,frc,2.0,true,10);
+ printLines("long line and spaces",mlc);
+ assertTrue(mlc.getMeasuredLines().size() > 2);
+ }
+
+ public void testLongWord() {
+ mlc = new
MeasuredLineCreator("homerbartlisamargesmithers",serif,frc,2.0,false,10);
+ printLines("long word",mlc);
+ assertTrue(mlc.getMeasuredLines().size() == 1);
+ }
+
+ public void testWidthUpdate() {
+ mlc = new
MeasuredLineCreator("homer\nmarge",serif,frc,2.0,true,100);
+ printLines("width update",mlc);
+ double w = mlc.getMaxLineWidth();
+ for ( MeasuredLine ml : mlc.getMeasuredLines() )
+ if ( ml.getWidth() == w )
+ return;
+
+ fail("max line width should have updated");
+ }
+
+ public void testFirstLineNotEmpty() {
+ mlc = new MeasuredLineCreator("homerbart lisa
margesmithers",serif,frc,2.0,false,10);
+ printLines("first line not empty",mlc);
+ List<MeasuredLine> ml = mlc.getMeasuredLines();
+ assertFalse( ml.get(0).getLine().equals("") );
+ }
+
+ public void testLastLineNotEmpty() {
+ mlc = new MeasuredLineCreator("homerbart lisa
margesmithers",serif,frc,2.0,false,10);
+ printLines("last line not empty",mlc);
+ List<MeasuredLine> ml = mlc.getMeasuredLines();
+ assertFalse( ml.get(ml.size()-1).getLine().equals("") );
+ }
+
+
+ private void printLines(String title, MeasuredLineCreator mlx) {
+ System.out.println("------------------------- " + title);
+ System.out.println("max line width: " + mlx.getMaxLineWidth());
+ System.out.println("total height : " + mlx.getTotalHeight());
+ for ( MeasuredLine ml : mlc.getMeasuredLines() )
+ System.out.println(ml.toString());
+ System.out.println();
+ }
+}
--
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=.