Source Code Cross Referenced for ThemeFactory.java in  » Swing-Library » pgslookandfeel » com » pagosoft » plaf » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » pgslookandfeel » com.pagosoft.plaf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Patrick Gotthardt
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package com.pagosoft.plaf;
017:
018:        import com.pagosoft.OS;
019:        import com.pagosoft.swing.ColorUtils;
020:
021:        import java.awt.*;
022:        import java.io.File;
023:        import java.io.FileInputStream;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.Map;
027:        import java.util.Properties;
028:        import java.util.regex.Pattern;
029:
030:        public class ThemeFactory {
031:            public static final PgsTheme GRAY = createTheme("Gray", new Color(
032:                    0x7997D1), new Color(0xABABAB), Color.black);
033:            public static final PgsTheme YELLOW = createTheme("Yellow",
034:                    new Color(0xCCAA53), new Color(0xABABAB), Color.black);
035:            public static final PgsTheme RUBY = createTheme("Ruby", new Color(
036:                    244, 10, 66), new Color(0xABABAB), Color.black);
037:            public static final PgsTheme GOLD = createTheme("Gold", new Color(
038:                    0xFFDB29));
039:            public static final PgsTheme WIN = new PgsTheme("Win",
040:                    new Color(0x6080AC), // p1
041:                    new Color(0xFFCF31), // p2
042:                    new Color(0xF9E089), // p3
043:
044:                    new Color(0x666554), new Color(0xDCDBCB), new Color(
045:                            0xF1F0E3), Color.black, Color.white,
046:                    getWinCustomEntries());
047:            public static final PgsTheme GREEN = createTheme("Green",
048:                    new Color(0x986847), new Color(0xEFEBE7), Color.BLACK);
049:
050:            private static Object[] getWinCustomEntries() {
051:                Color s2 = new Color(0xDCDBCB);
052:                Color s3 = new Color(0xF1F0E3);
053:                Color p2 = new Color(0xF9E089);
054:                Color p3 = new Color(0xFFCF31);
055:                return new Object[] { "Button.rolloverGradientStart",
056:                        Color.white, "Button.rolloverGradientEnd", s2,
057:                        "Button.selectedGradientStart", p3,
058:                        "Button.selectedGradientEnd", p2,
059:
060:                        "ToggleButton.rolloverGradientStart", Color.white,
061:                        "ToggleButton.rolloverGradientEnd", s2,
062:                        "ToggleButton.selectedGradientStart", p3,
063:                        "ToggleButton.selectedGradientEnd", p2,
064:
065:                        "ToolBar.gradientStart", s3, "ToolBar.gradientEnd", s2,
066:
067:                        "ToolBarButton.rolloverGradientStart", p3,
068:                        "ToolBarButton.rolloverGradientEnd", p2,
069:                        "ToolBarButton.selectedGradientStart", p2,
070:                        "ToolBarButton.selectedGradientEnd", p3,
071:
072:                        "ScrollBar.thumb", p3, "ScrollBar.thumbHighlight",
073:                        p3.brighter(),
074:
075:                        "ProgressBar.gradientStart", p3,
076:                        "ProgressBar.gradientEnd", p3.brighter() };
077:            }
078:
079:            public static PgsTheme createTheme(Color primary) {
080:                return ThemeFactory.createTheme("PgsTheme", primary);
081:            }
082:
083:            public static PgsTheme createTheme(String name, Color primary) {
084:                Color[] cs = ColorUtils.mixColors(primary);
085:                return new PgsTheme(name, cs[2], cs[1], cs[0], // pri
086:                        cs[5], cs[4], cs[3], // sec
087:                        cs[8], cs[7]); // black 'n white
088:            }
089:
090:            public static PgsTheme createTheme(Color primary, Color secondary,
091:                    Color text) {
092:                return ThemeFactory.createTheme("Custom PgsTheme", primary,
093:                        secondary, text);
094:            }
095:
096:            public static PgsTheme getDefaultTheme() {
097:                if (OS.isWindows()) {
098:                    return WIN;
099:                }
100:                return GRAY;
101:            }
102:
103:            public static PgsTheme createTheme(String name, Color primary,
104:                    Color secondary, Color text) {
105:                return new PgsTheme(name, primary.darker(), // p1
106:                        primary, // p2
107:                        primary.brighter(), // p3
108:
109:                        secondary.darker(), // s1
110:                        secondary, // s2
111:                        secondary.brighter(), // s3
112:                        text, ColorUtils.oposite(text));
113:            }
114:
115:            /**
116:             * <p>Supported formats are:<br />
117:             * {@code colors: [primary], [secondary], [text]}<br />
118:             * {@code theme: [gray|ruby|win|yellow|gold]}<br />
119:             * {@code res: [theme_source_file]}</p>
120:             */
121:            public static PgsTheme getTheme(String theme) {
122:                if (theme == null) {
123:                    throw new IllegalArgumentException(
124:                            "theme must not be null!");
125:                }
126:                if (theme.startsWith("theme:")) {
127:                    String name = theme.substring(5).trim();
128:                    return ThemeFactory.getThemeByName(name);
129:                } else if (theme.startsWith("colors:")) {
130:                    String colors = theme.substring(6).trim();
131:                    return ThemeFactory.getThemeByColors(colors);
132:                } else if (theme.startsWith("res:")) {
133:                    String res = theme.substring(4).trim();
134:                    File f = new File(res);
135:                    if (f.exists()) {
136:                        Properties props = new Properties();
137:                        try {
138:                            FileInputStream fis = new FileInputStream(f);
139:                            props.load(fis);
140:                            fis.close();
141:                            return ThemeFactory.createTheme(props);
142:                        } catch (Exception ex) {
143:                            ex.printStackTrace();
144:                            return getDefaultTheme();
145:                        }
146:                    } else {
147:                        return getDefaultTheme();
148:                    }
149:                }
150:                return ThemeFactory.getDefaultTheme();
151:            }
152:
153:            public static PgsTheme getThemeByName(String theme) {
154:                if ("ruby".equalsIgnoreCase(theme)) {
155:                    return ThemeFactory.RUBY;
156:                } else if ("win".equalsIgnoreCase(theme)) {
157:                    return ThemeFactory.WIN;
158:                } else if ("yellow".equalsIgnoreCase(theme)) {
159:                    return ThemeFactory.YELLOW;
160:                } else if ("gold".equalsIgnoreCase(theme)) {
161:                    return ThemeFactory.GOLD;
162:                }
163:                return ThemeFactory.getDefaultTheme();
164:            }
165:
166:            public static PgsTheme getThemeByColors(String colors) {
167:                String[] color = colors.split(",?\\s*");
168:                if (color.length != 2) {
169:                    throw new IllegalArgumentException(
170:                            "Theme has the wrong format: '"
171:                                    + colors
172:                                    + "', but should be '[primary], [secondary], [text]'");
173:                }
174:                return ThemeFactory.createTheme(Color.decode(color[0]), Color
175:                        .decode(color[1]), Color.decode(color[2]));
176:            }
177:
178:            // This Pattern splits on any whitespace and ","
179:            private static final Pattern SPLIT = Pattern.compile("\\s*,?\\s*");
180:
181:            public static PgsTheme createTheme(Map map) {
182:                ArrayList data = new ArrayList();
183:                Iterator i = map.keySet().iterator();
184:                String value;
185:                String key;
186:                String name = "Custom PgsTheme";
187:                Color p1 = null, p2 = null, p3 = null, s1 = null, s2 = null, s3 = null, bl = Color.black, wh = Color.white;
188:                while (i.hasNext()) {
189:                    key = i.next().toString();
190:                    value = map.get(key).toString();
191:
192:                    if (key.equals("name")) {
193:                        name = value;
194:                    } else if (key.equals("primary1")) {
195:                        p1 = Color.decode(value);
196:                    } else if (key.equals("primary2")) {
197:                        p2 = Color.decode(value);
198:                    } else if (key.equals("primary3")) {
199:                        p3 = Color.decode(value);
200:                    } else if (key.equals("secondary1")) {
201:                        s1 = Color.decode(value);
202:                    } else if (key.equals("secondary2")) {
203:                        s2 = Color.decode(value);
204:                    } else if (key.equals("secondary3")) {
205:                        s3 = Color.decode(value);
206:                    } else if (key.equals("black")) {
207:                        bl = Color.decode(value);
208:                    } else if (key.equals("white")) {
209:                        wh = Color.decode(value);
210:                    } else {
211:                        data.add(key);
212:                        if (value.startsWith("#")) {
213:                            data.add(Color.decode(value));
214:                        } else if (value.equals("true")) {
215:                            data.add(Boolean.TRUE);
216:                        } else if (value.equals("false")) {
217:                            data.add(Boolean.FALSE);
218:                        } else {
219:                            String val[] = SPLIT.split(value);
220:                            switch (val.length) {
221:                            case 1:
222:                                int in = Integer.parseInt(val[0]);
223:                                data.add(new Insets(in, in, in, in));
224:                                break;
225:                            case 2:
226:                                int in1 = Integer.parseInt(val[0]);
227:                                int in2 = Integer.parseInt(val[1]);
228:                                data.add(new Insets(in1, in2, in1, in2));
229:                                break;
230:                            case 4:
231:                                data.add(new Insets(Integer.parseInt(val[0]),
232:                                        Integer.parseInt(val[1]), Integer
233:                                                .parseInt(val[2]), Integer
234:                                                .parseInt(val[3])));
235:                                break;
236:                            }
237:                        }
238:                    }
239:                }
240:                return new PgsTheme(name, p1, p2, p3, s1, s2, s3, bl, wh, data
241:                        .toArray());
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.