1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.projections;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.swing.JButton;
24 import javax.swing.JPanel;
25 import javax.swing.JTextArea;
26 import javax.swing.JTextField;
27 import javax.swing.tree.TreePath;
28
29 import p3j.database.DatabaseFactory;
30 import p3j.gui.dialogs.AdjustMaxAgeDialog;
31 import p3j.gui.dialogs.DuplicateProjectionDialog;
32 import p3j.gui.dialogs.NewSetTypeDialog;
33 import p3j.gui.dialogs.ProjectionDialog;
34 import p3j.gui.misc.SubNodeSummary;
35 import p3j.gui.panels.PropertiesShowPanelFactory;
36 import p3j.misc.Misc;
37 import p3j.pppm.ProjectionModel;
38 import p3j.pppm.sets.SetType;
39
40
41
42
43
44
45
46
47
48
49 public class ProjectionNode extends ProjectionTreeNode<ProjectionModel> {
50
51
52 private static final long serialVersionUID = 8332182127722759791L;
53
54
55
56
57
58
59
60 public ProjectionNode(ProjectionModel projection) {
61 super(projection, projection.getName());
62 }
63
64 @Override
65 public void deselected() {
66
67 }
68
69 @Override
70 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
71
72
73 final ProjectionNode node = this;
74 final JTextField name = new JTextField(getEntity().getName());
75 final JTextArea description = new JTextArea(getEntity().getDescription());
76 final JTextField jumpOffYear = new JTextField(Integer.toString(getEntity()
77 .getJumpOffYear()));
78
79 JButton duplicateButton = new JButton("Duplicate");
80 duplicateButton.addActionListener(new ActionListener() {
81 @Override
82 public void actionPerformed(ActionEvent e) {
83 DuplicateProjectionDialog dp = new DuplicateProjectionDialog(
84 getEntity());
85 dp.setVisible(true);
86 }
87 });
88
89 JButton createSetTypeButton = new JButton("New Settype");
90 createSetTypeButton.addActionListener(new ActionListener() {
91 @Override
92 public void actionPerformed(ActionEvent e) {
93 NewSetTypeDialog nstd = new NewSetTypeDialog(node, projTree);
94 nstd.setVisible(true);
95 SetType newSetType = nstd.getNewSetType();
96 DatabaseFactory.getDatabaseSingleton().saveSetType(newSetType);
97 projTree.totalRefresh();
98 projTree.selectNode(node.getChildWithEntity(newSetType));
99 }
100 });
101
102 JButton applyButton = new JButton("Apply");
103 applyButton.addActionListener(new ActionListener() {
104 @Override
105 public void actionPerformed(ActionEvent e) {
106 ProjectionModel projection = getEntity();
107 projection.setName(name.getText());
108 projection.setDescription(description.getText());
109 projection.setJumpOffYear(Integer.parseInt(jumpOffYear.getText()));
110 setUserObject(projection.getName());
111 DatabaseFactory.getDatabaseSingleton().saveProjection(projection);
112 projTree.refreshNode(node);
113 }
114 });
115
116 JButton adjustMaxAgeButton = new JButton("Adjust Age Classes");
117 adjustMaxAgeButton.addActionListener(new ActionListener() {
118 @Override
119 public void actionPerformed(ActionEvent e) {
120 adjustMaxAge(getEntity());
121 }
122 });
123
124 List<JButton> buttons = new ArrayList<JButton>();
125 buttons.add(duplicateButton);
126 buttons.add(adjustMaxAgeButton);
127 buttons.add(createSetTypeButton);
128 buttons.add(applyButton);
129 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
130 pspf.sep("General Information");
131 pspf.app(Misc.GUI_LABEL_NAME, name);
132 pspf.app(Misc.GUI_LABEL_DESCRIPTION, description, 2);
133 pspf.app(Misc.GUI_LABEL_JUMP_OFF_YEAR, jumpOffYear);
134 pspf.app("Settypes:", getEntity().getAllSetTypes().size());
135 pspf.app("Descendant Generations:", getEntity().getGenerations() - 1);
136 pspf.app("Years to be predicted:", getEntity().getYears());
137 pspf.app("Number of age classes", getEntity().getNumberOfAgeClasses());
138 pspf.appPreview(new SubNodeSummary<SetType>(node, projTree, SetType.class));
139 return pspf.constructPanel();
140 }
141
142
143
144
145
146
147
148 protected void adjustMaxAge(ProjectionModel projectionModel) {
149 ProjectionDialog maDialog = new AdjustMaxAgeDialog(projectionModel);
150 maDialog.setVisible(true);
151 }
152 }