1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package test.css.utils; 26 27 import javafx.css.StyleConverter; 28 import javafx.css.CssMetaData; 29 import javafx.css.converter.*; 30 import com.sun.javafx.scene.layout.region.*; 31 import java.util.HashSet; 32 import java.util.Set; 33 34 /** 35 * 36 * @author Andrey Nazarov 37 */ 38 public class StyleGenerator { 39 40 static Set<CssMetaData> uniqKeys = new HashSet<CssMetaData>(); 41 42 static public void addKey(CssMetaData key) { 43 uniqKeys.add(key); 44 } 45 static StringBuffer unknownTypes = new StringBuffer(); 46 static StringBuffer genCode = new StringBuffer("--------------Generated code for unused css styles----------\n"); 47 48 public static void generate() { 49 for (CssMetaData key : uniqKeys) { 50 String value = getValueByType(key.getConverter()); 51 if (value == null) { 52 unknownTypes.append("Don't know value of property ").append(key.getProperty()).append(" of type ").append(key.getConverter()).append("\n"); 53 continue; 54 } 55 genCode.append("props2Impls.put(\""); 56 genCode.append(key.getProperty() + "\", new CssStyle[]{\n"); 57 genCode.append("new CssStyle(\"" + key.getProperty().substring(4).toUpperCase() + "\",\n"); 58 genCode.append("\"" + key.getProperty() + ": \"+\n"); 59 genCode.append("\""); 60 genCode.append(value + ";\")});\n"); 61 } 62 System.out.println(genCode.toString()); 63 System.out.println("----------------------Errors-------------------------"); 64 System.out.println(unknownTypes.toString()); 65 } 66 67 static String getValueByType(StyleConverter type) { 68 if (type instanceof BooleanConverter) { 69 return "true"; 70 } else if (type instanceof ColorConverter) { 71 return "red"; 72 } else if (type instanceof SizeConverter) { 73 return "40"; 74 } else if (type instanceof StringConverter) { 75 return "Just text"; 76 } else if (type instanceof InsetsConverter || type.toString().equals("InsetsSequenceConverter") || type.toString().equals("MarginsSequenceConverter")) { 77 return "10 5 30 15"; 78 //} else if (type instanceof BackgroundFillConverter) { 79 // return "linear (0%,0%) to (100%,100%) stops (0.0,yellow) (1.0,red)"; 80 } else if (type instanceof PaintConverter) { 81 return "green , linear (0%,0%) to (100%,100%) stops (0.0,yellow) (1.0,red)"; 82 //} else if (type instanceof StrokeBorderConverter) { 83 // return "round"; 84 //} else if (type instanceof LayeredBorderPaintConverter) { 85 // return "green blue yellow red"; 86 } else if (type instanceof FontConverter) { 87 return "15 cursive bolder"; 88 } else if (type instanceof EnumConverter) { 89 return "TODO type " + type.toString(); 90 } else if (type instanceof PaintConverter) { 91 return "ladder black stops (0.49, white) (0.5, black)"; 92 //} else if (type instanceof URLConverter || type instanceof BackgroundImageConverter || type instanceof BorderImageConverter || type.toString().equals("URLSeqType")) { 93 // return "url(\\\"file:javafx/scene/control/test/css/resources/car.png\\\")"; 94 } else if (type instanceof CursorConverter) { 95 return "crosshair"; 96 } else { 97 return null; 98 } 99 } 100 }