-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertiesMetalTheme.java
More file actions
117 lines (103 loc) · 3.28 KB
/
PropertiesMetalTheme.java
File metadata and controls
117 lines (103 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class PropertiesMetalTheme extends DefaultMetalTheme {
private String name = "Custom Theme";
private ColorUIResource primary1;
private ColorUIResource primary2;
private ColorUIResource primary3;
private ColorUIResource secondary1;
private ColorUIResource secondary2;
private ColorUIResource secondary3;
private ColorUIResource black;
private ColorUIResource white;
public PropertiesMetalTheme ( InputStream stream ) {
initColors();
loadProperties(stream);
}
private void initColors() {
primary1 = super.getPrimary1();
primary2 = super.getPrimary2();
primary3 = super.getPrimary3();
secondary1 = super.getSecondary1();
secondary2 = super.getSecondary2();
secondary3 = super.getSecondary3();
black = super.getBlack();
white = super.getWhite();
}
private void loadProperties (InputStream stream) {
Properties prop = new Properties();
try {
prop.load(stream);
}
catch (IOException e) {
System.out.println(e);
}
Object tempName = prop.get("name");
if (tempName != null) {
name = tempName.toString();
}
Object colorString = null;
colorString = prop.get ("primary1");
if (colorString != null){
primary1 = parseColor(colorString.toString());
}
colorString = prop.get("primary2");
if (colorString != null) {
primary2 = parseColor(colorString.toString());
}
colorString = prop.get("primary3");
if (colorString != null) {
primary3 = parseColor(colorString.toString());
}
colorString = prop.get("secondary1");
if (colorString != null) {
secondary1 = parseColor(colorString.toString());
}
colorString = prop.get("secondary2");
if (colorString != null) {
secondary2 = parseColor(colorString.toString());
}
colorString = prop.get("secondary3");
if (colorString != null) {
secondary3 = parseColor(colorString.toString());
}
colorString = prop.get("black");
if (colorString != null) {
black = parseColor(colorString.toString());
}
colorString = prop.get("white");
if (colorString != null) {
white = parseColor(colorString.toString());
}
}
public String getName() { return name; }
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
protected ColorUIResource getSecondary1() { return secondary1; }
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
protected ColorUIResource getBlack() { return black; }
protected ColorUIResource getWhite() { return white; }
private ColorUIResource parseColor(String s) {
int red = 0;
int green = 0;
int blue = 0;
try {
StringTokenizer st = new StringTokenizer(s, ",");
red = Integer.parseInt(st.nextToken());
green = Integer.parseInt(st.nextToken());
blue = Integer.parseInt(st.nextToken());
}
catch (Exception e) {
System.out.println(e);
System.out.println("Couldn't parse color :" + s);
}
return new ColorUIResource(red, green, blue);
}
}