use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Component method pointerReleased.
/**
* If this Component is focused, the pointer released event
* will call this method
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
*/
public void pointerReleased(int x, int y) {
if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
pointerReleasedListeners.fireActionEvent(ev);
if (ev.isConsumed()) {
return;
}
}
pointerReleaseImpl(x, y);
scrollOpacity = 0xff;
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Component method pointerPressed.
/**
* If this Component is focused, the pointer pressed event
* will call this method
*
* @param x the pointer x coordinate
* @param y the pointer y coordinate
*/
public void pointerPressed(int x, int y) {
dragActivated = false;
if (pointerPressedListeners != null && pointerPressedListeners.hasListeners()) {
pointerPressedListeners.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
}
clearDrag();
if (isDragAndDropOperation(x, y)) {
int restore = Display.getInstance().getDragStartPercentage();
if (restore > 1) {
restoreDragPercentage = restore;
}
Display.getInstance().setDragStartPercentage(1);
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Component method dragFinishedImpl.
void dragFinishedImpl(int x, int y) {
if (dragAndDropInitialized && dragActivated) {
Form p = getComponentForm();
if (p == null) {
// The component was removed from the form during the drag
dragActivated = false;
dragAndDropInitialized = false;
setVisible(true);
dragImage = null;
dropTargetComponent = null;
return;
}
p.setDraggedComponent(null);
Component dropTo = findDropTarget(this, x, y);
if (dropTargetComponent != dropTo) {
if (dropTargetComponent != null) {
dropTargetComponent.dragExit(this);
}
dropTargetComponent = dropTo;
if (dropTargetComponent != null) {
dropTargetComponent.dragEnter(this);
}
}
if (dropTargetComponent != null) {
p.repaint(x, y, getWidth(), getHeight());
getParent().scrollRectToVisible(getX(), getY(), getWidth(), getHeight(), getParent());
if (dropListener != null) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerDrag, dropTargetComponent, x, y);
dropListener.fireActionEvent(ev);
if (!ev.isConsumed()) {
dropTargetComponent.drop(this, x, y);
}
} else {
dropTargetComponent.drop(this, x, y);
}
} else {
if (dragOverListener != null) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerDrag, null, x, y);
dragOverListener.fireActionEvent(ev);
}
p.repaint();
}
setVisible(true);
dragImage = null;
dropTargetComponent = null;
}
if (getUIManager().getLookAndFeel().isFadeScrollBar() && isScrollable()) {
Form frm = getComponentForm();
if (frm != null) {
frm.registerAnimatedInternal(this);
}
}
dragActivated = false;
dragAndDropInitialized = false;
if (dragFinishedListeners != null && dragFinishedListeners.hasListeners()) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.DragFinished, x, y);
dragFinishedListeners.fireActionEvent(ev);
if (ev.isConsumed()) {
return;
}
}
dragFinished(x, y);
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class AutoCompleteTextField method addPopup.
private void addPopup() {
final Form f = getComponentForm();
popup.removeAll();
popup.setVisible(false);
popup.setEnabled(false);
filter(getText());
final com.codename1.ui.List l = new com.codename1.ui.List(getSuggestionModel());
if (getMinimumElementsShownInPopup() > 0) {
l.setMinElementHeight(getMinimumElementsShownInPopup());
}
l.setScrollToSelected(false);
l.setItemGap(0);
for (ActionListener al : listeners) {
l.addActionListener(al);
}
if (completionRenderer == null) {
((DefaultListCellRenderer<String>) l.getRenderer()).setShowNumbers(false);
} else {
l.setRenderer(completionRenderer);
}
l.setUIID("AutoCompleteList");
l.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
pickedText = (String) l.getSelectedItem();
setParentText(pickedText);
fireActionEvent();
// relaunch text editing if we are still editing
if (Display.getInstance().isTextEditing(AutoCompleteTextField.this)) {
Display.getInstance().editString(AutoCompleteTextField.this, getMaxSize(), getConstraint(), (String) l.getSelectedItem());
}
popup.setVisible(false);
popup.setEnabled(false);
f.repaint();
}
});
byte[] units = popup.getStyle().getMarginUnit();
if (units != null) {
units[Component.LEFT] = Style.UNIT_TYPE_PIXELS;
units[Component.TOP] = Style.UNIT_TYPE_PIXELS;
popup.getAllStyles().setMarginUnit(units);
}
popup.getAllStyles().setMargin(LEFT, Math.max(0, getAbsoluteX()));
int popupHeight = calcPopuupHeight(l);
popup.setPreferredW(getWidth());
popup.setHeight(popupHeight);
popup.setWidth(getWidth());
popup.addComponent(l);
popup.layoutContainer();
// block the reflow of this popup, which can cause painting problems
dontCalcSize = true;
if (f != null) {
if (popup.getParent() == null) {
Container lay = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);
lay.setLayout(new LayeredLayout());
Container wrapper = new Container();
wrapper.add(popup);
lay.addComponent(wrapper);
}
f.revalidate();
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Button method pointerReleased.
/**
* {@inheritDoc}
*/
public void pointerReleased(int x, int y) {
if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
pointerReleasedListeners.fireActionEvent(ev);
if (ev.isConsumed()) {
return;
}
}
Form f = getComponentForm();
// might happen when programmatically triggering press
if (f != null) {
if (f.buttonsAwatingRelease != null) {
f.buttonsAwatingRelease.remove(this);
}
}
// button shouldn't fire an event when a pointer is dragged into it
if (state == STATE_PRESSED) {
released(x, y);
}
if (restoreDragPercentage > -1) {
Display.getInstance().setDragStartPercentage(restoreDragPercentage);
}
}
Aggregations