1 package fr.ifremer.tutti.ui.swing.util.species;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import fr.ifremer.tutti.type.WeightUnit;
26 import fr.ifremer.tutti.ui.swing.TuttiUIContext;
27 import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler;
28 import jaxx.runtime.JAXXUtil;
29 import jaxx.runtime.SwingUtil;
30 import jaxx.runtime.validator.swing.SwingValidator;
31
32 import javax.swing.JComponent;
33 import java.awt.Component;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
36
37 import static org.nuiton.i18n.I18n.t;
38
39
40
41
42
43
44
45 public class EnterMelagWeightUIHandler extends AbstractTuttiUIHandler<TuttiUIContext, EnterMelagWeightUI> {
46
47 @Override
48 public void onCloseUI() {
49 }
50
51 @Override
52 public SwingValidator<TuttiUIContext> getValidator() {
53 return null;
54 }
55
56 @Override
57 protected JComponent getComponentToFocus() {
58 return null;
59 }
60
61 @Override
62 public void afterInit(EnterMelagWeightUI ui) {
63
64
65 ui.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
66 getConfig().getShortcutClosePopup(), "close");
67
68 ui.addWindowListener(new WindowAdapter() {
69
70 @Override
71 public void windowClosed(WindowEvent e) {
72 Component ui = (Component) e.getSource();
73 JAXXUtil.destroy(ui);
74 }
75 });
76 initUI(ui);
77
78
79 }
80
81 protected Float openAndGetWeightValue(WeightUnit weightUnit) {
82
83 ui.setWeightUnit(weightUnit);
84 SwingUtil.center(getContext().getMainUI(), ui);
85 ui.pack();
86 ui.getEditor().requestFocusInWindow();
87 ui.setVisible(true);
88 Number weight = ui.getEditor().getModel().getNumberValue();
89 return weight == null ? null : weight.floatValue();
90
91 }
92
93 protected String getTile(WeightUnit weightUnit) {
94 return t("tutti.createSpeciesMelag.title", weightUnit.getShortLabel());
95 }
96
97 protected String getMessage(WeightUnit weightUnit) {
98 return t("tutti.createSpeciesMelag.message", weightUnit.getShortLabel());
99 }
100 }