-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLayoutInflater.java
More file actions
136 lines (113 loc) · 3.29 KB
/
LayoutInflater.java
File metadata and controls
136 lines (113 loc) · 3.29 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package android.view;
import java.util.HashMap;
import javax.swing.JComponent;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.krikelin.spotifysource.Context;
public class LayoutInflater{
HashMap<Integer, JComponent> components = new HashMap<Integer, JComponent>();
/***
* @from http://forums.macrumors.com/showthread.php?t=368861
* @param source
*/
public String capitalize(String source)
{
String bob = "";
for (String string : source.split(" ")) {
bob+=(string.substring(0, 1).toUpperCase());
bob+=(string.substring(1).toLowerCase());
bob+=(" ");
}
return bob;
}
private JComponent rootComponent;
public JComponent deserialize(Node c) throws NoSuchMethodException
{
if (c instanceof org.w3c.dom.Element)
{
org.w3c.dom.Element elm = (org.w3c.dom.Element)c;
try {
JComponent _elm = (JComponent)Class.forName("javax.swing."+elm.getTagName().toLowerCase()).getConstructors()[0].newInstance(this);
for(int i=0; i <elm.getAttributes().getLength(); i++)
{
Node attrib = elm.getAttributes().item(i);
String val = attrib.getNodeValue();
String attribute = attrib.getNodeName();
String methodName = capitalize(attribute).trim();
if(attribute.startsWith("src"))
{
int ec = 3;
}
try
{
int valN = Integer.valueOf(val);
Class.forName("javax.swing."+elm.getTagName().toLowerCase()).getMethod("set"+methodName,java.lang.Integer.class).invoke(_elm,valN);
}
catch(Exception e)
{
try{
_elm.getClass().getDeclaredMethod("set"+methodName, String.class).invoke(_elm, val);
}
catch(Exception e2){
}
}
// set data of method
}
try
{
Node x= ((org.w3c.dom.Element)elm).getFirstChild();
if(x instanceof org.w3c.dom.Text)
if(x.getNodeValue() != null)
{
_elm.getClass().getMethod("setText", java.lang.String.class).invoke(_elm,x.getNodeValue());
}
}
catch(Exception e)
{
}
NodeList childNodes = elm.getChildNodes();
int length = childNodes.getLength();
for(int j=0; j < length; j++)
{
Node welm = childNodes.item(j);
Node parent = welm.getParentNode();
if(welm instanceof org.w3c.dom.Element)
{
if(welm.getParentNode()!=(elm))
continue;
JComponent f = deserialize(welm);
if(f != null)
{
// f.setBounds(new Rectangle(0,0,_elm.getWidth(),_elm.getHeight()));
_elm.add(f);
}
}
}
//_elm.getClass().((Object[])null);
return _elm;
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
public JComponent getRootComponent() {
return rootComponent;
}
public void setRootComponent(JComponent rootComponent) {
this.rootComponent = rootComponent;
}
}