1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.listeners;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.awt.event.FocusEvent;
21 import java.awt.event.FocusListener;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24
25 import javax.swing.JCheckBox;
26
27 import org.xulux.api.gui.IWidget;
28 import org.xulux.gui.GuiUtils;
29 import org.xulux.gui.XuluxListener;
30 import org.xulux.gui.utils.XuluxEventQueue;
31 import org.xulux.guilayer.swing.widgets.Button;
32 import org.xulux.guilayer.swing.widgets.CheckBox;
33 import org.xulux.guilayer.swing.widgets.MenuItem;
34 import org.xulux.guilayer.swing.widgets.RadioButton;
35 import org.xulux.guilayer.swing.widgets.ToggleButton;
36
37
38
39
40
41
42
43
44
45
46 public class PrePostFieldListener extends XuluxListener implements FocusListener, ActionListener, ItemListener {
47
48
49
50
51 public PrePostFieldListener() {
52 super();
53 }
54
55
56
57
58 public PrePostFieldListener(IWidget widget) {
59 super(widget);
60 }
61
62
63
64
65
66 public void focusGained(FocusEvent e) {
67 if (isProcessing()) {
68 return;
69 }
70 if (e.getID() != FocusEvent.FOCUS_GAINED || e.isTemporary()) {
71 return;
72 }
73 XuluxEventQueue q = XuluxEventQueue.getInstance();
74 q.holdEvents(false);
75 started();
76 }
77
78
79
80
81
82 public void focusLost(FocusEvent e) {
83 if (isProcessing()) {
84 return;
85 }
86 if (e.getID() != FocusEvent.FOCUS_LOST || e.isTemporary()) {
87 return;
88 }
89 XuluxEventQueue q = XuluxEventQueue.getInstance();
90
91
92
93 if (!(e.getComponent() instanceof JCheckBox)) {
94 q.holdEvents(true);
95 q.holdAccepted(this);
96 }
97 }
98
99
100
101
102
103
104 public void actionPerformed(ActionEvent e) {
105 if (isProcessing()) {
106 return;
107 }
108 if (widget.isRefreshing()) {
109 return;
110 }
111 XuluxEventQueue q = XuluxEventQueue.getInstance();
112 if (widget instanceof Button || widget instanceof MenuItem) {
113 boolean isCancel = GuiUtils.processCancel(widget);
114 if (isCancel) {
115
116 q.clearAccepted();
117 }
118
119 q.holdEvents(false);
120 }
121 if (accepted(widget)) {
122 completed();
123 }
124 }
125
126
127
128
129
130
131
132
133
134 public void itemStateChanged(ItemEvent e) {
135
136
137
138
139
140 if (widget.isRefreshing()) {
141 return;
142 }
143 boolean refresh = false;
144
145 if (widget instanceof CheckBox || widget instanceof RadioButton || widget instanceof ToggleButton) {
146 if (e.getStateChange() == ItemEvent.SELECTED) {
147 widget.setValue("true");
148 refresh = true;
149
150 } else if (e.getStateChange() == ItemEvent.DESELECTED) {
151 widget.setValue("false");
152 refresh = true;
153 }
154 System.out.println("Checkbox or RadioButton clicked on NyxWidget : " + widget.getName() + " value: " + widget.getValue());
155 }
156 if (refresh) {
157 XuluxEventQueue.getInstance().holdEvents(false);
158 widget.getPart().refreshFields(widget);
159 widget.getPart().updateDependandWidgets(widget);
160 }
161 completed();
162 }
163
164 }