use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class Form method pointerDragged.
@Override
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[0], y[0]);
if (pointerDraggedListeners != null && pointerDraggedListeners.hasListeners()) {
ActionEvent av = new ActionEvent(this, ActionEvent.Type.PointerDrag, x[0], y[0]);
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[0], y[0]);
if (x[0] < actual.getX()) {
// special case for sidemenu
Component cmp = ((BorderLayout) super.getLayout()).getWest();
if (cmp != null) {
cmp = ((Container) cmp).getComponentAt(x[0], y[0]);
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[0], y[0]);
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.layouts.BorderLayout in project CodenameOne by codenameone.
the class Form method pointerReleased.
/**
* {@inheritDoc}
*/
public void pointerReleased(int x, int y) {
rippleMotion = null;
pressedCmp = null;
boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
Container actual = getActualPane(formLayeredPane, x, y);
if (buttonsAwatingRelease != null && buttonsAwatingRelease.size() == 1) {
// special case allowing drag within a button
Component atXY = actual.getComponentAt(x, y);
Component pendingButton = (Component) buttonsAwatingRelease.get(0);
if (atXY == pendingButton) {
buttonsAwatingRelease = null;
if (dragged == pendingButton) {
if (pendingButton.isDragAndDropInitialized()) {
pendingButton.dragFinishedImpl(x, y);
} else {
pendingButton.pointerReleased(x, y);
}
dragged = null;
} else {
pendingButton.pointerReleased(x, y);
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
dragged = null;
} else {
dragged.pointerReleased(x, y);
dragged = null;
}
}
}
return;
}
if (pendingButton instanceof Button) {
Button b = (Button) pendingButton;
int relRadius = b.getReleaseRadius();
if (relRadius > 0 || b.contains(x, y)) {
Rectangle r = new Rectangle(b.getAbsoluteX() - relRadius, b.getAbsoluteY() - relRadius, b.getWidth() + relRadius * 2, b.getHeight() + relRadius * 2);
if (r.contains(x, y)) {
buttonsAwatingRelease = null;
pointerReleased(b.getAbsoluteX() + 1, b.getAbsoluteY() + 1);
return;
}
}
}
}
if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
pointerReleasedListeners.fireActionEvent(ev);
if (ev.isConsumed()) {
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
}
dragged = null;
}
return;
}
}
if (dragStopFlag) {
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
}
dragged = null;
}
dragStopFlag = false;
return;
}
if (dragged == null) {
// soft button.
if (menuBar.contains(x, y)) {
Component cmp = menuBar.getComponentAt(x, y);
if (cmp != null && cmp.isEnabled()) {
cmp.pointerReleased(x, y);
}
return;
}
if (stickyDrag != null) {
stickyDrag.pointerReleased(x, y);
repaint();
} else {
// Container actual = getActualPane();
if (y >= actual.getY() && x >= actual.getX()) {
Component cmp = actual.getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
if (cmp.hasLead) {
Container leadParent;
if (cmp instanceof Container) {
leadParent = ((Container) cmp).getLeadParent();
} else {
leadParent = cmp.getParent().getLeadParent();
}
leadParent.repaint();
if (!isScrollWheeling) {
setFocused(leadParent);
}
cmp.getLeadComponent().pointerReleased(x, y);
} else {
if (cmp.isEnabled()) {
if (!isScrollWheeling && cmp.isFocusable()) {
setFocused(cmp);
}
cmp.pointerReleased(x, y);
}
}
}
} else {
if (y < actual.getY()) {
Component cmp = getTitleArea().getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
cmp.pointerReleased(x, y);
}
} else {
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()) {
if (cmp.hasLead) {
Container leadParent;
if (cmp instanceof Container) {
leadParent = ((Container) cmp).getLeadParent();
} else {
leadParent = cmp.getParent().getLeadParent();
}
leadParent.repaint();
if (!isScrollWheeling) {
setFocused(leadParent);
}
cmp = cmp.getLeadComponent();
cmp.pointerReleased(x, y);
} else {
cmp.pointerReleased(x, y);
}
}
}
}
}
}
} else {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
dragged = null;
} else {
dragged.pointerReleased(x, y);
dragged = null;
}
}
stickyDrag = null;
if (buttonsAwatingRelease != null && !Display.getInstance().isRecursivePointerRelease()) {
for (int iter = 0; iter < buttonsAwatingRelease.size(); iter++) {
Button b = (Button) buttonsAwatingRelease.get(iter);
b.setState(Button.STATE_DEFAULT);
b.repaint();
}
buttonsAwatingRelease = null;
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class InputComponent method constructUI.
void constructUI() {
if (getComponentCount() == 0) {
if (isOnTopMode()) {
lbl.setUIID("FloatingHint");
setLayout(new BorderLayout());
add(BorderLayout.CENTER, getEditor());
add(BorderLayout.NORTH, lbl);
add(BorderLayout.SOUTH, errorMessage);
} else {
setLayout(new BorderLayout());
add(BorderLayout.CENTER, getEditor());
add(BorderLayout.WEST, lbl);
add(BorderLayout.SOUTH, errorMessage);
}
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class MenuBar method updateTitleCommandPlacement.
private void updateTitleCommandPlacement() {
int commandBehavior = getCommandBehavior();
Container t = getTitleAreaContainer();
BorderLayout titleLayout = (BorderLayout) t.getLayout();
if (getParent() == null) {
installMenuBar();
} else {
if (getParent() == getTitleAreaContainer() && commandBehavior != Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT && commandBehavior != Display.COMMAND_BEHAVIOR_ICS) {
getParent().removeComponent(this);
installMenuBar();
}
}
if (!(parent instanceof Dialog)) {
if ((commandBehavior == Display.COMMAND_BEHAVIOR_ICS || commandBehavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) && parent.getTitle() != null && parent.getTitle().length() > 0) {
synchronizeCommandsWithButtonsInBackbutton();
return;
} else {
if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) {
if (getParent() != null) {
if (getParent() == getTitleAreaContainer()) {
return;
}
getParent().removeComponent(this);
}
// getTitleAreaContainer().addComponent(BorderLayout.EAST, findRightTitleContainer());
return;
}
}
}
if (t.getComponentCount() - componentCountOffset(t) > 1) {
if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
} else {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
}
Component l = getTitleComponent();
if (l.getParent() != null) {
l.getParent().removeComponent(l);
}
t.removeAll();
t.addComponent(BorderLayout.CENTER, l);
initTitleBarStatus();
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class MenuBar method showMenu.
/**
* This method shows the menu on the Form.
* The method creates a Dialog with the commands and calls showMenuDialog.
* The method blocks until the user dispose the dialog.
*/
public void showMenu() {
final Dialog d = new Dialog("Menu", "");
d.setDisposeWhenPointerOutOfBounds(true);
d.setMenu(true);
d.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
d.dispose();
}
});
d.setTransitionInAnimator(transitionIn);
d.setTransitionOutAnimator(transitionOut);
d.setLayout(new BorderLayout());
d.setScrollable(false);
// calling parent.createCommandComponent is done only for backward
// compatability reasons, in the next version this call be replaced with
// calling directly to createCommandComponent
((Form) d).getMenuBar().commandList = createCommandComponent(commands);
if (menuCellRenderer != null && ((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).setListCellRenderer(menuCellRenderer);
}
d.getContentPane().getStyle().setMargin(0, 0, 0, 0);
d.addComponent(BorderLayout.CENTER, ((Form) d).getMenuBar().commandList);
if (thirdSoftButton) {
d.addCommand(selectMenuItem);
d.addCommand(cancelMenuItem);
} else {
d.addCommand(cancelMenuItem);
if (soft.length > 1) {
d.addCommand(selectMenuItem);
}
}
d.setClearCommand(cancelMenuItem);
d.setBackCommand(cancelMenuItem);
if (((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).addActionListener(((Form) d).getMenuBar());
}
menuDisplaying = true;
Command result = showMenuDialog(d);
menuDisplaying = false;
if (result != cancelMenuItem) {
Command c = null;
if (result == selectMenuItem) {
c = getComponentSelectedCommand(((Form) d).getMenuBar().commandList);
if (c != null) {
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
c.actionPerformed(e);
}
} else {
c = result;
// a touch menu will always send its commands on its own...
if (!isTouchMenus()) {
c = result;
if (c != null) {
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
c.actionPerformed(e);
}
}
}
// menu item was handled internally in a touch interface that is not a touch menu
if (c != null) {
parent.actionCommandImpl(c);
}
}
if (((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).removeActionListener(((Form) d).getMenuBar());
}
Form upcoming = Display.getInstance().getCurrentUpcoming();
if (upcoming == parent) {
d.disposeImpl();
} else {
parent.tint = (upcoming instanceof Dialog);
}
}
Aggregations