use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method keyReleased.
/**
* {@inheritDoc}
*/
public void keyReleased(int keyCode) {
int game = Display.getInstance().getGameAction(keyCode);
if (menuBar.handlesKeycode(keyCode)) {
menuBar.keyReleased(keyCode);
return;
}
// Component focused = focusManager.getFocused();
if (focused != null) {
if (focused.getComponentForm() == this) {
if (focused.isEnabled()) {
focused.keyReleased(keyCode);
}
}
}
// prevent the default action from stealing the behavior from the popup/combo box...
if (game == Display.GAME_FIRE) {
Command defaultCmd = getDefaultCommand();
if (defaultCmd != null) {
defaultCmd.actionPerformed(new ActionEvent(defaultCmd, keyCode));
actionCommandImpl(defaultCmd);
}
}
fireKeyEvent(keyListeners, keyCode);
fireKeyEvent(gameKeyListeners, game);
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method sizeChangedInternal.
/**
* This method is only invoked when the underlying canvas for the form gets
* a size changed event.
* This method will trigger a relayout of the Form.
* This method will get the callback only if this Form is the Current Form
* @param w the new width of the Form
* @param h the new height of the Form
*/
void sizeChangedInternal(int w, int h) {
int oldWidth = getWidth();
int oldHeight = getHeight();
sizeChanged(w, h);
Style formStyle = getStyle();
w = w - (formStyle.getHorizontalMargins());
h = h - (formStyle.getVerticalMargins());
setSize(new Dimension(w, h));
setShouldCalcPreferredSize(true);
doLayout();
focused = getFocused();
if (focused != null) {
Component.setDisableSmoothScrolling(true);
scrollComponentToVisible(focused);
Component.setDisableSmoothScrolling(false);
}
if (oldWidth != w && oldHeight != h) {
if (orientationListener != null) {
orientationListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.OrientationChange));
}
}
if (sizeChangedListener != null) {
sizeChangedListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.SizeChange, w, h));
}
repaint();
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method createStatusBar.
/**
* Subclasses can override this method to control the creation of the status bar component.
* Notice that this method will only be invoked if the paintsTitleBarBool theme constant is true
* which it is on iOS by default
* @return a Component that represents the status bar if the OS requires status bar spacing
*/
protected Component createStatusBar() {
if (getUIManager().isThemeConstant("statusBarScrollsUpBool", true)) {
Button bar = new Button();
bar.setShowEvenIfBlank(true);
bar.setUIID("StatusBar");
bar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Component c = findScrollableChild(getContentPane());
if (c != null) {
c.scrollRectToVisible(new Rectangle(0, 0, 10, 10), c);
}
}
});
return bar;
} else {
Container bar = new Container();
bar.setUIID("StatusBar");
return bar;
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class SideMenuBar method installMenuBar.
/**
* {@inheritDoc}
*/
protected void installMenuBar() {
if (parent.getClientProperty("Menu") != null) {
return;
}
super.installMenuBar();
if (parent instanceof Dialog) {
return;
}
openButton = createOpenButton();
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(null);
}
});
addOpenButton(null, true);
UIManager uim = parent.getUIManager();
final boolean[] hasSideMenus = new boolean[2];
if (uim.isThemeConstant("sideMenuFoldedSwipeBool", true) && parent.getClientProperty("sideMenuFoldedSwipeListeners") == null) {
pointerDragged = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sideSwipePotential && hasSideMenus[0]) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) > x - initialDragX) {
sideSwipePotential = false;
return;
}
evt.consume();
if (x - initialDragX > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = x;
dragActivated = true;
parent.pointerReleased(-1, -1);
openMenu(null, 0, draggedX, false);
initialDragX = 0;
initialDragY = 0;
}
return;
}
if (rightSideSwipePotential && (hasSideMenus[1] || (hasSideMenus[0] && isRTL()))) {
final int x = evt.getX();
final int y = evt.getY();
if (x < 0 || Math.abs(y - initialDragY) > initialDragX - x) {
rightSideSwipePotential = false;
return;
}
evt.consume();
if (initialDragX - x > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = x;
dragActivated = true;
parent.pointerReleased(-1, -1);
if (isRTL()) {
openMenu(null, 0, draggedX, false);
} else {
openMenu(COMMAND_PLACEMENT_VALUE_RIGHT, 0, draggedX, false);
}
initialDragX = 0;
initialDragY = 0;
}
}
if (topSwipePotential) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) < x - initialDragX) {
topSwipePotential = false;
return;
}
evt.consume();
if (initialDragY - y > Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = y;
dragActivated = true;
parent.pointerReleased(-1, -1);
openMenu(COMMAND_PLACEMENT_VALUE_TOP, 0, draggedX, false);
initialDragX = 0;
initialDragY = 0;
}
}
}
};
parent.addPointerDraggedListener(pointerDragged);
pointerPressed = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rightSideSwipePotential = false;
topSwipePotential = false;
sideSwipePotential = false;
if (getCommandCount() == 0) {
return;
}
if (parent.getCommandCount() == 1) {
if (parent.getCommand(0) == parent.getBackCommand()) {
return;
}
}
for (int iter = 0; iter < getCommandCount(); iter++) {
Command c = getCommand(iter);
String p = (String) c.getClientProperty(COMMAND_PLACEMENT_KEY);
if (p == null) {
// has left menu
hasSideMenus[0] = true;
} else if (p.equals(COMMAND_PLACEMENT_VALUE_RIGHT)) {
// has right menu
hasSideMenus[1] = true;
}
}
int displayWidth = Display.getInstance().getDisplayWidth();
if (rightSideButton != null || isRTL()) {
rightSideSwipePotential = !transitionRunning && evt.getX() > displayWidth - displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
}
if (getTitleComponent() instanceof Button) {
topSwipePotential = !transitionRunning && evt.getY() < Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
}
sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
initialDragX = evt.getX();
initialDragY = evt.getY();
if (sideSwipePotential || rightSideSwipePotential || topSwipePotential) {
Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
if (c != null && c.shouldBlockSideSwipe()) {
sideSwipePotential = false;
}
}
}
};
parent.addPointerPressedListener(pointerPressed);
parent.putClientProperty("sideMenuFoldedSwipeListeners", "true");
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class SideMenuBar method validateCommandPlacement.
private void validateCommandPlacement(String placement) {
if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
((BorderLayout) getTitleAreaContainer().getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
if (!(getTitleComponent() instanceof Button)) {
Button b = new Button(parent.getTitle());
b.setUIID("Title");
parent.setTitleComponent(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(COMMAND_PLACEMENT_VALUE_TOP);
}
});
}
return;
}
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
if (rightSideButton != null && rightSideButton.getParent() != null) {
return;
}
rightSideButton = new Button();
rightSideButton.setUIID("MenuButtonRight");
UIManager uim = parent.getUIManager();
Image i = (Image) uim.getThemeImageConstant("rightSideMenuImage");
if (i != null) {
rightSideButton.setIcon(i);
} else {
FontImage.setMaterialIcon(rightSideButton, FontImage.MATERIAL_MENU);
}
Image p = (Image) uim.getThemeImageConstant("rightSideMenuPressImage");
if (p != null) {
rightSideButton.setPressedIcon(p);
}
rightSideButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(COMMAND_PLACEMENT_VALUE_RIGHT);
}
});
Container ta = getTitleAreaContainer();
ta.addComponent(BorderLayout.EAST, rightSideButton);
ta.revalidate();
return;
}
}
Aggregations