Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.graphstream.ui.graphicGraph.stylesheet.parser.StyleSheetParser.jj Maven / Gradle / Ivy
options { JDK_VERSION = "1.5"; STATIC = false; }
PARSER_BEGIN(StyleSheetParser)
/*
* Copyright 2006 - 2012
* Stefan Balev
* Julien Baudry
* Antoine Dutot
* Yoann Pigné
* Guilhelm Savin
*
* This file is part of GraphStream .
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program 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. 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 program. If not, see .
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.ui.graphicGraph.stylesheet.parser;
import java.awt.Color;
import java.io.InputStream;
import java.io.IOException;
import java.io.Reader;
import org.graphstream.ui.graphicGraph.stylesheet.*;
import org.graphstream.util.parser.ParseException;
import org.graphstream.util.parser.SimpleCharStream;
import org.graphstream.util.parser.Token;
import org.graphstream.util.parser.TokenMgrError;
@SuppressWarnings("unused")
public class StyleSheetParser {
/**
* The style sheet.
*/
protected StyleSheet stylesheet;
public StyleSheetParser( StyleSheet stylesheet, InputStream stream )
{
this( stream );
this.stylesheet = stylesheet;
}
public StyleSheetParser( StyleSheet stylesheet, Reader stream )
{
this( stream );
this.stylesheet = stylesheet;
}
public static class Number
{
public float value;
public Style.Units units = Style.Units.PX;
public Number( float value, Style.Units units ) { this.value=value; this.units = units; }
}
/**
* Closes the parser, closing the opened stream.
*/
public void close() throws IOException {
jj_input_stream.close();
}
}
PARSER_END(StyleSheetParser)
/*
* The lexer.
*/
SKIP :
{
" "
| "\r"
| "\t"
| "\n"
}
//
// Base tokens.
//
TOKEN: { < #EOL : (("\r")|("\n"))> }
TOKEN: { < #DIGIT : ["0"-"9"] > }
TOKEN: { < #HEXDIGIT : (["0"-"9","a"-"f","A"-"F"])> }
TOKEN: { < #UNITS : (("gu")|("px")|("%"))> }
TOKEN: { < DOT : "." > }
TOKEN: { < LBRACE : "{" > }
TOKEN: { < RBRACE : "}" > }
TOKEN: { < LPAREN : "(" > }
TOKEN: { < RPAREN : ")" > }
TOKEN: { < SHARP : "#" > }
TOKEN: { < COLON : ":" > }
TOKEN: { < SEMICOLON : ";" > }
TOKEN: { < COMA : "," > }
//TOKEN: { < RGBA : "rgba("(){1,3}","(){1,3}","(){1,3}","(){1,3}")" > }
//TOKEN: { < RGB : "rgb("(){1,3}","(){1,3}","(){1,3}")" > }
TOKEN: { < RGBA : "rgba" > }
TOKEN: { < RGB : "rgb" > }
TOKEN: { < HTMLCOLOR : ( "#" (((){3})|((){4})|((){6})|((){8})|((){9})|((){12})|((){16})) ) > }
TOKEN: { < REAL : ( "-" | "+" )? ( )+ ( "." ()+ )? ()? > }
TOKEN: { < STRING : (("\"" (~["\""])* "\"")|("'" (~["'"])* "'")) > }
TOKEN: { < URL : "url" > }
//
// Selectors.
//
TOKEN: { < GRAPH : "graph" > }
TOKEN: { < EDGE : "edge" > }
TOKEN: { < NODE : "node" > }
TOKEN: { < SPRITE : "sprite" > }
//
// General properties.
//
TOKEN: { < FILLMODE : "fill-mode" > }
TOKEN: { < FILLCOLOR : "fill-color" > }
TOKEN: { < FILLIMAGE : "fill-image" > }
TOKEN: { < STROKEMODE : "stroke-mode" > }
TOKEN: { < STROKECOLOR : "stroke-color" > }
TOKEN: { < STROKEWIDTH : "stroke-width" > }
TOKEN: { < SHADOWMODE : "shadow-mode" > }
TOKEN: { < SHADOWCOLOR : "shadow-color" > }
TOKEN: { < SHADOWWIDTH : "shadow-width" > }
TOKEN: { < SHADOWOFFSET : "shadow-offset" > }
TOKEN: { < TEXTMODE : "text-mode" > }
TOKEN: { < TEXTCOLOR : "text-color" > }
TOKEN: { < TEXTSTYLE : "text-style" > }
TOKEN: { < TEXTFONT : "text-font" > }
TOKEN: { < TEXTSIZE : "text-size" > }
TOKEN: { < TEXTVISIBILITYMODE: "text-visibility-mode" > }
TOKEN: { < TEXTVISIBILITY : "text-visibility" > }
TOKEN: { < TEXTBACKGROUNDMODE: "text-background-mode" > }
TOKEN: { < TEXTBACKGROUNDCOLOR: "text-background-color" > }
TOKEN: { < TEXTOFFSET : "text-offset" > }
TOKEN: { < TEXTPADDING : "text-padding" > }
TOKEN: { < ICONMODE : "icon-mode" > }
TOKEN: { < ICON : "icon" > }
TOKEN: { < PADDING : "padding" > }
TOKEN: { < ZINDEX : "z-index" > }
TOKEN: { < VISIBILITYMODE : "visibility-mode" > }
TOKEN: { < VISIBILITY : "visibility" > }
//
// Properties common to nodes, edges and sprites.
//
TOKEN: { < SHAPE : "shape" > }
TOKEN: { < SIZE : "size" > }
TOKEN: { < SIZEMODE : "size-mode" > }
TOKEN: { < SHAPEPOINTS : "shape-points" > }
TOKEN: { < TEXTALIGNMENT : "text-alignment" > }
TOKEN: { < JCOMPONENT : "jcomponent" > }
//
// Properties for edges only.
//
TOKEN: { < ARROWIMGURL : "arrow-image" > }
TOKEN: { < ARROWSIZE : "arrow-size" > }
TOKEN: { < ARROWSHAPE : "arrow-shape" > }
//
// Properties for sprites only.
//
TOKEN: { < SPRITEORIENT : "sprite-orientation" > }
//
// Properties for graphs only.
//
TOKEN: { < CANVASCOLOR : "canvas-color" > }
//
// Property values.
//
TOKEN: { < PLAIN : "plain" > }
TOKEN: { < DYNPLAIN : "dyn-plain" > }
TOKEN: { < DYNSIZE : "dyn-size" > }
TOKEN: { < DYNICON : "dyn-icon" > }
TOKEN: { < DASHES : "dashes" > }
TOKEN: { < DOTS : "dots" > }
TOKEN: { < DOUBLE : "double" > }
TOKEN: { < GRADIENTDIAGONAL1 : "gradient-diagonal1" > }
TOKEN: { < GRADIENTDIAGONAL2 : "gradient-diagonal2" > }
TOKEN: { < GRADIENTHORIZONTAL: "gradient-horizontal" > }
TOKEN: { < GRADIENTRADIAL : "gradient-radial" > }
TOKEN: { < GRADIENTVERTICAL : "gradient-vertical" > }
TOKEN: { < HIDDEN : "hidden" > }
TOKEN: { < IMAGETILED : "image-tiled" > }
TOKEN: { < IMAGESCALED : "image-scaled" > }
TOKEN: { < IMAGESCALEDRATIOMAX : "image-scaled-ratio-max" > }
TOKEN: { < IMAGESCALEDRATIOMIN : "image-scaled-ratio-min" > }
TOKEN: { < NONE : "none" > }
TOKEN: { < NORMAL : "normal" > }
TOKEN: { < TRUNCATED : "truncated"> }
TOKEN: { < ZOOMRANGE : "zoom-range" > }
TOKEN: { < ATZOOM : "at-zoom" > }
TOKEN: { < UNDERZOOM : "under-zoom" > }
TOKEN: { < OVERZOOM : "over-zoom" > }
TOKEN: { < ZOOMS : "zooms" > }
TOKEN: { < FIT : "fit" > }
TOKEN: { < BOLD : "bold" > }
TOKEN: { < BOLD_ITALIC : "bold-italic" > }
TOKEN: { < ITALIC : "italic" > }
TOKEN: { < ALONG : "along" > }
TOKEN: { < ATLEFT : "at-left" > }
TOKEN: { < ATRIGHT : "at-right" > }
TOKEN: { < CENTER : "center" > }
TOKEN: { < LEFT : "left" > }
TOKEN: { < RIGHT : "right" > }
TOKEN: { < UNDER : "under" > }
TOKEN: { < ABOVE : "above" > }
TOKEN: { < JUSTIFY : "justify" > }
TOKEN: { < CIRCLE : "circle" > }
TOKEN: { < TRIANGLE : "triangle" > }
TOKEN: { < FREEPLANE : "freeplane" > }
TOKEN: { < TEXTBOX : "text-box" > }
TOKEN: { < TEXTROUNDEDBOX : "text-rounded-box" > }
TOKEN: { < TEXTCIRCLE : "text-circle" > }
TOKEN: { < TEXTDIAMOND : "text-diamond" > }
TOKEN: { < TEXTPARAGRAPH : "text-paragraph" > }
TOKEN: { < BOX : "box" > }
TOKEN: { < ROUNDEDBOX : "rounded-box" > }
TOKEN: { < CROSS : "cross" > }
TOKEN: { < DIAMOND : "diamond" > }
TOKEN: { < POLYGON : "polygon" > }
TOKEN: { < BUTTON : "button" > }
TOKEN: { < TEXTFIELD : "text-field" > }
TOKEN: { < PANEL : "panel" > }
TOKEN: { < LINE : "line" > }
TOKEN: { < POLYLINE : "polyline" > }
TOKEN: { < POLYLINESCALED : "polyline-scaled" > }
TOKEN: { < ANGLE : "angle" > }
TOKEN: { < CUBICCURVE : "cubic-curve" > }
TOKEN: { < BLOB : "blob" > }
TOKEN: { < SQUARELINE : "square-line" > }
TOKEN: { < LSQUARELINE : "L-square-line" > }
TOKEN: { < HSQUARELINE : "horizontal-square-line" > }
TOKEN: { < VSQUARELINE : "vertical-square-line" > }
TOKEN: { < ARROW : "arrow" > }
TOKEN: { < FLOW : "flow" > }
TOKEN: { < PIECHART : "pie-chart" > }
TOKEN: { < IMAGE : "image" > }
TOKEN: { < IMAGES : "images" > }
TOKEN: { < FROM : "from" > }
TOKEN: { < NODE0 : "node0" > }
TOKEN: { < TO : "to" > }
TOKEN: { < NODE1 : "node1" > }
TOKEN: { < PROJECTION : "projection" > }
TOKEN: { < CLICKED : "clicked" > }
TOKEN: { < SELECTED : "selected" > }
//
// More base tokens that must appear at the end for precedence reasons.
//
TOKEN: { < IDENTIFIER : (["a"-"z","A"-"Z"])(["a"-"z","A"-"Z","0"-"9","_"])* > }
TOKEN: { < COMMENT : ("/*"(~["*"])* "*/" ) | ( "//"((~["\r","\n"])*) ) > }
/*
* The parser.
*/
void start():
{
Rule r;
}
{
( r=rule() { stylesheet.addRule( r ); }
|
)*
}
Rule rule():
{
Selector select;
Style style;
Rule rule;
}
{
select=select()
{
rule = new Rule( select );
style = new Style();
rule.setStyle( style );
}
( styles( style ) )
{ return rule; }
}
void styles( Style style ):
{}
{
( style(style) )*
}
void stylesStart(Style style):
{}
{
(style(style))*
}
Selector select():
{
Token t;
Selector select;
}
{
( ( { select=new Selector( Selector.Type.GRAPH ); } )
| ( { select=new Selector( Selector.Type.NODE ); } )
| ( { select=new Selector( Selector.Type.EDGE ); } )
| ( { select=new Selector( Selector.Type.SPRITE ); } )
)
( ( ( ( t= { select.setId( t.image ); } )
| ( t= { select.setId( t.image.substring( 1, t.image.length()-1 ) ); } )
| ( t= { select.setId( t.image.toString() ); } )
)
)
| ( ( ( t= { select.setClass( t.image ); } )
| ( t= { select.setClass( "clicked" ); } ) // If we want "clicked" and
| ( t= { select.setClass( "selected" ); } ) // "selected" to be normal classes.
| ( t= { select.setClass( t.image.substring( 1, t.image.length()-1 ) ); } )
)
)
)?
( ( ( { select.setPseudoClass( "clicked" ); } )
| ( { select.setPseudoClass( "selected" ); } )
| ( t= { select.setPseudoClass( t.image.substring( 1, t.image.length()-1 ) ); } )
| ( t= { select.setPseudoClass( t.image ); } )
)
)?
{ return select; }
}
void style( Style style ):
{
Color color;
Colors colors;
String url;
Value value;
Values values;
Style.FillMode fillMode;
Style.StrokeMode strokeMode;
Style.ShadowMode shadowMode;
Style.TextMode textMode;
Style.TextVisibilityMode textVisMode;
Style.TextBackgroundMode textBgMode;
Style.TextStyle textStyle;
Style.TextAlignment textAlignment;
Style.IconMode iconMode;
Style.VisibilityMode visMode;
Style.SizeMode sizeMode;
Style.Shape shape;
Style.SpriteOrientation spriteOrient;
Style.ArrowShape arrowShape;
Style.JComponents component;
}
{
( ( )
| ( value = value() { style.setValue( "z-index", new Integer( (int)value.value ) ); } )
| ( fillMode = fillMode() { style.setValue( "fill-mode", fillMode ); } )
| ( colors = colors() { style.setValue( "fill-color", colors ); } )
| ( url = url() { style.setValue( "fill-image", url ); } )
| ( strokeMode = strokeMode() { style.setValue( "stroke-mode", strokeMode ); } )
| ( colors = colors() { style.setValue( "stroke-color", colors ); } )
| ( value = value() { style.setValue( "stroke-width", value ); } )
| ( shadowMode = shadowMode() { style.setValue( "shadow-mode", shadowMode ); } )
| ( colors = colors() { style.setValue( "shadow-color", colors ); } )
| ( value = value() { style.setValue( "shadow-width", value ); } )
| ( values = values() { style.setValue( "shadow-offset", values ); } )
| ( values = values() { style.setValue( "padding", values ); } )
| ( textMode = textMode() { style.setValue( "text-mode", textMode ); } )
| ( textVisMode = textVisMode() { style.setValue( "text-visibility-mode", textVisMode ); } )
| ( values = values() { style.setValue( "text-visibility", values ); } )
| ( textBgMode = textBgMode() { style.setValue( "text-background-mode", textBgMode ); } )
| ( colors = colors() { style.setValue( "text-color", colors ); } )
| ( colors = colors() { style.setValue( "text-background-color", colors ); } )
| ( textStyle = textStyle() { style.setValue( "text-style", textStyle ); } )
| ( url = font() { style.setValue( "text-font", url ); } )
| ( value = value() { style.setValue( "text-size", value ); } )
| ( textAlignment = textAlign() { style.setValue( "text-alignment", textAlignment ); } )
| ( values = values() { style.setValue( "text-offset", values ); } )
| ( values = values() { style.setValue( "text-padding", values ); } )
| ( iconMode = iconMode() { style.setValue( "icon-mode", iconMode ); } )
| ( url = icon() { style.setValue( "icon", url ); } )
| ( component = jcomponent() { style.setValue( "jcomponent", component ); } )
| ( visMode = visMode() { style.setValue( "visibility-mode", visMode ); } )
| ( values = values() { style.setValue( "visibility", values ); } )
| ( sizeMode = sizeMode() { style.setValue( "size-mode", sizeMode ); } )
| ( values = values() { style.setValue( "size", values ); } )
| ( values = values() { style.setValue( "shape-points", values ); } )
| ( shape = shape() { style.setValue( "shape", shape ); } )
| ( spriteOrient = spriteOrient() { style.setValue( "sprite-orientation", spriteOrient ); } )
| ( arrowShape = arrowShape() { style.setValue( "arrow-shape", arrowShape ); } )
| ( url = url() { style.setValue( "arrow-image", url ); } )
| ( values = values() { style.setValue( "arrow-size", values ); } )
| ( colors = colors() { style.setValue( "canvas-color", colors ); } )
)
}
Value value():
{
Token t;
Style.Units units = Style.Units.PX;
Value value = null;
}
{
t =
{
String nb = t.image.toLowerCase();
if( nb.endsWith( "px" ) )
{
units = Style.Units.PX;
nb = nb.substring( 0, nb.length()-2 );
}
else if( nb.endsWith( "gu" ) )
{
units = Style.Units.GU;
nb = nb.substring( 0, nb.length()-2 );
}
else if( nb.endsWith( "%" ) )
{
units = Style.Units.PERCENTS;
nb = nb.substring( 0, nb.length()-1 );
}
try{ value = new Value( units, Float.parseFloat( nb ) ); }
catch( NumberFormatException e ) { generateParseException(); }
return value;
}
}
Values values():
{
Values values;
Value value;
}
{
value = value() { values = new Values( value.units, value.value ); }
( value = value() { values.addValues( value.value ); } )*
{ return values; }
}
String url():
{
Token t;
}
{
t=
{ return t.image.substring( 1, t.image.length()-1 ); }
}
String icon():
{
String s;
}
{
( { return "dynamic"; }
| s = url() { return s; }
)
}
String font():
{
Token t;
String s;
}
{
( ( t= { s = t.image; } )
| ( t= { s = t.image.substring( 1, t.image.length()-1 ); } )
)
{ return s; }
}
Color color():
{
Token t;
String s;
Token r, g, b, a;
}
{
( ( r= g= b= { s = String.format("rgb(%s,%s,%s)", r.image, g.image, b.image); } )
| ( r= g= b= a= { s = String.format("rgba(%s,%s,%s,%s)", r.image, g.image, b.image, a.image); } )
| ( t= { s = t.image; } )
| ( t= { s = t.image; } )
| ( t= { s = t.image.substring( 1, t.image.length()-1 ); } )
)
{
Color color = Style.convertColor( s );
if( color == null ) color = Color.BLACK;
return color;
}
}
Colors colors():
{
Colors colors = new Colors();
Color color;
}
{
color = color() { colors.add( color ); }
( color = color() { colors.add( color ); } )*
{ return colors; }
}
Style.FillMode fillMode():
{
Style.FillMode m;
}
{
( ( { m = Style.FillMode.NONE; } )
| ( { m = Style.FillMode.PLAIN; } )
| ( { m = Style.FillMode.DYN_PLAIN; } )
| ( { m = Style.FillMode.GRADIENT_RADIAL; } )
| ( { m = Style.FillMode.GRADIENT_VERTICAL; } )
| ( { m = Style.FillMode.GRADIENT_HORIZONTAL; } )
| ( { m = Style.FillMode.GRADIENT_DIAGONAL1; } )
| ( { m = Style.FillMode.GRADIENT_DIAGONAL2; } )
| ( { m = Style.FillMode.IMAGE_TILED; } )
| ( { m = Style.FillMode.IMAGE_SCALED; } )
| ( { m = Style.FillMode.IMAGE_SCALED_RATIO_MAX; } )
| ( { m = Style.FillMode.IMAGE_SCALED_RATIO_MIN; } )
)
{ return m; }
}
Style.StrokeMode strokeMode():
{
Style.StrokeMode m;
}
{
( ( { m = Style.StrokeMode.NONE; } )
| ( { m = Style.StrokeMode.PLAIN; } )
| ( { m = Style.StrokeMode.DASHES; } )
| ( { m = Style.StrokeMode.DOTS; } )
| ( { m = Style.StrokeMode.DOUBLE; } )
)
{ return m; }
}
Style.ShadowMode shadowMode():
{
Style.ShadowMode s;
}
{
( ( { s = Style.ShadowMode.NONE; } )
| ( { s = Style.ShadowMode.PLAIN; } )
| ( { s = Style.ShadowMode.GRADIENT_RADIAL; } )
| ( { s = Style.ShadowMode.GRADIENT_HORIZONTAL; } )
| ( { s = Style.ShadowMode.GRADIENT_VERTICAL; } )
| ( { s = Style.ShadowMode.GRADIENT_DIAGONAL1; } )
| ( { s = Style.ShadowMode.GRADIENT_DIAGONAL2; } )
)
{ return s; }
}
Style.TextMode textMode():
{
Style.TextMode m;
}
{
( ( { m = Style.TextMode.NORMAL; } )
| ( { m = Style.TextMode.HIDDEN; } )
| ( { m = Style.TextMode.TRUNCATED; } )
)
{ return m; }
}
Style.TextVisibilityMode textVisMode():
{
Style.TextVisibilityMode m;
}
{
( ( { m = Style.TextVisibilityMode.NORMAL; } )
| ( { m = Style.TextVisibilityMode.HIDDEN; } )
| ( { m = Style.TextVisibilityMode.AT_ZOOM; } )
| ( { m = Style.TextVisibilityMode.UNDER_ZOOM; } )
| ( { m = Style.TextVisibilityMode.OVER_ZOOM; } )
| ( { m = Style.TextVisibilityMode.ZOOM_RANGE; } )
| ( { m = Style.TextVisibilityMode.ZOOMS; } )
)
{ return m; }
}
Style.TextBackgroundMode textBgMode():
{
Style.TextBackgroundMode m;
}
{
( ( { m = Style.TextBackgroundMode.NONE; } )
| ( { m = Style.TextBackgroundMode.PLAIN; } )
| ( { m = Style.TextBackgroundMode.ROUNDEDBOX; } )
)
{ return m; }
}
Style.TextStyle textStyle():
{
Style.TextStyle t;
}
{
( ( { t = Style.TextStyle.NORMAL; } )
| ( { t = Style.TextStyle.BOLD; } )
| ( { t = Style.TextStyle.ITALIC; } )
| ( { t = Style.TextStyle.BOLD_ITALIC; } )
)
{ return t; }
}
Style.SizeMode sizeMode():
{
Style.SizeMode m;
}
{
( ( { m = Style.SizeMode.NORMAL; } )
| ( { m = Style.SizeMode.FIT; } )
| ( { m = Style.SizeMode.DYN_SIZE; } )
)
{ return m; }
}
Style.TextAlignment textAlign():
{
Style.TextAlignment t;
}
{
( ( { t = Style.TextAlignment.CENTER; } )
| ( { t = Style.TextAlignment.LEFT; } )
| ( { t = Style.TextAlignment.RIGHT; } )
| ( { t = Style.TextAlignment.AT_LEFT; } )
| ( { t = Style.TextAlignment.AT_RIGHT; } )
| ( { t = Style.TextAlignment.UNDER; } )
| ( { t = Style.TextAlignment.ABOVE; } )
| ( { t = Style.TextAlignment.JUSTIFY; } )
| ( { t = Style.TextAlignment.ALONG; } )
)
{ return t; }
}
Style.IconMode iconMode():
{
Style.IconMode i;
}
{
( ( { i = Style.IconMode.NONE; } )
| ( { i = Style.IconMode.AT_LEFT; } )
| ( { i = Style.IconMode.AT_RIGHT; } )
| ( { i = Style.IconMode.ABOVE; } )
| (