use of com.codename1.ui.events.DataChangedListener in project CodenameOne by codenameone.
the class HTMLEventsListener method deregisterAll.
/**
* Deregisters all the listeners, happens before a new page is loaded
*/
void deregisterAll() {
for (Enumeration e = comps.keys(); e.hasMoreElements(); ) {
Component cmp = (Component) e.nextElement();
cmp.removeFocusListener(this);
if (cmp instanceof Button) {
// catches Button, CheckBox, RadioButton
((Button) cmp).removeActionListener(this);
} else if (cmp instanceof List) {
// catches ComboBox
((List) cmp).removeSelectionListener((SelectionListener) listeners.get(cmp));
} else if (cmp instanceof TextArea) {
((TextArea) cmp).removeActionListener(this);
if (cmp instanceof TextField) {
((TextField) cmp).removeDataChangeListener((DataChangedListener) listeners.get(cmp));
}
}
}
comps = new Hashtable();
listeners = new Hashtable();
}
use of com.codename1.ui.events.DataChangedListener in project CodenameOne by codenameone.
the class HTMLEventsListener method registerComponent.
/**
* Registeres the specified component/element duo to listen to all available events
*
* @param cmp The actual component
* @param element The element representing the component
*/
void registerComponent(final Component cmp, final HTMLElement element) {
comps.put(cmp, element);
cmp.addFocusListener(this);
if (cmp instanceof Button) {
// catches Button, CheckBox, RadioButton
((Button) cmp).addActionListener(this);
} else if (cmp instanceof List) {
// catches ComboBox
final List list = (List) cmp;
list.addActionListener(this);
SelectionListener sl = new // We create a listener and not listen ourself since the listener's method does not pass the event origin, so we need to make one listener per component
SelectionListener() {
public void selectionChanged(int oldSelected, int newSelected) {
if (htmlC.getHTMLCallback() != null) {
htmlC.getHTMLCallback().selectionChanged(oldSelected, newSelected, htmlC, list, element);
}
}
};
list.addSelectionListener(sl);
listeners.put(cmp, sl);
} else if (cmp instanceof TextArea) {
((TextArea) cmp).addActionListener(this);
if (cmp instanceof TextField) {
final TextField tf = (TextField) cmp;
DataChangedListener dcl = new // We create a listener and not listen ourself since the listener's method does not pass the event origin, so we need to make one listener per component
DataChangedListener() {
public void dataChanged(int type, int index) {
element.setAttributeById(HTMLElement.ATTR_VALUE, tf.getText());
if (htmlC.getHTMLCallback() != null) {
htmlC.getHTMLCallback().dataChanged(type, index, htmlC, tf, element);
}
}
};
tf.addDataChangedListener(dcl);
listeners.put(cmp, dcl);
}
}
}
use of com.codename1.ui.events.DataChangedListener in project CodenameOne by codenameone.
the class ImageViewer method setImageList.
/**
* By providing this optional list of images you can allows swiping between multiple images
*
* @param model a list of images
*/
public void setImageList(ListModel<Image> model) {
if (model == null || model.getSize() == 0) {
return;
}
if (image == null) {
image = model.getItemAt(0);
}
if (swipeableImages != null) {
swipeableImages.removeDataChangedListener(listListener);
swipeableImages.removeSelectionListener((SelectionListener) listListener);
model.addDataChangedListener(listListener);
model.addSelectionListener((SelectionListener) listListener);
} else {
class Listener implements SelectionListener, DataChangedListener {
public void selectionChanged(int oldSelected, int newSelected) {
if (selectLock) {
return;
}
if (swipeableImages.getSize() > 0 && newSelected > -1 && newSelected < swipeableImages.getSize()) {
setImage(swipeableImages.getItemAt(newSelected));
}
}
public void dataChanged(int type, int index) {
if (swipeableImages.getSize() > 0 && swipeableImages.getSelectedIndex() > -1 && swipeableImages.getSelectedIndex() < swipeableImages.getSize()) {
setImage(swipeableImages.getItemAt(swipeableImages.getSelectedIndex()));
}
}
}
listListener = new Listener();
model.addDataChangedListener(listListener);
model.addSelectionListener((SelectionListener) listListener);
}
this.swipeableImages = model;
}
Aggregations