-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructuresView.java
More file actions
78 lines (63 loc) · 2.21 KB
/
StructuresView.java
File metadata and controls
78 lines (63 loc) · 2.21 KB
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
package view;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by Hadi on 2/3/2015 8:47 AM.
*/
public class StructuresView extends JPanel {
private JPanel structuresPanel = new JPanel();
private ArrayList<SingleStructure> structures = new ArrayList<>();
private JButton mAddObjectType = new JButton("New Type");
private JButton mRemoveObjectType = new JButton("Remove Type");
public StructuresView() {
setLayout(new BorderLayout());
add(structuresPanel, BorderLayout.NORTH);
structuresPanel.setLayout(new GridLayout(0, 1));
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new GridLayout(1, 2));
buttonsPanel.add(mAddObjectType);
buttonsPanel.add(mRemoveObjectType);
add(buttonsPanel, BorderLayout.SOUTH);
}
public SingleStructure addStructure(String name) {
SingleStructure structure = new SingleStructure(name);
structures.add(structure);
structuresPanel.add(structure);
structuresPanel.revalidate();
structuresPanel.repaint();
return structure;
}
public SingleStructure removeStructure(String name) {
int index = -1;
for (int i = 0; i < structures.size() && index == -1; i++)
if (structures.get(i).getName().equals(name))
index = i;
if (index == -1)
return null;
structuresPanel.remove(index);
return structures.remove(index);
}
public void removeAllStructures() {
structuresPanel.removeAll();
structures.clear();
revalidate();
repaint();
}
public SingleStructure[] getStructures() {
return structures.toArray(new SingleStructure[structures.size()]);
}
public SingleStructure getStructure(String name) {
int index = -1;
for (int i = 0; i < structures.size() && index == -1; i++)
if (structures.get(i).getName().equals(name))
index = i;
return index == -1 ? null : structures.get(index);
}
public JButton getAddObjectType() {
return mAddObjectType;
}
public JButton getRemoveObjectType() {
return mRemoveObjectType;
}
}