aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui/CheckBox.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-04-11 17:32:47 +0300
committerArtur Signell <artur@vaadin.com>2012-04-12 09:58:13 +0300
commit8b3e927419e61ff2eee43a4dcb4b832a3e22746b (patch)
treec09a7e04d8cf2cf2c2cf6e524ee330d36ced8033 /src/com/vaadin/ui/CheckBox.java
parent5689234f5db140a4bedd7636c4b0635126b27d61 (diff)
downloadvaadin-framework-8b3e927419e61ff2eee43a4dcb4b832a3e22746b.tar.gz
vaadin-framework-8b3e927419e61ff2eee43a4dcb4b832a3e22746b.zip
Button, NativeButton and CheckBox are no longer Vaadin6Components
Added FocusAndBlurServerRpc for sending focus and blur events to any component.
Diffstat (limited to 'src/com/vaadin/ui/CheckBox.java')
-rw-r--r--src/com/vaadin/ui/CheckBox.java75
1 files changed, 43 insertions, 32 deletions
diff --git a/src/com/vaadin/ui/CheckBox.java b/src/com/vaadin/ui/CheckBox.java
index e53bb5a3b7..e98cf3638f 100644
--- a/src/com/vaadin/ui/CheckBox.java
+++ b/src/com/vaadin/ui/CheckBox.java
@@ -4,24 +4,50 @@
package com.vaadin.ui;
-import java.util.Map;
-
import com.vaadin.data.Property;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Vaadin6Component;
-import com.vaadin.terminal.gwt.client.ui.VCheckBox;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
+import com.vaadin.terminal.gwt.client.ui.CheckBoxConnector.CheckBoxServerRpc;
+import com.vaadin.terminal.gwt.client.ui.CheckBoxConnector.CheckBoxState;
+
+public class CheckBox extends AbstractField<Boolean> {
+
+ private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {
+
+ public void setChecked(boolean checked,
+ MouseEventDetails mouseEventDetails) {
+ if (isReadOnly()) {
+ return;
+ }
+
+ final Boolean oldValue = getValue();
+ final Boolean newValue = checked;
+
+ if (!newValue.equals(oldValue)) {
+ // The event is only sent if the switch state is changed
+ setValue(newValue);
+ }
+
+ }
+ };
+
+ FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(this) {
+ @Override
+ protected void fireEvent(Event event) {
+ CheckBox.this.fireEvent(event);
+ }
+ };
-public class CheckBox extends AbstractField<Boolean> implements
- Vaadin6Component {
/**
* Creates a new checkbox.
*/
public CheckBox() {
+ registerRpc(rpc);
+ registerRpc(focusBlurRpc);
setValue(Boolean.FALSE);
}
@@ -66,32 +92,18 @@ public class CheckBox extends AbstractField<Boolean> implements
return Boolean.class;
}
- public void paintContent(PaintTarget target) throws PaintException {
- Boolean value = getValue();
- boolean booleanValue = (value != null) ? value : false;
- target.addVariable(this, VCheckBox.VARIABLE_STATE, booleanValue);
+ @Override
+ public CheckBoxState getState() {
+ return (CheckBoxState) super.getState();
}
- public void changeVariables(Object source, Map<String, Object> variables) {
-
- if (!isReadOnly() && variables.containsKey(VCheckBox.VARIABLE_STATE)) {
- // Gets the new and old states
- final Boolean newValue = (Boolean) variables
- .get(VCheckBox.VARIABLE_STATE);
- final Boolean oldValue = getValue();
-
- // The event is only sent if the switch state is changed
- if (newValue != null && !newValue.equals(oldValue)) {
- setValue(newValue);
- }
- }
-
- if (variables.containsKey(FocusEvent.EVENT_ID)) {
- fireEvent(new FocusEvent(this));
- }
- if (variables.containsKey(BlurEvent.EVENT_ID)) {
- fireEvent(new BlurEvent(this));
+ @Override
+ protected void setInternalValue(Boolean newValue) {
+ super.setInternalValue(newValue);
+ if (newValue == null) {
+ newValue = false;
}
+ getState().setChecked(newValue);
}
public void addListener(BlurListener listener) {
@@ -110,7 +122,6 @@ public class CheckBox extends AbstractField<Boolean> implements
public void removeListener(FocusListener listener) {
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
-
}
/**