Skip to content

Commit b5815e6

Browse files
authored
Merge pull request #34 from UCSDOalads/addCDEFbykaic
Add History UI
2 parents a082739 + 75c0517 commit b5815e6

9 files changed

Lines changed: 201 additions & 6 deletions

TODOList.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88
8. Auto-Update Display Box Affected by Recent Changes
99
9. Debug Undo Function
1010
10. Type Cast try (String) catch
11+
12+
13+
14+
1. File Save
15+
2. ClassSearch
16+
11. Display history
17+
12.
18+
13.

src/actions/AddLazyJavaClassAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import actions.edit.undoredo.SharedUndoRedoActionManager;
88
import actions.edit.undoredo.UndoRedoableInterface;
99
import actions.menu.ActionsMenuBarTitles;
10-
import actions.menu.PaintActionMenuItem;
1110
import paintcomponents.java.lazy.ClassPaintComponent;
1211
import ui.PaintPanel;
13-
import ui.helper.ClassSearchFrame;
14-
import ui.helper.ClassSearchFrameDelegateInterface;
12+
import ui.helper.classsearch.ClassSearchFrame;
13+
import ui.helper.classsearch.ClassSearchFrameDelegateInterface;
1514

1615
public class AddLazyJavaClassAction extends PaintAction {
1716

src/ui/helper/ClassSearchFrame.java renamed to src/ui/helper/classsearch/ClassSearchFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ui.helper;
1+
package ui.helper.classsearch;
22

33
import java.awt.BorderLayout;
44
import java.awt.event.ActionEvent;

src/ui/helper/ClassSearchFrameDelegateInterface.java renamed to src/ui/helper/classsearch/ClassSearchFrameDelegateInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ui.helper;
1+
package ui.helper.classsearch;
22

33
public interface ClassSearchFrameDelegateInterface {
44

src/ui/helper/ClassSearchFrameTest.java renamed to src/ui/helper/classsearch/ClassSearchFrameTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ui.helper;
1+
package ui.helper.classsearch;
22

33
import static org.junit.Assert.*;
44

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ui.helper.historyui;
2+
3+
public class HistoryDataObject {
4+
5+
String data;
6+
7+
public HistoryDataObject(String data){
8+
this.data = data;
9+
}
10+
11+
12+
public String toString(){
13+
return data;
14+
}
15+
16+
17+
18+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package ui.helper.historyui;
2+
3+
import java.awt.BorderLayout;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
7+
8+
import javax.swing.JFrame;
9+
import javax.swing.JPanel;
10+
import javax.swing.JScrollPane;
11+
import javax.swing.JTable;
12+
import javax.swing.ListSelectionModel;
13+
import javax.swing.table.DefaultTableModel;
14+
15+
16+
import javax.swing.DefaultListSelectionModel;
17+
import javax.swing.JButton;
18+
19+
public class HistoryUI extends JFrame
20+
{
21+
private static final long serialVersionUID = 8141494344180865577L;
22+
private JTable resultsTable;
23+
private DefaultTableModel defaultTableModel;
24+
private HistoryUIInterface delegate;
25+
26+
27+
private JPanel panel;
28+
private JScrollPane scrollPane;
29+
30+
31+
/*
32+
* Setup class finders
33+
*/
34+
public HistoryUI(String[] titles) {
35+
36+
// set the defaultTableModel to non editable by user clicking around
37+
defaultTableModel = new DefaultTableModel(0, 1) {
38+
private static final long serialVersionUID = 1L;
39+
40+
@Override
41+
public boolean isCellEditable(int row, int column) {
42+
return false;
43+
44+
}
45+
};
46+
47+
// big JPanel window
48+
panel = new JPanel();
49+
getContentPane().add(panel, BorderLayout.CENTER);
50+
panel.setLayout(new BorderLayout(0, 0));
51+
52+
// show result
53+
resultsTable = new JTable();
54+
resultsTable.setModel(defaultTableModel);
55+
resultsTable.setSelectionModel(new ForcedListSelectionModel());
56+
57+
// scroll option
58+
scrollPane = new JScrollPane(resultsTable);
59+
panel.add(scrollPane, BorderLayout.CENTER);
60+
61+
// add small JPanel for Cancel and Confirm buttons
62+
JPanel buttom_panel = new JPanel();
63+
getContentPane().add(buttom_panel, BorderLayout.SOUTH);
64+
65+
//create buttons from array list
66+
for (String title : titles){
67+
JButton button = new JButton(title);
68+
buttom_panel.add(button);
69+
button.addActionListener(new ActionListener() {
70+
71+
@Override
72+
public void actionPerformed(ActionEvent e) {
73+
delegate.didPressButton(title, resultsTable.getSelectedRow());
74+
75+
}
76+
});
77+
}
78+
}
79+
80+
//add a row to the end of table
81+
public void insert(HistoryDataObject e){
82+
defaultTableModel.addRow(new Object[] {e.toString()});
83+
}
84+
85+
86+
87+
public void setDelegate(HistoryUIInterface delegate) {
88+
this.delegate = delegate;
89+
}
90+
91+
/*
92+
* Forcedly remove single selection in JTable
93+
*/
94+
private static class ForcedListSelectionModel
95+
extends
96+
DefaultListSelectionModel {
97+
private static final long serialVersionUID = 1L;
98+
99+
public ForcedListSelectionModel() {
100+
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
101+
};
102+
}
103+
104+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ui.helper.historyui;
2+
3+
public interface HistoryUIInterface {
4+
5+
/**
6+
* Called when a button is pressed.
7+
* @param buttonName The name of the button
8+
* @param selectedRow the index of selected row. -1 if no row selected
9+
*/
10+
11+
public void didPressButton(String buttonName, int selectedRow);
12+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ui.helper.historyui;
2+
3+
4+
5+
import java.awt.Dimension;
6+
7+
import javax.swing.SwingUtilities;
8+
9+
import org.junit.Before;
10+
import org.junit.Test;
11+
12+
public class HistoryUITest {
13+
14+
HistoryUI historyUI;
15+
16+
17+
@Before
18+
public void setUp(){
19+
String[] arr = {"cacel","revert","confirm"};
20+
historyUI = new HistoryUI(arr);
21+
historyUI.insert(new HistoryDataObject("AAAA"));
22+
historyUI.insert(new HistoryDataObject("BBB"));
23+
}
24+
25+
@Test
26+
public void test() throws InterruptedException {
27+
SwingUtilities.invokeLater(new Runnable() {
28+
29+
@Override
30+
public void run() {
31+
//ClassSearchFrame classSearchFrame = new ClassSearchFrame();
32+
33+
historyUI.setDelegate(new HistoryUIInterface() {
34+
35+
@Override
36+
public void didPressButton(String buttonName, int selectedRow) {
37+
System.out.println("buttonname = " + buttonName + "; selectedRow = " + selectedRow);
38+
39+
}
40+
});
41+
42+
43+
historyUI.setVisible(true);
44+
historyUI.setSize(new Dimension(300, 200));
45+
46+
47+
}
48+
});
49+
Thread.sleep(Long.MAX_VALUE);
50+
}
51+
52+
53+
54+
}

0 commit comments

Comments
 (0)