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.dialogs.SubPopulationModelEditDialog;
35 import p3j.gui.misc.SubNodeSummary;
36 import p3j.gui.panels.PropertiesShowPanelFactory;
37 import p3j.misc.Misc;
38 import p3j.pppm.ProjectionModel;
39 import p3j.pppm.sets.SetType;
40
41
42
43
44
45
46
47
48
49
50 public class ProjectionNode extends ProjectionTreeNode<ProjectionModel> {
51
52
53 private static final long serialVersionUID = 8332182127722759791L;
54
55
56
57
58
59
60
61 public ProjectionNode(ProjectionModel projection) {
62 super(projection, projection.getName());
63 }
64
65 @Override
66 public void deselected() {
67
68 }
69
70 @Override
71 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
72
73
74 final ProjectionNode node = this;
75 final JTextField name = new JTextField(getEntity().getName());
76 final JTextArea description = new JTextArea(getEntity().getDescription());
77 final JTextField jumpOffYear = new JTextField(Integer.toString(getEntity()
78 .getJumpOffYear()));
79
80 JButton showSubPopsButton = new JButton("Show Sub-Population Structure");
81 showSubPopsButton.addActionListener(new ActionListener() {
82 @Override
83 public void actionPerformed(ActionEvent e) {
84 new SubPopulationModelEditDialog(getEntity().getSubPopulationModel(),
85 false).setVisible(true);
86 }
87 });
88
89 JButton duplicateButton = new JButton("Duplicate");
90 duplicateButton.addActionListener(new ActionListener() {
91 @Override
92 public void actionPerformed(ActionEvent e) {
93 DuplicateProjectionDialog dp = new DuplicateProjectionDialog(
94 getEntity());
95 dp.setVisible(true);
96 }
97 });
98
99 JButton createSetTypeButton = new JButton("New Settype");
100 createSetTypeButton.addActionListener(new ActionListener() {
101 @Override
102 public void actionPerformed(ActionEvent e) {
103 NewSetTypeDialog nstd = new NewSetTypeDialog(node, projTree);
104 nstd.setVisible(true);
105 SetType newSetType = nstd.getNewSetType();
106 DatabaseFactory.getDatabaseSingleton().saveSetType(newSetType);
107 projTree.totalRefresh();
108 projTree.selectNode(node.getChildWithEntity(newSetType));
109 }
110 });
111
112 JButton applyButton = new JButton("Apply");
113 applyButton.addActionListener(new ActionListener() {
114 @Override
115 public void actionPerformed(ActionEvent e) {
116 ProjectionModel projection = getEntity();
117 projection.setName(name.getText());
118 projection.setDescription(description.getText());
119 projection.setJumpOffYear(Integer.parseInt(jumpOffYear.getText()));
120 setUserObject(projection.getName());
121 DatabaseFactory.getDatabaseSingleton().saveProjection(projection);
122 projTree.refreshNode(node);
123 }
124 });
125
126 JButton adjustMaxAgeButton = new JButton("Adjust Age Classes");
127 adjustMaxAgeButton.addActionListener(new ActionListener() {
128 @Override
129 public void actionPerformed(ActionEvent e) {
130 adjustMaxAge(getEntity());
131 }
132 });
133
134 List<JButton> buttons = new ArrayList<JButton>();
135 buttons.add(showSubPopsButton);
136 buttons.add(duplicateButton);
137 buttons.add(adjustMaxAgeButton);
138 buttons.add(createSetTypeButton);
139 buttons.add(applyButton);
140 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
141 pspf.sep("General Information");
142 pspf.app(Misc.GUI_LABEL_NAME, name);
143 pspf.app(Misc.GUI_LABEL_DESCRIPTION, description, 2);
144 pspf.app(Misc.GUI_LABEL_JUMP_OFF_YEAR, jumpOffYear);
145 pspf.app("Settypes:", getEntity().getAllSetTypes().size());
146 pspf.app("Descendant Generations:", getEntity().getGenerations() - 1);
147 pspf.app("Years to be predicted:", getEntity().getYears());
148 pspf.app("Number of age classes:", getEntity().getNumberOfAgeClasses());
149 pspf.app("Number of sub-populations:", getEntity().getSubPopulationModel()
150 .getSubPopulations().size());
151 pspf.appPreview(new SubNodeSummary<SetType>(node, projTree, SetType.class));
152 return pspf.constructPanel();
153 }
154
155
156
157
158
159
160
161 protected void adjustMaxAge(ProjectionModel projectionModel) {
162 ProjectionDialog maDialog = new AdjustMaxAgeDialog(projectionModel);
163 maDialog.setVisible(true);
164 }
165 }