-
Notifications
You must be signed in to change notification settings - Fork 1
/
CCGunitBuild.java
312 lines (265 loc) · 11.3 KB
/
CCGunitBuild.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package ccg.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
public class CCGunitBuild extends JFrame
{
private static final long serialVersionUID = 1L;
private JPanel masterPanel;
private static String genOut;
private JTextField clssNameTxtFld;
private JLabel clssLbl;
private JPanel hasGroup, isGroup;
private JToggleButton superTgglBtn;
private JToggleButton constantsTgglBtn;
private JToggleButton toStringTgglBtn;
private JToggleButton instVarTgglBtn;
private JToggleButton methodsTgglBtn;
private JToggleButton dataDefTgglBtn;
private JRadioButton abstractRdBtn, finalRdBtn;
private ButtonGroup group;
public static void main(String[] args) {
EventQueue.invokeLater(
new Runnable() {
public void run() {
try {
CCGunitBuild frame = new CCGunitBuild();
frame.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
}
public CCGunitBuild()
{
/*general form op's*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 900, 500);
masterPanel = new JPanel();
masterPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
masterPanel.setLayout(new BorderLayout(0, 0));
setContentPane(masterPanel);
//JPanel panel = new JPanel();
//masterPanel.add(panel, BorderLayout.CENTER);
final JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP);
//tabs.setSize(400,400);
/*Class Specs for Tab 1*/
JPanel clssPnl = new JPanel();
clssLbl = new JLabel("Class Name:");
clssNameTxtFld = new JTextField(10);
/*class has toggle bttns*/
workClassHas();
/*class 'is' details*/
/*class 'is' toggle bttns*/
dataDefTgglBtn = new JToggleButton("Defines Data");
dataDefTgglBtn.setSize(new Dimension(20,20));
abstractRdBtn = new JRadioButton("Abstract");
finalRdBtn = new JRadioButton("Final");
group = new ButtonGroup();
isGroup = new JPanel(new GridLayout(3,1));
group.add(abstractRdBtn);group.add(finalRdBtn);
isGroup.add(abstractRdBtn);isGroup.add(finalRdBtn);
isGroup.add(dataDefTgglBtn);
isGroup.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.GRAY, Color.WHITE), "Class Is"));
//clssPnl.add(isGroup);
clssPnl.setSize(250, 250);
tabs.addTab("Class", clssPnl);
GroupLayout gl_clssPnl = new GroupLayout(clssPnl);
gl_clssPnl.setHorizontalGroup(
gl_clssPnl.createParallelGroup(Alignment.LEADING)
.addGroup(gl_clssPnl.createSequentialGroup()
.addGroup(gl_clssPnl.createParallelGroup(Alignment.LEADING)
.addGroup(gl_clssPnl.createSequentialGroup()
.addGap(5)
.addComponent(clssLbl)
.addGap(5)
.addComponent(clssNameTxtFld, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_clssPnl.createSequentialGroup()
.addContainerGap()
.addComponent(hasGroup, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(158, Short.MAX_VALUE))
);
gl_clssPnl.setVerticalGroup(
gl_clssPnl.createParallelGroup(Alignment.LEADING)
.addGroup(gl_clssPnl.createSequentialGroup()
.addGroup(gl_clssPnl.createParallelGroup(Alignment.LEADING)
.addGroup(gl_clssPnl.createSequentialGroup()
.addGap(71)
.addComponent(clssLbl))
.addGroup(gl_clssPnl.createSequentialGroup()
.addGap(69)
.addComponent(clssNameTxtFld, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGap(18)
.addComponent(hasGroup, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addContainerGap(157, Short.MAX_VALUE))
);
clssPnl.setLayout(gl_clssPnl);
/*interface work*/
JPanel intfcPnl = new JPanel();
intfcPnl.add(new JButton("rawr"));
intfcPnl.setSize(200, 200);
tabs.addTab("Interface", intfcPnl);
/*output textfield and other mechanics*/
GroupLayout gl_panel = new GroupLayout(masterPanel);
workerOutput(tabs, gl_panel, masterPanel);
}
/**
* TODO
* */
private void workClassHas()
{
superTgglBtn = new JToggleButton("Super");
superTgglBtn.setSize(new Dimension(20,20));
constantsTgglBtn = new JToggleButton("Constants");
constantsTgglBtn.setSize(new Dimension(20,20));
toStringTgglBtn = new JToggleButton("toString");
toStringTgglBtn.setSize(new Dimension(20,20));
instVarTgglBtn = new JToggleButton("Instance Vars.");
instVarTgglBtn.setSize(new Dimension(20,20));
methodsTgglBtn = new JToggleButton("Methods");
methodsTgglBtn.setSize(new Dimension(20,20));
hasGroup = new JPanel(new GridLayout(5,1));
hasGroup.add(superTgglBtn);hasGroup.add(constantsTgglBtn);
hasGroup.add(toStringTgglBtn);
hasGroup.add(instVarTgglBtn);hasGroup.add(methodsTgglBtn);
hasGroup.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.GRAY,
Color.WHITE), "Class Has"));
}
/**
* Worker method that will make and manage the output textfield and bttns.
*
* */
private void workerOutput(final JTabbedPane myTabs, GroupLayout gm, JPanel myPnl)
{
final JTextArea generatedOutput = new JTextArea();
JLabel outputLbl = new JLabel("Output");
JButton getBttn = new JButton("Get");
genOut = new String("public ");
getBttn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
if(myTabs.getSelectedIndex() == 0)
{
genOut = "public class ";
genOut = form(clssNameTxtFld);
}
else if(myTabs.getSelectedIndex() == 1)
{
genOut = "public interface";
}
generatedOutput.setText(genOut.toString());
}
});
/*reset the var value and update the output textfield*/
JButton resetBttn = new JButton("Reset");
resetBttn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent arg0){generatedOutput.setText("");genOut = "";}
});
gm.setHorizontalGroup(gm.createParallelGroup(Alignment.LEADING)
.addGroup(gm.createSequentialGroup().addGap(21)
.addComponent(myTabs, GroupLayout.PREFERRED_SIZE, 374, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
.addGroup(gm.createParallelGroup(Alignment.TRAILING)
.addGroup(gm.createSequentialGroup()
.addGroup(gm.createParallelGroup(Alignment.TRAILING)
.addComponent(getBttn).addComponent(outputLbl))
.addGap(22))
.addGroup(gm.createSequentialGroup().addComponent(resetBttn)
.addPreferredGap(ComponentPlacement.UNRELATED)))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(generatedOutput, GroupLayout.PREFERRED_SIZE, 311, GroupLayout.PREFERRED_SIZE)
.addGap(39)));
gm.setVerticalGroup(gm.createParallelGroup(Alignment.TRAILING)
.addGroup(gm.createSequentialGroup()
.addGroup(gm.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gm.createSequentialGroup()
.addContainerGap()
.addComponent(myTabs, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))
.addGroup(gm.createSequentialGroup()
.addGap(43)
.addGroup(gm.createParallelGroup(Alignment.BASELINE)
.addGroup(gm.createSequentialGroup()
.addComponent(outputLbl)
.addGap(2)
.addComponent(getBttn)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(resetBttn))
.addComponent(generatedOutput, GroupLayout.PREFERRED_SIZE, 395, GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
myPnl.setLayout(gm);
gm.setHorizontalGroup(
gm.createParallelGroup(Alignment.LEADING)
.addGroup(gm.createSequentialGroup()
.addGap(21)
.addComponent(myTabs, GroupLayout.PREFERRED_SIZE, 374, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
.addGroup(gm.createParallelGroup(Alignment.TRAILING)
.addGroup(gm.createSequentialGroup()
.addGroup(gm.createParallelGroup(Alignment.TRAILING)
.addComponent(getBttn)
.addComponent(outputLbl))
.addGap(22))
.addGroup(gm.createSequentialGroup()
.addComponent(resetBttn)
.addPreferredGap(ComponentPlacement.UNRELATED)))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(generatedOutput, GroupLayout.PREFERRED_SIZE, 311, GroupLayout.PREFERRED_SIZE)
.addGap(39))
);
gm.setVerticalGroup(
gm.createParallelGroup(Alignment.TRAILING)
.addGroup(gm.createSequentialGroup()
.addGroup(gm.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gm.createSequentialGroup()
.addContainerGap()
.addComponent(myTabs, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))
.addGroup(gm.createSequentialGroup()
.addGap(43)
.addGroup(gm.createParallelGroup(Alignment.BASELINE)
.addGroup(gm.createSequentialGroup()
.addComponent(outputLbl)
.addGap(2)
.addComponent(getBttn)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(resetBttn))
.addComponent(generatedOutput, GroupLayout.PREFERRED_SIZE, 395, GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
myPnl.setLayout(gm);
}
private static String form(JTextField clssNameTxtFld)
{
String out = genOut + clssNameTxtFld.getText();
return out;
}
}