Skip to content

Commit 90d2070

Browse files
author
x1gong
committed
method input dialog v1
1 parent f2150f7 commit 90d2070

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package ui.helper.methodinput;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
import java.lang.reflect.Method;
7+
8+
import javax.swing.DefaultListSelectionModel;
9+
import javax.swing.JButton;
10+
import javax.swing.JFrame;
11+
import javax.swing.JPanel;
12+
import javax.swing.JScrollPane;
13+
import javax.swing.JTable;
14+
import javax.swing.JTextField;
15+
import javax.swing.ListSelectionModel;
16+
import javax.swing.table.DefaultTableModel;
17+
18+
19+
public class MethodInputFrame extends JFrame {
20+
21+
private JTextField searchingTextField;
22+
private JTable resultsTable;
23+
private JButton btnCancel, btnConfirm;
24+
private JPanel panel;
25+
private JScrollPane scrollPane;
26+
private DefaultTableModel defaultTableModel;
27+
28+
private Class mtdClass;
29+
private Method[] methods;
30+
31+
32+
public MethodInputFrame(Class c) {
33+
// set the defaultTableModel to non editable by user clicking around
34+
defaultTableModel = new DefaultTableModel(0, 1) {
35+
@Override
36+
public boolean isCellEditable(int row, int column) {
37+
return false;
38+
}
39+
};
40+
41+
this.mtdClass = c;
42+
this.methods = this.mtdClass.getMethods();
43+
44+
// big JPanel window
45+
panel = new JPanel();
46+
getContentPane().add(panel, BorderLayout.CENTER);
47+
panel.setLayout(new BorderLayout(0, 0));
48+
49+
searchingTextField = new JTextField();
50+
getContentPane().add(searchingTextField, BorderLayout.NORTH);
51+
searchingTextField.setColumns(10);
52+
53+
// show result
54+
resultsTable = new JTable();
55+
resultsTable.setModel(defaultTableModel);
56+
resultsTable.setSelectionModel(new ForcedListSelectionModel());
57+
58+
// scroll option
59+
scrollPane = new JScrollPane(resultsTable);
60+
panel.add(scrollPane, BorderLayout.CENTER);
61+
62+
// add small JPanel for Cancel and Confirm buttons
63+
JPanel panel_1 = new JPanel();
64+
getContentPane().add(panel_1, BorderLayout.SOUTH);
65+
66+
ButtonListener listener = new ButtonListener();
67+
68+
btnCancel = new JButton("Cancel");
69+
panel_1.add(btnCancel);
70+
btnCancel.addActionListener(listener);
71+
72+
btnConfirm = new JButton("Confirm");
73+
panel_1.add(btnConfirm);
74+
btnConfirm.addActionListener(listener);
75+
76+
// set up connections
77+
// searchingTextField.addActionListener(this);
78+
// searchingTextField.getDocument().addDocumentListener(this);
79+
}
80+
81+
82+
/*
83+
* Forcely remove single selection in Jtable
84+
*/
85+
private static class ForcedListSelectionModel
86+
extends
87+
DefaultListSelectionModel {
88+
public ForcedListSelectionModel() {
89+
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90+
};
91+
/*
92+
* potentially better solve the selection problem, but not needed at the
93+
* moment
94+
*
95+
* @Override public void clearSelection() { }
96+
*
97+
* @Override public void removeSelectionInterval(int index0, int index1)
98+
* { }
99+
*/
100+
}
101+
102+
private class ButtonListener implements ActionListener {
103+
104+
@Override
105+
public void actionPerformed(ActionEvent e) {
106+
if (e.getSource() == btnCancel) {
107+
108+
} else if (e.getSource() == btnConfirm) {
109+
110+
}
111+
}
112+
113+
}
114+
}

0 commit comments

Comments
 (0)