use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class MenuBar method keyReleased.
/**
* {@inheritDoc}
*/
public void keyReleased(int keyCode) {
int commandBehavior = getCommandBehavior();
if (commandBehavior >= Display.COMMAND_BEHAVIOR_BUTTON_BAR && keyCode != backSK && keyCode != clearSK && keyCode != backspaceSK) {
return;
}
if (getCommandCount() > 0) {
int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
if (softkeyCount < 2 && keyCode == leftSK) {
if (commandList != null) {
Container parent = commandList.getParent();
while (parent != null) {
if (parent instanceof Dialog && ((Dialog) parent).isMenu()) {
return;
}
parent = parent.getParent();
}
}
showMenu();
return;
} else {
if (keyCode == leftSK) {
if (left != null) {
left.released();
}
return;
} else {
// it might be a back command...
if ((keyCode == rightSK || keyCode == rightSK2)) {
if (right != null) {
right.released();
}
return;
} else {
if (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) {
main.released();
return;
}
}
}
}
}
// allows a back/clear command to occur regardless of whether the
// command was added to the form
Command c = null;
if (keyCode == backSK) {
// the back command should be invoked
c = parent.getBackCommand();
if (c == null && minimizeOnBack) {
Display.getInstance().minimizeApplication();
return;
}
} else {
if (keyCode == clearSK || keyCode == backspaceSK) {
c = getClearCommand();
}
}
if (c != null) {
ActionEvent ev = new ActionEvent(c, keyCode);
c.actionPerformed(ev);
if (!ev.isConsumed()) {
parent.actionCommandImpl(c);
}
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Toolbar method constructOnTopSideMenu.
private void constructOnTopSideMenu() {
if (sidemenuDialog == null) {
permanentSideMenuContainer = constructSideNavigationComponent();
final Form parent = getComponentForm();
parent.addPointerPressedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
if (sidemenuDialog.isShowing()) {
if (evt.getX() > sidemenuDialog.getWidth()) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
closeSideMenu();
evt.consume();
} else {
if (evt.getX() + Display.getInstance().convertToPixels(8) > sidemenuDialog.getWidth()) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
} else {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
}
if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
evt.consume();
}
}
} else {
int displayWidth = Display.getInstance().getDisplayWidth();
final int sensitiveSection = displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
if (evt.getX() < sensitiveSection) {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
evt.consume();
} else {
parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
permanentSideMenuContainer.pointerPressed(evt.getX(), evt.getY());
}
}
}
});
parent.addPointerDraggedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuCharged");
if (b != null && b.booleanValue()) {
parent.putClientProperty("cn1$sidemenuActivated", Boolean.TRUE);
showOnTopSidemenu(evt.getX(), false);
evt.consume();
} else {
if (sidemenuDialog.isShowing()) {
permanentSideMenuContainer.pointerDragged(evt.getX(), evt.getY());
evt.consume();
}
}
}
});
parent.addPointerReleasedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (Display.getInstance().getImplementation().isScrollWheeling()) {
return;
}
Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuActivated");
if (b != null && b.booleanValue()) {
parent.putClientProperty("cn1$sidemenuActivated", null);
if (evt.getX() < parent.getWidth() / 4) {
closeSideMenu();
} else {
showOnTopSidemenu(-1, true);
}
evt.consume();
} else {
if (sidemenuDialog.isShowing()) {
if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
evt.consume();
}
permanentSideMenuContainer.pointerReleased(evt.getX(), evt.getY());
}
}
}
});
sidemenuDialog = new InteractionDialog(new BorderLayout());
sidemenuDialog.setFormMode(true);
sidemenuDialog.setUIID("Container");
sidemenuDialog.setDialogUIID("Container");
sidemenuDialog.getTitleComponent().remove();
sidemenuDialog.add(BorderLayout.CENTER, permanentSideMenuContainer);
if (sidemenuSouthComponent != null) {
sidemenuDialog.add(BorderLayout.SOUTH, sidemenuSouthComponent);
}
float size = 4.5f;
try {
size = Float.parseFloat(getUIManager().getThemeConstant("menuImageSize", "4.5"));
} catch (Throwable t) {
Log.e(t);
}
if (!parent.getUIManager().isThemeConstant("hideLeftSideMenuBool", false)) {
Image i = (Image) parent.getUIManager().getThemeImageConstant("sideMenuImage");
if (i != null) {
Command cmd = addCommandToLeftBar("", i, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sidemenuDialog.isShowing()) {
closeSideMenu();
return;
}
showOnTopSidemenu(-1, false);
}
});
Image p = (Image) parent.getUIManager().getThemeImageConstant("sideMenuPressImage");
if (p != null) {
findCommandComponent(cmd).setPressedIcon(p);
}
} else {
addMaterialCommandToLeftBar("", FontImage.MATERIAL_MENU, size, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sidemenuDialog.isShowing()) {
closeSideMenu();
return;
}
showOnTopSidemenu(-1, false);
}
});
}
}
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class URLImage method fetch.
/**
* Images are normally fetched from storage or network only as needed,
* however if the download must start before the image is drawn this method
* can be invoked. Notice that "immediately" doesn't mean synchronously, it just
* means that the image will be added to the queue right away but probably won't be
* available by the time the method completes.
*/
public void fetch() {
if (fetching || imageData != null) {
return;
}
fetching = true;
try {
locked = super.isLocked();
if (storageFile != null) {
if (Storage.getInstance().exists(storageFile)) {
super.unlock();
imageData = new byte[Storage.getInstance().entrySize(storageFile)];
InputStream is = Storage.getInstance().createInputStream(storageFile);
Util.readFully(is, imageData);
resetCache();
fetching = false;
repaintImage = true;
return;
}
if (adapter != null) {
Util.downloadImageToStorage(url, storageFile + IMAGE_SUFFIX, new SuccessCallback<Image>() {
public void onSucess(Image value) {
DownloadCompleted onComplete = new DownloadCompleted();
onComplete.setSourceImage(value);
onComplete.actionPerformed(new ActionEvent(value));
}
});
} else {
Util.downloadImageToStorage(url, storageFile, new SuccessCallback<Image>() {
public void onSucess(Image value) {
DownloadCompleted onComplete = new DownloadCompleted();
onComplete.setSourceImage(value);
onComplete.actionPerformed(new ActionEvent(value));
}
});
}
} else {
if (FileSystemStorage.getInstance().exists(fileSystemFile)) {
super.unlock();
imageData = new byte[(int) FileSystemStorage.getInstance().getLength(fileSystemFile)];
InputStream is = FileSystemStorage.getInstance().openInputStream(fileSystemFile);
Util.readFully(is, imageData);
resetCache();
fetching = false;
repaintImage = true;
return;
}
if (adapter != null) {
Util.downloadImageToFileSystem(url, fileSystemFile + IMAGE_SUFFIX, new SuccessCallback<Image>() {
public void onSucess(Image value) {
DownloadCompleted onComplete = new DownloadCompleted();
onComplete.setSourceImage(value);
onComplete.actionPerformed(new ActionEvent(value));
}
});
} else {
Util.downloadImageToFileSystem(url, fileSystemFile, new SuccessCallback<Image>() {
public void onSucess(Image value) {
DownloadCompleted onComplete = new DownloadCompleted();
onComplete.setSourceImage(value);
onComplete.actionPerformed(new ActionEvent(value));
}
});
}
}
} catch (IOException ioErr) {
throw new RuntimeException(ioErr.toString());
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method pointerDragged.
/**
* {@inheritDoc}
*/
public void pointerDragged(int x, int y) {
// disable the drag stop flag if we are dragging again
boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
if (dragStopFlag) {
pointerPressed(x, y);
}
autoRelease(x, y);
if (pointerDraggedListeners != null) {
ActionEvent av = new ActionEvent(this, ActionEvent.Type.PointerDrag, x, y);
pointerDraggedListeners.fireActionEvent(av);
if (av.isConsumed()) {
return;
}
}
rippleMotion = null;
if (dragged != null) {
dragged.pointerDragged(x, y);
return;
}
if (pressedCmp != null && pressedCmp.isStickyDrag()) {
stickyDrag = pressedCmp;
}
if (stickyDrag != null) {
stickyDrag.pointerDragged(x, y);
repaint();
return;
}
Container actual = getActualPane(formLayeredPane, x, y);
if (x < actual.getX()) {
// special case for sidemenu
Component cmp = ((BorderLayout) super.getLayout()).getWest();
if (cmp != null) {
cmp = ((Container) cmp).getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
cmp.pointerDragged(x, y);
cmp.repaint();
if (cmp == pressedCmp && cmp.isStickyDrag()) {
stickyDrag = cmp;
}
}
}
return;
}
Component cmp = actual.getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null) {
if (!isScrollWheeling && cmp.isFocusable() && cmp.isEnabled()) {
setFocused(cmp);
}
cmp.pointerDragged(x, y);
cmp.repaint();
if (cmp == pressedCmp && cmp.isStickyDrag()) {
stickyDrag = cmp;
}
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method onShowCompletedImpl.
void onShowCompletedImpl() {
setLightweightMode(false);
onShowCompleted();
if (showListener != null) {
showListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.Show));
}
if (editOnShow != null) {
editOnShow.startEditingAsync();
}
}
Aggregations