Index: libskinlf-java-6.7/src/com/l2fprod/gui/plaf/skin/impl/gtk/parser/GtkParser.jj
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ libskinlf-java-6.7/src/com/l2fprod/gui/plaf/skin/impl/gtk/parser/GtkParser.jj 2011-08-29 23:42:10.000000000 +0200
@@ -0,0 +1,405 @@
+PARSER_BEGIN(GtkParser)
+
+/* ====================================================================
+ *
+ * @PROJECT.FULLNAME@ @VERSION@ License.
+ *
+ * Copyright (c) @YEAR@ L2FProd.com. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by L2FProd.com
+ * (http://www.L2FProd.com/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "@PROJECT.FULLNAME@", "SkinLF" and "L2FProd.com" must not
+ * be used to endorse or promote products derived from this software
+ * without prior written permission. For written permission, please
+ * contact info@L2FProd.com.
+ *
+ * 5. Products derived from this software may not be called "SkinLF"
+ * nor may "SkinLF" appear in their names without prior written
+ * permission of L2FProd.com.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ */
+package com.l2fprod.gui.plaf.skin.impl.gtk.parser;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Enumeration;
+import com.l2fprod.gui.plaf.skin.impl.gtk.*;
+import com.l2fprod.gui.plaf.skin.*;
+
+public class GtkParser {
+
+ Hashtable styleTable, classTable;
+ URL directory;
+
+ public static void main(String[] args) throws Exception {
+ GtkParser parser = new GtkParser(new FileInputStream(args[0]));
+ parser.buildStructure();
+ }
+
+
+ public GtkParser(String filename) throws Exception {
+ this(new File(filename));
+ }
+
+ public GtkParser(File file) throws Exception {
+ this(SkinUtils.toURL(file));
+ }
+
+ public GtkParser(URL url) throws Exception {
+ this(url.openStream());
+ directory = url;
+ /* String urlpath = url.toString();
+ int index = urlpath.lastIndexOf("/");
+
+ if (index != -1)
+ directory = new URL(urlpath.substring(0, index) + "/");
+ else
+ directory = new URL(urlpath + "/../");
+ */
+ //PENDING(fred): we could use directly the URL given because it could act as an url context...
+ // need testing...
+ }
+
+ public URL getDirectory() {
+ return directory;
+ }
+
+ /**
+ * Sets the Directory attribute of the GtkParser object
+ *
+ * @param dir The new Directory value
+ */
+ public void setDirectory(URL dir) {
+ directory = dir;
+ }
+
+ public Hashtable getStyles() {
+ return styleTable;
+ }
+
+ public Hashtable getClasses() {
+ return classTable;
+ }
+
+ public GtkStyle getStyle(String name) {
+ return (GtkStyle)getStyles().get(name);
+ }
+
+ public GtkClass getClass(String name) {
+ return (GtkClass)getClasses().get(name);
+ }
+
+}
+
+PARSER_END(GtkParser)
+
+SKIP: { " " | "\t" | "\n" | "\r" | "\f" }
+
+MORE :
+{
+ "#" : IN_SINGLE_LINE_COMMENT
+ |
+ <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
+ |
+ "/*" : IN_MULTI_LINE_COMMENT
+ }
+<IN_SINGLE_LINE_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT
+ }
+
+<IN_FORMAL_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <FORMAL_COMMENT: "*/" > : DEFAULT
+ }
+
+<IN_MULTI_LINE_COMMENT>
+ SPECIAL_TOKEN :
+{
+ <MULTI_LINE_COMMENT: "*/" > : DEFAULT
+ }
+
+<IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
+ MORE :
+{
+ < ~[] >
+ }
+
+TOKEN :
+{
+< DECIMAL_LITERAL: ((["0"-"9"])+ ("."(["0"-"9"])+)? )>
+| < STRING_LITERAL:
+ "\""
+ ( (~["\"","\\","\n","\r"])
+ | ("\\"
+ ( ["n","t","b","r","f","\\","'","\""]
+ | ["0"-"7"] ( ["0"-"7"] )?
+ | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+ )
+ )
+ )*
+ "\""
+ >
+}
+
+TOKEN: {
+ <BOOLEAN: "TRUE" | "FALSE">
+ | <EXTRA: "bg_pixmap" | "bg" | "fg" | "base" | "text">
+ | <FONT: "font">
+ | <STYLE: "style">
+ | <CLASS: "class">
+ | <ENGINE: "engine">
+ | <IMAGE: "image">
+ | <FUNCTION: "function">
+ | <RECOLORABLE: "recolorable">
+ | <FILE: "file">
+ | <BORDER: "border">
+ | <STRETCH: "stretch">
+ | <SHADOW: "shadow">
+ | <STATE: "state">
+ | <DETAIL: "detail">
+ | <GAP_SIDE: "gap_side">
+ | <GAP_FILE: "gap_file">
+ | <GAP_BORDER: "gap_border">
+ | <GAP_START_FILE: "gap_start_file">
+ | <GAP_START_BORDER: "gap_start_border">
+ | <GAP_END_FILE: "gap_end_file">
+ | <GAP_END_BORDER: "gap_end_border">
+ | <OVERLAY_FILE: "overlay_file">
+ | <OVERLAY_BORDER: "overlay_border">
+ | <OVERLAY_STRETCH: "overlay_stretch">
+ | <ORIENTATION: "orientation">
+ | <ARROW_DIRECTION: "arrow_direction">
+}
+
+TOKEN: {
+ <FUNCTION_TYPE: "ARROW" | "BOX" | "BOX_GAP" | "CHECK" | "EXTENSION" | "FLAT_BOX"
+ | "FOCUS" | "HANDLE" | "HLINE" | "OPTION" | "SHADOW" | "SHADOW_GAP"
+ | "SLIDER" | "VLINE" | "EXTENSION" | "TAB">
+| <STATE_TYPE: "ACTIVE" | "INSENSITIVE" | "NORMAL" | "PRELIGHT" | "SELECTED">
+| <SHADOW_TYPE: "ETCHED_IN" | "ETCHED_OUT" | "IN" | "OUT">
+| <ORIENTATION_TYPE: "HORIZONTAL" | "VERTICAL">
+| <DIRECTION: "DOWN" | "LEFT" | "RIGHT" | "UP" | "BOTTOM" | "TOP" >
+}
+
+TOKEN: {
+ <LCROC: "[">
+ | <RCROC: "]">
+ | <LBRACK: "{" >
+ | <RBRACK: "}" >
+ | <ASSIGN: "=" >
+ | <COMMA: "," >
+}
+
+TOKEN: {
+ <OTHER_TOKEN: "module_path" | "include" | "pixmap_path">
+ | <WIDGET_CLASS: "widget_class">
+ | <WIDGET: "widget">
+ | < PROPERTY_KEY: ( (["a"-"z"])+ )>
+}
+
+void buildStructure(): {
+ styleTable = new Hashtable();
+ classTable = new Hashtable();
+} {
+ (styleDefinition()
+ | classDefinition()
+ | whatever()
+ | widgetClassDefinition()
+ | widgetDefinition())*
+ {
+ for (Enumeration e = getClasses().keys(); e.hasMoreElements(); ) {
+ Object key = e.nextElement();
+ GtkClass clas = (GtkClass)getClasses().get(key);
+ for (int i = 0, c = clas.styles.size(); i < c; i++)
+ clas.styles.(i,(GtkStyle)getStyles().get(clas.styles.elementAt(i)));
+ }
+ }
+
+}
+
+void whatever(): {
+} {
+ <OTHER_TOKEN> readString()
+}
+
+void widgetClassDefinition(): {
+} {
+ <WIDGET_CLASS> readString() <STYLE> readString()
+}
+
+void widgetDefinition(): {
+} {
+ <WIDGET> readString() <STYLE> readString()
+}
+
+void styleDefinition(): {
+ GtkStyle style = new GtkStyle();
+ style.parser = this;
+ Token property, state = null;
+ String value = null;
+} {
+ <STYLE> style.name=readString() <LBRACK>
+ (<FONT> <ASSIGN> readString())*
+ (property=<EXTRA> <LCROC> state=<STATE_TYPE> <RCROC> <ASSIGN>
+ (value=readString() |
+ (<LBRACK> { value="{"; value = value + readFloat() + ","; } <COMMA>
+ { value = value + readFloat() + ","; } <COMMA>
+ { value = value + readFloat(); }
+ { value += "}"; }
+ <RBRACK>))
+ {style.setProperty(property.image + "[" + state + "]",
+ value);
+ })*
+ (<ENGINE> readString() <LBRACK>
+ { GtkEngine engine = new GtkEngine();
+ style.engine = engine;
+ engine.style = style; }
+ (imageDefinition(engine))*
+ <RBRACK>)?
+ <RBRACK>
+ {
+ styleTable.put(style.name, style);
+ }
+}
+
+void imageDefinition(GtkEngine engine): {
+ GtkImage image = new GtkImage();
+ Token property = null;
+ Token value = null;
+} {
+ <IMAGE> <LBRACK>
+ ((property=<FUNCTION> <ASSIGN> value=<FUNCTION_TYPE>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<RECOLORABLE> <ASSIGN> value=<BOOLEAN>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<STATE> <ASSIGN> value=<STATE_TYPE>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<DETAIL> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<FILE> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<BORDER> <ASSIGN>
+ { image.setProperty(property.image, borderDefinition()); })
+ | (property=<STRETCH> <ASSIGN> value=<BOOLEAN>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<OVERLAY_FILE> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<OVERLAY_BORDER> <ASSIGN>
+ { image.setProperty(property.image, borderDefinition()); })
+ | (property=<OVERLAY_STRETCH> <ASSIGN> value=<BOOLEAN>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<SHADOW> <ASSIGN> value=<SHADOW_TYPE>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<GAP_START_FILE> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<GAP_START_BORDER> <ASSIGN>
+ { image.setProperty(property.image, borderDefinition()); })
+ | (property=<GAP_END_FILE> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<GAP_END_BORDER> <ASSIGN>
+ { image.setProperty(property.image, borderDefinition()); })
+ | (property=<GAP_SIDE> <ASSIGN> value=<DIRECTION>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<GAP_FILE> <ASSIGN>
+ { image.setProperty(property.image, readString()); })
+ | (property=<GAP_BORDER> <ASSIGN>
+ { image.setProperty(property.image, borderDefinition()); })
+ | (property=<ORIENTATION> <ASSIGN> value=<ORIENTATION_TYPE>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<ARROW_DIRECTION> <ASSIGN> value=<DIRECTION>)
+ { image.setProperty(property.image, value.image); }
+ | (property=<PROPERTY_KEY> <ASSIGN>)
+ { image.setProperty(property.image, readString()); }
+ )+
+ <RBRACK>
+ { engine.addImage(image); }
+}
+
+GtkBorder borderDefinition(): {
+ GtkBorder border = new GtkBorder();
+ Token tok = null;
+} {
+ // left, right, top, bottom
+ <LBRACK> tok=<DECIMAL_LITERAL> { border.left = Integer.parseInt(tok.image); } <COMMA>
+ tok=<DECIMAL_LITERAL> { border.right = Integer.parseInt(tok.image); } <COMMA>
+ tok=<DECIMAL_LITERAL> { border.top = Integer.parseInt(tok.image); } <COMMA>
+ tok=<DECIMAL_LITERAL> { border.bottom = Integer.parseInt(tok.image); } <RBRACK> {
+ return border;
+ }
+}
+
+void classDefinition(): {
+ GtkClass clas;
+} {
+ <CLASS> { String name = readString();
+ clas = (GtkClass)classTable.get(name);
+ if (clas == null) {
+ clas = new GtkClass();
+ clas.setName(name);
+ classTable.put(clas.name, clas);
+ }
+ } <STYLE>
+ {
+ clas.addStyleName(readString());
+ }
+}
+
+String readString(): {
+ String value = null;
+ Token toks = null;
+} {
+ toks=<STRING_LITERAL> {
+ value = new String();
+ for (int i=1; i < toks.image.length()-1; i++) {
+ if (toks.image.charAt(i) == '\\') {
+ if ((toks.image.charAt(i+1) == '\\') || (toks.image.charAt(i+1) == '"')) {
+ i++;
+ }
+ }
+ value = value + toks.image.charAt(i);
+ }
+ return(value);
+ }
+}
+
+float readFloat(): {
+ Token toks = null;
+} {
+ toks = <DECIMAL_LITERAL> {
+ return Float.valueOf(token.image).floatValue();
+ }
+}