Author: jm
Date: 2012-07-11 12:45:47 -0700 (Wed, 11 Jul 2012)
New Revision: 29840
Modified:
core3/api/trunk/presentation-api/src/main/java/org/cytoscape/view/presentation/property/FontVisualProperty.java
Log:
Fixes #1253: Added support for parsing Cy2 fonts
Modified:
core3/api/trunk/presentation-api/src/main/java/org/cytoscape/view/presentation/property/FontVisualProperty.java
===================================================================
---
core3/api/trunk/presentation-api/src/main/java/org/cytoscape/view/presentation/property/FontVisualProperty.java
2012-07-11 19:07:58 UTC (rev 29839)
+++
core3/api/trunk/presentation-api/src/main/java/org/cytoscape/view/presentation/property/FontVisualProperty.java
2012-07-11 19:45:47 UTC (rev 29840)
@@ -38,6 +38,8 @@
import java.awt.GraphicsEnvironment;
import java.util.HashSet;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.view.model.AbstractVisualProperty;
@@ -60,6 +62,8 @@
private static final Font DEFAULT_FONT = new Font("SansSerif",
Font.PLAIN, DEF_FONT_SIZE);
+ private static final Pattern CY2_FONT_PATTERN =
Pattern.compile("(.+)-(\\d+)-(\\d+)");
+
static {
final Set<Font> fontSet = new HashSet<Font>();
final Font[] allFonts =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
@@ -100,23 +104,35 @@
@Override
public Font parseSerializableString(final String text) {
if (text != null && text.trim().length() != 0) {
- // e.g. "Monospaced,plain,12"
- String name =
text.replaceAll("(\\.[bB]old)?,[a-zA-Z]+,\\d+(\\.\\d+)?", "");
+ Matcher matcher = CY2_FONT_PATTERN.matcher(text);
+ if (matcher.matches())
+ return parseCy2Font(matcher.group(1),
matcher.group(2), matcher.group(3));
+ else
+ return parseFont(text);
+ } else
+ return DEFAULT_FONT;
+ }
+
+ private Font parseFont(String text) {
+ // e.g. "Monospaced,plain,12"
+ String name =
text.replaceAll("(\\.[bB]old)?,[a-zA-Z]+,\\d+(\\.\\d+)?", "");
- boolean bold =
text.matches("(?i).*\\.bold,[a-zA-Z]+,.*");
- int style = bold ? Font.BOLD : Font.PLAIN;
- int size = DEF_FONT_SIZE;
+ boolean bold = text.matches("(?i).*\\.bold,[a-zA-Z]+,.*");
+ int style = bold ? Font.BOLD : Font.PLAIN;
+ int size = DEF_FONT_SIZE;
- String sSize = text.replaceAll(".+,[^,]+,", "");
+ String sSize = text.replaceAll(".+,[^,]+,", "");
- try {
- size = Integer.parseInt(sSize);
- } catch (NumberFormatException nfe) {
- logger.warn("Cannot parse font size in '" +
text + "'", nfe);
- }
+ try {
+ size = Integer.parseInt(sSize);
+ } catch (NumberFormatException nfe) {
+ logger.warn("Cannot parse font size in '" + text + "'",
nfe);
+ }
- return new Font(name, style, size);
- } else
- return DEFAULT_FONT;
+ return new Font(name, style, size);
}
+
+ private Font parseCy2Font(String name, String style, String size) {
+ return new Font(name, Integer.parseInt(style),
Integer.parseInt(size));
+ }
}
--
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.