Skip to content

Commit 4610907

Browse files
committed
comment note
1 parent 4a59282 commit 4610907

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/ui/helper/historyui/HistoryDataObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package ui.helper.historyui;
22

3+
4+
/**
5+
*
6+
* HistoryDataOjbect
7+
*
8+
*/
39
public class HistoryDataObject {
410

511
String data;

src/ui/helper/historyui/HistoryUI.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323

2424

25-
25+
/**
26+
* create historyUI
27+
*
28+
*/
2629
public class HistoryUI extends JFrame
2730
{
2831
private static final long serialVersionUID = 8141494344180865577L;
@@ -37,8 +40,10 @@ public class HistoryUI extends JFrame
3740
@SuppressWarnings("rawtypes")
3841
private Stack<ArrayList> delete_history;
3942

40-
/*
43+
/**
4144
* Setup historyUI
45+
*
46+
* param: receive a list of button names
4247
*/
4348
public HistoryUI(String[] titles) {
4449

@@ -67,21 +72,23 @@ public boolean isCellEditable(int row, int column) {
6772
scrollPane = new JScrollPane(resultsTable);
6873
panel.add(scrollPane, BorderLayout.CENTER);
6974

70-
// add small JPanel for Cancel and Confirm buttons
75+
// add small JPanel for buttons
7176
JPanel button_panel = new JPanel();
7277
getContentPane().add(button_panel, BorderLayout.SOUTH);
7378

7479
//initialize buttons
7580
createButtons(titles, button_panel);
7681

82+
//stack, used to stored deleted rows
7783
delete_history = new Stack<>();
7884
}
7985

80-
/*
86+
/**
8187
* create buttons
8288
* param: a list of buttons' name and button panel
8389
*/
8490
public void createButtons(String[] titles, JPanel button_panel){
91+
//loop through arr and add buttons
8592
for (String title : titles){
8693
JButton button = new JButton(title);
8794
button_panel.add(button);
@@ -100,12 +107,12 @@ else if(title == "exit"){
100107
System.exit(EXIT_ON_CLOSE);
101108
}
102109

103-
//if revert button pressed
110+
//if revert button pressed, revert to last version
104111
else if(title =="revert"){
105112
revert();
106113
}
107114

108-
//if clear button pressed
115+
//if clear button pressed, delete all rows in table
109116
else if(title =="clear"){
110117
int num_rows = resultsTable.getRowCount();
111118
int[] indices = IntStream.range(0, num_rows).toArray();
@@ -119,15 +126,19 @@ else if(title =="clear"){
119126
}
120127

121128

122-
/*
129+
/**
123130
* revert deleted rows
124131
*/
125132
@SuppressWarnings("rawtypes")
126133
public void revert(){
134+
127135
if(!delete_history.isEmpty()){
128136
ArrayList arr = delete_history.pop();
137+
//get the deleted rows and corresponding data
129138
int[] indices = (int[]) arr.get(0);
130139
HistoryDataObject[] objects = (HistoryDataObject[]) arr.get(1);
140+
141+
//insert data to its row
131142
for(int i = 0; i<indices.length; i++){
132143
defaultTableModel.insertRow(indices[i], new Object[] {objects[i]} );
133144
}
@@ -136,7 +147,7 @@ public void revert(){
136147

137148

138149

139-
/*
150+
/**
140151
* add a row to the end of table
141152
* receive a HistoryDataObject
142153
*/
@@ -145,22 +156,24 @@ public void insert(HistoryDataObject e){
145156
}
146157

147158

148-
/*
159+
/**
149160
* remove several selected rows from table and stores them into stack
150161
* param: an array of rows number to be removed
151162
*/
152163
@SuppressWarnings({ "rawtypes", "unchecked" })
153164
public void removeSeveralRows(int[] indices){
154-
//create a arr to hold the deleted data and rows
165+
//create a arr to hold the deleted rows and its data
155166
ArrayList arr = new ArrayList<>();
156167
HistoryDataObject[] objects = new HistoryDataObject[indices.length];
157168
Arrays.sort(indices);
158169

170+
//loop through indices and delete
159171
for(int i=indices.length-1;i>=0;i--){
160172
objects[i] = (HistoryDataObject) resultsTable.getModel().getValueAt(indices[i], 0);
161173
defaultTableModel.removeRow(indices[i]);
162174
}
163175

176+
//stores deleted rows and its data to delete_history stack
164177
arr.add(indices);
165178
arr.add(objects);
166179
delete_history.push(arr);
@@ -170,8 +183,8 @@ public void setDelegate(HistoryUIInterface delegate) {
170183
this.delegate = delegate;
171184
}
172185

173-
/*
174-
* Forcedly remove single selection in JTable
186+
/**
187+
* Forcedly multiple interval selection in JTable
175188
*/
176189
private static class ForcedListSelectionModel
177190
extends

0 commit comments

Comments
 (0)