UIProperty.java revision 9330:8b1f1c2a400f
1226031Sstas/*
2226031Sstas * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3226031Sstas * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4226031Sstas *
5226031Sstas * This code is free software; you can redistribute it and/or modify it
6226031Sstas * under the terms of the GNU General Public License version 2 only, as
7226031Sstas * published by the Free Software Foundation.  Oracle designates this
8226031Sstas * particular file as subject to the "Classpath" exception as provided
9226031Sstas * by Oracle in the LICENSE file that accompanied this code.
10226031Sstas *
11226031Sstas * This code is distributed in the hope that it will be useful, but WITHOUT
12226031Sstas * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13226031Sstas * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14226031Sstas * version 2 for more details (a copy is included in the LICENSE file that
15226031Sstas * accompanied this code).
16226031Sstas *
17226031Sstas * You should have received a copy of the GNU General Public License version
18226031Sstas * 2 along with this work; if not, write to the Free Software Foundation,
19226031Sstas * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20226031Sstas *
21226031Sstas * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22226031Sstas * or visit www.oracle.com if you need additional information or have any
23226031Sstas * questions.
24226031Sstas */
25226031Sstas
26226031Sstaspackage build.tools.generatenimbus;
27226031Sstas
28226031Sstasimport javax.xml.bind.annotation.XmlAttribute;
29226031Sstasimport javax.xml.bind.annotation.XmlElement;
30226031Sstas
31226031Sstasclass UIProperty extends UIDefault<String> {
32226031Sstas    public static enum PropertyType {
33226031Sstas        BOOLEAN, INT, FLOAT, DOUBLE, STRING, FONT, COLOR, INSETS, DIMENSION, BORDER
34226031Sstas    }
35226031Sstas    @XmlAttribute private PropertyType type;
36226031Sstas
37226031Sstas    @XmlElement private Border border;
38226031Sstas    @XmlElement private Dimension dimension;
39226031Sstas    @XmlElement private Insets insets;
40226031Sstas    @XmlElement private Matte matte;
41226031Sstas    @XmlElement private Typeface typeface;
42226031Sstas
43226031Sstas    @XmlAttribute
44226031Sstas    @Override public void setValue(String value) {
45226031Sstas        super.setValue(value);
46226031Sstas    }
47226031Sstas
48226031Sstas    public String write(String prefix) {
49226031Sstas        switch (type) {
50226031Sstas            case BOOLEAN:
51226031Sstas                return String.format("        d.put(\"%s%s\", Boolean.%s);\n",
52226031Sstas                                     prefix, getName(), getValue().toUpperCase());  ///autobox
53226031Sstas            case STRING:
54226031Sstas                return String.format("        d.put(\"%s%s\", \"%s\");\n",
55226031Sstas                                     prefix, getName(), getValue());
56226031Sstas            case INT:
57226031Sstas                return String.format("        d.put(\"%s%s\", new Integer(%s));\n",
58226031Sstas                                     prefix, getName(), getValue());
59226031Sstas            case FLOAT:
60226031Sstas                return String.format("        d.put(\"%s%s\", new Float(%sf));\n",
61226031Sstas                                     prefix, getName(), getValue());
62226031Sstas            case DOUBLE:
63226031Sstas                return String.format("        d.put(\"%s%s\", new Double(%s));\n",
64226031Sstas                                     prefix, getName(), getValue());
65226031Sstas            case COLOR:
66226031Sstas                return String.format("        addColor(d, \"%s%s\", %s);\n",
67                                     prefix, getName(), matte.write());
68            case FONT:
69                return String.format("        d.put(\"%s%s\", %s);\n",
70                                     prefix, getName(), typeface.write());
71            case INSETS:
72                return String.format("        d.put(\"%s%s\", %s);\n",
73                                     prefix, getName(), insets.write(true));
74            case DIMENSION:
75                return String.format("        d.put(\"%s%s\", new DimensionUIResource(%d, %d));\n",
76                                     prefix, getName(), dimension.width, dimension.height);
77            case BORDER:
78                return String.format("        d.put(\"%s%s\", new BorderUIResource(%s));\n",
79                                     prefix, getName(), border.write());
80            default:
81                return "###  Look, something's wrong with UIProperty.write()  $$$";
82        }
83    }
84}
85