[graphl-cvs] graphl/src/org/mediavirus/util ParseUtils.java
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2004-10-04 10:21:16
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18139/src/org/mediavirus/util Added Files: ParseUtils.java Log Message: * added width and height properties to the Node interface, to allow layouters to define a bounding box for nodes. * AbsoluteNodeLayouter will also use bounding box information for maps etc. This is currently only used in imageNodePainter * added DirectedEdgeLayouter for laying out hierarchical and directed graphs like trees. this works nice for rdf schemas et al. * Added ShapeNodePainter to draw labels as java2d shapes (currently predefined: circle, square, cross and X). No label yet. * using JavaBeans/property pages for facet configuration. added a dependency to com.l2fprod package, implementing paroperty sheets - i want to get rid of this again in the future, but i don't have time currently to implement such bullshit that should be in the jdk anyhow * Added a StrokeChooser for defining strokes for node and edgepainters * added a ParseUtils class for parsing colors and strokes from literals * greatly extended default configuration for facets * some documentation updates (javadoc runs without warnings now) --- NEW FILE: ParseUtils.java --- /* * Created on 01.10.2004 by Flo Ledermann <led...@im...> */ package org.mediavirus.util; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Stroke; import java.util.StringTokenizer; /** * @author Flo Ledermann <led...@im...> * created: 01.10.2004 21:56:43 */ public class ParseUtils { public static Color parseColor(String colstr) { Color col = null; if (colstr != null) { colstr = colstr.substring(1); int colval = Integer.parseInt(colstr, 16); col = new Color(colval); } return col; } /** * @param str A String that contains a Stroke definition in the following format: * a float value indicating the line width, followed by 0-6 int values, defining * the stroke pattern. @see java.awt.BasicStroke * @return A Stroke that matches the definition in str, or null if the definition * could not be parsed. */ public static Stroke parseStroke(String str) { if (str != null) { float width; StringTokenizer tok = new StringTokenizer(str); try { width = Float.parseFloat(tok.nextToken()); } catch (NumberFormatException ex){ return null; } int i=0; int[] p = new int[6]; while (i<6 && tok.hasMoreTokens()) { try { p[i] = Integer.parseInt(tok.nextToken()); i++; } catch (NumberFormatException e) { } } float[] pattern; if (i == 6) pattern = new float[] { p[0],p[1],p[2],p[3],p[4],p[5] }; else if (i > 3) pattern = new float[] { p[0],p[1],p[2],p[3] }; else if (i > 1) pattern = new float[] { p[0],p[1] }; else if (i == 1) pattern = new float[] { p[0] }; else return new BasicStroke(width); return new BasicStroke(width,BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, pattern, 0.0f); } return null; } } |