-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectiveInfo.java
More file actions
123 lines (104 loc) · 2.25 KB
/
SelectiveInfo.java
File metadata and controls
123 lines (104 loc) · 2.25 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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/** @author Gergely Kota
SelectiveInfo returns the read value or null if the field is disabled
*/
public class SelectiveInfo extends JPanel
{
private JCheckBox jcb;
private JTextField jtf;
private JLabel label;
private String id;
private boolean selectable;
public SelectiveInfo(String s)
{
this(s, true);
}
public SelectiveInfo(String s, boolean x)
{
this(s, x, 150); // because I like numbers.
}
public SelectiveInfo(String s, boolean x, int textWidth)
{
this(s, x, textWidth, false);
}
public SelectiveInfo(String s, boolean x, int textWidth, boolean balanced)
{
id = s.trim() + ":";
selectable = x;
jcb = new JCheckBox(id, true);
JLabel jl = new JLabel(id);
label = new JLabel();
jcb.setPreferredSize(new Dimension(textWidth, 0));
jl.setPreferredSize(new Dimension(textWidth, 0));
jtf = new JTextField(15);
setLayout(new BorderLayout());
JPanel stuffing = new JPanel(new BorderLayout());
stuffing.add(GUtil.filler(10), BorderLayout.WEST);
stuffing.add(label, BorderLayout.CENTER);
if(balanced)
{
jtf = new JTextField();
JPanel leftside = new JPanel(new GridLayout(1,2));
if(selectable)
leftside.add(jcb);
else
leftside.add(jl);
leftside.add(jtf);
add(leftside, BorderLayout.WEST);
add(stuffing, BorderLayout.CENTER);
}
else
{
add(jtf, BorderLayout.CENTER);
if(selectable)
add(jcb, BorderLayout.WEST);
else
add(jl, BorderLayout.WEST);
add(stuffing, BorderLayout.EAST);
}
jcb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
onClick();
}
});
}
public void clear()
{
jtf.setText("");
}
public void setDescription(String s)
{
label.setText(s);
}
public void set(String s)
{
jtf.setText(s);
}
private void onClick()
{
if(selectable)
jtf.setEnabled(jcb.isSelected());
else
jcb.setSelected(true);
}
public String read()
{
if(jtf.isEnabled())
return jtf.getText().trim();
return null;
}
public void setEnabled(boolean x)
{
jcb.setSelected(x);
onClick();
}
public static void main(String[] arhs)
{
JFrame jf = new JFrame();
jf.getContentPane().add(new SelectiveInfo("Author"));
jf.pack();
jf.show();
}
}