-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlanetReport.java
132 lines (102 loc) · 3.68 KB
/
PlanetReport.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
/**
* planet report class is report that display the report of all the immobile in the aquarium
* @author Adir Zoari 203002753
* @author Idan Levi 305562431
*/
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class PlanetReport extends JPanel{
/**
*
*/
private static final long serialVersionUID = 1L;
private String typeAnimal=null,idOb;
private int idObject=0;
private int optionTable;
private HashSet<Immobile> planetSet=new HashSet<Immobile>(); //hash set for swimmable
private HashMap<Integer, Memento> plantesMementoList;
private Set set;
private Iterator <Immobile>itrPlantes;
private JTable table;
private AquaPanel panel;
private JPanel tablePanel=new JPanel();
public void setDialog()
{
setSize(650,300);
setLayout(new BorderLayout());
}
public PlanetReport(AquaPanel panel,HashSet<Immobile> planetSet,int optionTable)
{
//setting Dialog
setDialog();
this.optionTable=optionTable;
this.panel=panel;
this.planetSet=new HashSet<Immobile>(planetSet);
//set panel
SettingTable();
add(tablePanel);
}
public PlanetReport(HashMap<Integer, Memento> plantesMementoList,int optionTable)
{
setDialog();
this.plantesMementoList=new HashMap<Integer, Memento>(plantesMementoList);
this.optionTable=optionTable;
SettingTable();
add(tablePanel);
}
public void SettingTable()
{
tablePanel=new JPanel();
itrPlantes= planetSet.iterator();
String[] columns=null;
if(optionTable==1)
columns=new String[]{"","ID","Planet","Color","Size"}; // columns
if(optionTable==2)
columns=new String[]{"","ID","Planet","Color","Size","x_front","y_front"}; // columns
DefaultTableModel tableModel = new DefaultTableModel(columns,0);
table=new JTable (tableModel);
table.setPreferredScrollableViewportSize(new Dimension(600,150));
if(optionTable==1){
while(itrPlantes.hasNext()){
Immobile im = itrPlantes.next();
String[] swimm=new String[]{"",String.valueOf(im.getID()),im.getPlanetName(),im.getColor(),String.valueOf(im.getSize())};
tableModel.addRow(swimm);
}
}
if(optionTable==2){
set=plantesMementoList.entrySet();
Iterator iterator=set.iterator();
while(iterator.hasNext()){
Map.Entry mentry = (Map.Entry)iterator.next();
Memento im = (Memento) mentry.getValue();
String[] swimm=new String[]{"",String.valueOf(im.getID()),im.getAnimalName(),im.getColor(),String.valueOf(im.getSize()),String.valueOf(im.getXfront()),String.valueOf(im.getYfront())};
tableModel.addRow(swimm);
}
}
table.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = table.rowAtPoint(evt.getPoint());
int col = table.columnAtPoint(evt.getPoint());
if (row >= 0 && col >= 0) {
idOb=(String) table.getValueAt(row, 1); //for check
typeAnimal=(String) (table.getValueAt(row, 2));
idObject=Integer.valueOf(idOb);
//System.out.println(idObject);
}
}
});
JScrollPane pane=new JScrollPane(table);
tablePanel.add(pane); // add the table to the panel
}
public int getIDobject(){return idObject;}
public String getTypeAnimal(){return typeAnimal;}
}