-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddShapeDialog.java
67 lines (53 loc) · 1.81 KB
/
AddShapeDialog.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
package lab2.gui.dialog.addshape;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import lab2.shapes.plump.Shape3D;
public class AddShapeDialog extends JDialog {
private JPanel mainPanel;
private JPanel cardPanel;
private JComboBox<String> chooser;
private Shape3D value;
public AddShapeDialog(JFrame owner) {
super(owner, "Add shape...", true);
this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
value = null;
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
chooser = new JComboBox<String>();
chooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
CardLayout cl = (CardLayout) cardPanel.getLayout();
cl.show(cardPanel, (String) chooser.getSelectedItem());
}
});
mainPanel.add(chooser);
cardPanel = new JPanel();
cardPanel.setLayout(new CardLayout());
AddShapeCard[] cards = {new AddCubeCard(), new AddCuboidCard(), new AddBallCard(), new AddCylinderCard()};
for (AddShapeCard card : cards) {
JPanel cardButtonPanel = new JPanel();
cardButtonPanel.setLayout(new BoxLayout(cardButtonPanel, BoxLayout.Y_AXIS));
cardButtonPanel.add(card);
JButton submitButton = new JButton("Add");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
setValue(card.getValue());
}
});
cardButtonPanel.add(submitButton);
chooser.addItem(card.getTitle());
cardPanel.add(cardButtonPanel, card.getTitle());
}
mainPanel.add(cardPanel);
this.add(mainPanel);
this.pack();
}
public void setValue(Shape3D shape) {
value = shape;
setVisible(false);
}
public Shape3D getValue() {
return value;
}
}