1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.dialogs;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20
21 import javax.swing.JButton;
22 import javax.swing.JDialog;
23 import javax.swing.JPanel;
24
25 import p3j.gui.panels.projections.IProjectionTree;
26 import p3j.gui.panels.projections.ProjectionTreeNode;
27 import p3j.misc.gui.GUI;
28
29 import com.jgoodies.forms.builder.ButtonBarBuilder2;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public abstract class AbstractProjectionTreeDialog<E, N extends ProjectionTreeNode<E>>
47 extends JDialog {
48
49
50 private static final long serialVersionUID = -1735341315107050803L;
51
52
53 private final E entity;
54
55
56 private final N entityNode;
57
58
59 private IProjectionTree projectionTree;
60
61
62 private final JButton cancelButton = new JButton("Cancel");
63 {
64 cancelButton.addActionListener(new ActionListener() {
65 @Override
66 public void actionPerformed(ActionEvent e) {
67 cancel();
68 }
69 });
70 }
71
72
73 private final JButton okButton = new JButton("OK");
74 {
75 okButton.addActionListener(new ActionListener() {
76 @Override
77 public void actionPerformed(ActionEvent e) {
78 ok();
79 }
80 });
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 public AbstractProjectionTreeDialog(N projNode, IProjectionTree projTree,
99 int width, int height, String okButtonText) {
100 entity = projNode.getEntity();
101 entityNode = projNode;
102 setProjectionTree(projTree);
103 okButton.setText(okButtonText);
104 setSize(width, height);
105 GUI.centerOnScreen(this);
106 }
107
108
109
110
111
112
113 protected JPanel getButtonPanel() {
114 ButtonBarBuilder2 bbBuilder = new ButtonBarBuilder2();
115 bbBuilder.addButton(okButton);
116 bbBuilder.addRelatedGap();
117 bbBuilder.addButton(cancelButton);
118 return bbBuilder.getPanel();
119 }
120
121
122
123
124 protected abstract void ok();
125
126
127
128
129 protected abstract void cancel();
130
131 public N getEntityNode() {
132 return entityNode;
133 }
134
135 public IProjectionTree getProjectionTree() {
136 return projectionTree;
137 }
138
139 public final void setProjectionTree(IProjectionTree projectionTree) {
140 this.projectionTree = projectionTree;
141 }
142
143 public E getEntity() {
144 return entity;
145 }
146 }