forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.java
148 lines (130 loc) · 3.15 KB
/
Util.java
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
137
138
139
140
141
142
143
144
145
146
147
import java.awt.*;
import java.awt.image.*;
class Util
{
static Frame fr;
static Graphics g;
static Font f;
static FontMetrics fnm;
static Toolkit tk;
static Color light_edge = Color.white;
static Color dark_edge = Color.black;
static Color body = Color.lightGray;
static Color body_hi = new Color(210, 210, 210);
static Color light_edge_hi = Color.white;
static Color dark_edge_hi = Color.darkGray;
static Color dark_bg = new Color(150, 150, 150);
static Color text = Color.black;
static Color light_bg = Color.white;
static
{
fr = new Frame();
fr.addNotify();
g = fr.getGraphics();
setFont(new Font("TimesRoman", Font.PLAIN, 8));
tk = Toolkit.getDefaultToolkit();
}
static boolean waitForImage(Image i)
{
MediaTracker mt = new MediaTracker(fr);
mt.addImage(i, 0);
try { mt.waitForAll(); } catch(Exception e) { return false; }
return !mt.isErrorAny();
}
static boolean waitForImage(Image i, int w, int h)
{
MediaTracker mt = new MediaTracker(fr);
mt.addImage(i, w, h, 0);
try { mt.waitForAll(); } catch(Exception e) { return false; }
return !mt.isErrorAny();
}
static int getWidth(Image i)
{
waitForImage(i);
return i.getWidth(fr);
}
static int getHeight(Image i)
{
waitForImage(i);
return i.getHeight(fr);
}
static Image createImage(int w, int h)
{
return fr.createImage(w, h);
}
static Image createImage(ImageProducer p)
{
return fr.createImage(p);
}
static Object createObject(String name)
{
try {
Class c = Class.forName(name);
return c.newInstance();
}
catch(Exception e) {
System.err.println("Failed to create object "+name+" : "+
e.getClass().getName());
System.exit(1);
}
return null;
}
/**Create a new instance of some object
*/
static Object createObject(Object o)
{
try { return o.getClass().newInstance(); }
catch(Exception e) {
System.err.println("Failed to reproduce object "+o+" : "+
e.getClass().getName());
System.exit(1);
}
return null;
}
static void dottedRect(Graphics g, int x1, int y1,
int x2, int y2, int s)
{
int i, s2 = s*2, t;
if (x2 < x1) { t = x1; x1 = x2; x2 = t; }
if (y2 < y1) { t = y1; y1 = y2; y2 = t; }
for(i=x1; i<=x2; i+=s2)
g.drawLine(i, y1, i+s > x2 ? x2 : i+s, y1);
for(i=y1; i<=y2; i+=s2)
g.drawLine(x2, i, x2, i+s > y2 ? y2 : i+s);
for(i=x2; i>=x1; i-=s2)
g.drawLine(i, y2, i-s < x1 ? x1 : i-s, y2);
for(i=y2; i>=y1; i-=s2)
g.drawLine(x1, i, x1, i-s < y1 ? y1 : i-s);
}
static void recursiveLayout(Container c)
{
c.layout();
for(int i=0; i<c.countComponents(); i++) {
Component cc = c.getComponent(i);
if (cc instanceof Container)
recursiveLayout((Container)cc);
}
}
static void recursiveBackground(Component c, Color b)
{
if (c instanceof TextField || c instanceof Choice ||
c instanceof TextArea)
return; // leave these alone
c.setBackground(b);
if (c instanceof Container) {
Container cn = (Container)c;
for(int i=0; i<cn.countComponents(); i++)
recursiveBackground(cn.getComponent(i), b);
}
}
static void recursiveBody(Component c)
{
recursiveBackground(c, Util.body);
}
static void setFont(Font nf)
{
f = nf;
g.setFont(f);
fnm = g.getFontMetrics();
}
}