Revision: 2733
http://sourceforge.net/p/swingme/code/2733
Author: yuranet
Date: 2023-04-26 12:14:15 +0000 (Wed, 26 Apr 2023)
Log Message:
-----------
any component can easily detect right click/long press
Modified Paths:
--------------
SwingME/src/net/yura/mobile/gui/DesktopPane.java
SwingME/src/net/yura/mobile/gui/KeyEvent.java
SwingME/src/net/yura/mobile/gui/components/Button.java
SwingME/src/net/yura/mobile/gui/components/Component.java
SwingME/src/net/yura/mobile/gui/components/FrameTitlePane.java
SwingME/src/net/yura/mobile/gui/components/ImageView.java
SwingME/src/net/yura/mobile/gui/components/List.java
SwingME/src/net/yura/mobile/gui/components/Menu.java
SwingME/src/net/yura/mobile/gui/components/Slider.java
SwingME/src/net/yura/mobile/gui/components/Spinner.java
SwingME/src/net/yura/mobile/gui/components/TextComponent.java
SwingME/src/net/yura/mobile/gui/components/Window.java
Modified: SwingME/src/net/yura/mobile/gui/DesktopPane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/DesktopPane.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/DesktopPane.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -1350,9 +1350,23 @@
//==== pointer commands ====================================================
//\xB0``\xB0\xBA\xA4\xF8,\xB8\xB8,\xF8\xA4\xBA\xB0``\xB0\xBA\xA4\xF8,\xB8\xB8,\xF8\xA4\xBA\xB0``\xB0\xBA\xA4\xF8,\xB8\xB8,\xF8\xA4\xBA\xB0``\xB0\xBA\xA4\xF8,\xB8\xB8,\xF8\xA4\xBA\xB0``\xB0\xBA\xA4\xF8,\xB8\xB8,\xF8\xA4\xBA\xB0``\xB0
- public static final int DRAGGED = 0;
+ /**
+ * @see java.awt.event.MouseEvent#MOUSE_PRESSED
+ */
public static final int PRESSED = 1;
+ /**
+ * @see java.awt.event.MouseEvent#MOUSE_DRAGGED
+ */
+ public static final int DRAGGED = 6;
+ /**
+ * @see java.awt.event.MouseEvent#MOUSE_RELEASED
+ */
public static final int RELEASED = 2;
+ /**
+ * This is used the same way as android, when scrolling has taken over and
+ * we want to tell the component to cancel whatever it was going to do.
+ * @see android.view.MotionEvent#ACTION_CANCEL
+ */
public static final int CANCEL = 3;
private Component pointerComponent;
@@ -1397,6 +1411,10 @@
return Math.abs(oldx - x) <= inaccuracy;
}
+ /**
+ * On ME4SE right-click button is kept down during mouse events
+ * @see javax.microedition.lcdui.ScmCanvas#mouseReleased(int, int, int, int)
+ */
private void pointerEvent(int type, int x, int y) {
//System.out.println("SM pointerEvent "+pointerComponent+" point="+type+" "+x+" "+y);
@@ -1435,7 +1453,7 @@
}
// check its dragged more then 5px
else if (!(isAccurate(pointerFirstX, x, inaccuracy) && isAccurate(pointerFirstY, y, inaccuracy))) {
- pointerComponent.processMouseEvent(CANCEL, x, y, keypad);
+ pointerComponent.processMouseEvent(CANCEL, 0, 0, keypad);
pointerComponent = null;
if (DEFAULT_NO_FOCUS) {
@@ -1444,23 +1462,18 @@
}
}
+ boolean simulateRightClick = false;
// When pointer released, reset pointer Component/ScrollPane
if (type == RELEASED) {
-
long time = System.currentTimeMillis();
// TODO we need a better way to decide when to open a popup that does not wait for the user to let go
- if (keypad.isDownKey(KeyEvent.KEY_RIGHT_CLICK) || (time - pointerFristTime > 1000 && isAccurate(pointerFirstX, x, inaccuracy) && isAccurate(pointerFirstY, y, inaccuracy))) {
- if (pointerComponent!=null) {
- Window popup = pointerComponent.getPopupMenu();
- if (popup!=null && !popup.isVisible()) {
- popup.show(pointerComponent, x, y);
-
- // as we have triggered a popup menu, we want to send this as a cancel to the component
- type = CANCEL;
- }
+ if (!keypad.isDownKey(KeyEvent.KEY_RIGHT_CLICK) && (time - pointerFristTime > 1000 && isAccurate(pointerFirstX, x, inaccuracy) && isAccurate(pointerFirstY, y, inaccuracy))) {
+ if (pointerComponent != null) {
+ // if this is a long press, simulate a right click for the component
+ keypad.keyPressed(KeyEvent.KEY_RIGHT_CLICK);
+ simulateRightClick = true;
}
}
-
}
// Handle events for pointer component
@@ -1471,6 +1484,10 @@
pc.processMouseEvent(type, pcX, pcY, keypad);
}
+ if (simulateRightClick) {
+ keypad.keyReleased(KeyEvent.KEY_RIGHT_CLICK);
+ }
+
// Handle events for pointer ScrollPane
if (pointerScrollPane != null) {
if (type == PRESSED || type == RELEASED ||
@@ -1492,7 +1509,7 @@
}
//#enddebug
- if (type == RELEASED || type==CANCEL) {
+ if (type == RELEASED) {
if (DEFAULT_NO_FOCUS) {
currentWindow.setNothingFocused();
@@ -1500,20 +1517,17 @@
pointerScrollPane = null;
pointerComponent = null;
-
}
+ }
+ if (type == PRESSED || type == RELEASED) {
+ showHideToolTip(type == PRESSED, pointerComponent);
}
-
- // TODO: if dragged by only a little bit, should not hide the tooltip
- showHideToolTip(type == PRESSED,pointerComponent);
-
}
catch (Throwable th) {
//#debug warn
Logger.warn("Exception in pointerEvent", th);
}
-
}
public void toast(String text) {
@@ -1526,7 +1540,7 @@
animateComponent(toast);
}
- private void showHideToolTip(boolean show,Component comp) {
+ private void showHideToolTip(boolean show, Component comp) {
// if a tooltip should be setup
if (show && comp != null && comp.getToolTipText() != null) {
@@ -1557,7 +1571,6 @@
tooltip.setLocation(x, y);
animateComponent(tooltip);
-
}
else if (tooltip != null) {
// this will never be null unless this method is called
@@ -1571,8 +1584,6 @@
}
}
}
-
-
}
public void setIndicatorText(String txt) {
@@ -1719,7 +1730,6 @@
sizeChangedImpl();
repaint();
-
}
protected void hideNotify() {
Modified: SwingME/src/net/yura/mobile/gui/KeyEvent.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/KeyEvent.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/KeyEvent.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -92,6 +92,7 @@
/**
* MS4SE Right Click Key
+ * @see java.awt.event.MouseEvent#isPopupTrigger()
*/
public static final int KEY_RIGHT_CLICK = -51;
Modified: SwingME/src/net/yura/mobile/gui/components/Button.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Button.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Button.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -256,24 +256,26 @@
selected = true;
repaint();
}
- else if (x>=cx && x<=(cx+cw) && y>=cy && y<=(cy+ch)) {
+ else if (x>=cx && x<=(cx+cw) && y>=cy && y<=(cy+ch)) { // inside component
if (type == DesktopPane.DRAGGED && !selected) {
selected = true;
repaint();
}
+ else if (type == DesktopPane.CANCEL || isPopupTrigger(type, keys)) { // user scrolls or popup menu open
+ selected = oldState;
+ repaint();
+ }
else if (type == DesktopPane.RELEASED) {
selected = oldState;
fireActionPerformed();
repaint();
}
-
}
- else if (selected) { // && type == DesktopPane.DRAGGED
+ else if (selected) { // && type == DesktopPane.DRAGGED outside component
selected = oldState;
repaint();
}
-
}
/**
@@ -291,9 +293,8 @@
}
if (al!=null) {
- al.actionPerformed((actionCommand!=null)?actionCommand:getText());
+ al.actionPerformed(actionCommand != null ? actionCommand : getText());
}
-
}
/**
Modified: SwingME/src/net/yura/mobile/gui/components/Component.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Component.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Component.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -218,7 +218,7 @@
*/
public boolean isFocusable() {
if (!isVisible()) return false;
- return focusable;
+ return focusable;
}
/**
@@ -491,16 +491,32 @@
}
/**
+ * @return true if the event has been consumed and should not trigger any more actions, usually when popupmenu is triggered.
* @see java.awt.Component#processMouseEvent(java.awt.event.MouseEvent) Component.processMouseEvent
+ * @see awt.event.InputEvent#consume()
*/
- public void processMouseEvent(int type, int x, int y, KeyEvent keys) {
+ public void processMouseEvent(int type, int x, int y, KeyEvent buttons) {
+
+ if (isPopupTrigger(type, buttons)) {
+ Window popup = getPopupMenu();
+ if (popup != null && !popup.isVisible()) {
+ // no action listener is called, if you want to customise menu, override getPopupMenu()
+ popup.show(this, x + getXOnScreen(), y + getYOnScreen());
+
+ // if we opened a popup menu, we do not want to open any parent popup menu
+ return;
+ }
+ }
+
if (focusable) {
if (type == DesktopPane.PRESSED) {
- if(!isFocusOwner() && isVisible()) { requestFocusInWindow(); }
+ if(!isFocusOwner() && isVisible()) {
+ requestFocusInWindow();
+ }
}
}
- else if (parent!=null) {
- parent.processMouseEvent(type,x+posX,y+posY, keys);
+ else if (parent != null) {
+ parent.processMouseEvent(type, posX + x, posY + y, buttons);
}
//else {
// owner.pointerEvent(type,x+getXInWindow(),y+getYInWindow());
@@ -507,6 +523,13 @@
//}
}
+ /**
+ * @see java.awt.event.MouseEvent#isPopupTrigger()
+ */
+ protected boolean isPopupTrigger(int type, KeyEvent buttons) {
+ return type == DesktopPane.RELEASED && buttons.isDownKey(KeyEvent.KEY_RIGHT_CLICK) && popup != null;
+ }
+
public void processMultitouchEvent(int[] type, int[] x, int[] y) {
if (parent!=null) {
for (int c=0;c<type.length;c++) {
@@ -517,8 +540,11 @@
}
}
+ /**
+ * @return if drag events should never go to a parent scrollpane, if this component wants them all
+ */
public boolean consumesMotionEvents() {
- if (parent!=null) {
+ if (parent != null) {
return parent.consumesMotionEvents();
}
return false;
@@ -903,15 +929,18 @@
* in Swing this is done by adding a MouseListener that will then fire the popup menu
* @see java.awt.Component#addMouseListener(java.awt.event.MouseListener) Component.addMouseListener
* @see java.awt.Component#add(java.awt.PopupMenu)
+ * @see javax.swing.JComponent#setComponentPopupMenu(javax.swing.JPopupMenu)
*/
public void setPopupMenu(Window component) {
popup = component;
}
+
/**
+ * Override this method to customise the content of the popup when it is triggered
* @see javax.swing.JMenu#getPopupMenu() JMenu.getPopupMenu
+ * @see javax.swing.JComponent#getComponentPopupMenu()
*/
public Window getPopupMenu() {
return popup;
}
-
}
Modified: SwingME/src/net/yura/mobile/gui/components/FrameTitlePane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/FrameTitlePane.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/FrameTitlePane.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -169,7 +169,6 @@
if (type == DesktopPane.PRESSED) {
oldX=x;
oldY=y;
-
}
else if (type == DesktopPane.DRAGGED) {
Frame owner = (Frame)getWindow();
@@ -177,7 +176,6 @@
move(owner,owner.getX()+(x-oldX),owner.getY()+(y-oldY));
}
}
-
}
private void move(Window owner,int x,int y) {
Modified: SwingME/src/net/yura/mobile/gui/components/ImageView.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/ImageView.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/ImageView.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -108,11 +108,6 @@
}
// Override
- public void processMouseEvent(int type, int x, int y, KeyEvent keys) {
- // We handle all our Mouse events
- }
-
- // Override
public void processMultitouchEvent(int[] type, int[] x, int[] y) {
consumingMotionEvents = (type[0] != DesktopPane.RELEASED );
Modified: SwingME/src/net/yura/mobile/gui/components/List.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/List.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/List.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -555,8 +555,10 @@
if (!isFocusable()) {
// if we are disabled then we do not do anything!
+ return;
}
- else if (type == DesktopPane.PRESSED || type == DesktopPane.DRAGGED) {
+
+ if (type == DesktopPane.PRESSED || type == DesktopPane.DRAGGED) {
int i = locationToIndex(x, y)[0];
if (i>=0) { // if (ri<0||ri>=size) { this check is not needed any more
@@ -566,11 +568,8 @@
setSelectedIndex(-1);
}
}
- else if (type == DesktopPane.RELEASED) {
+ else if (type == DesktopPane.RELEASED && !isPopupTrigger(type, keys) && !isCtrlKeyDown(keys)) {
- if (isCtrlKeyDown(keys)) {
- return;
- }
if (doubleClick) {
long time = System.currentTimeMillis();
@@ -788,7 +787,6 @@
//if we did not consume the event
return false;
}
-
}
/**
Modified: SwingME/src/net/yura/mobile/gui/components/Menu.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Menu.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Menu.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -73,6 +73,12 @@
}
*/
+ // Override
+ protected boolean isPopupTrigger(int type, KeyEvent buttons) {
+ // do not trigger popup menus, just open menu as normal
+ return false;
+ }
+
public void fireActionPerformed() {
super.fireActionPerformed();
setPopupMenuVisible(true);
Modified: SwingME/src/net/yura/mobile/gui/components/Slider.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Slider.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Slider.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -286,7 +286,7 @@
if (!focusable) return;
- if (type==DesktopPane.RELEASED) {
+ if (type == DesktopPane.RELEASED) {
click = 0;
}
else if (type == DesktopPane.PRESSED) {
@@ -362,7 +362,6 @@
setValue(newValue);
}
}
-
}
public boolean processKeyEvent(KeyEvent keypad) {
Modified: SwingME/src/net/yura/mobile/gui/components/Spinner.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Spinner.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Spinner.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -142,14 +142,8 @@
}
fire();
}
- else if (type == DesktopPane.RELEASED) {
- if (leftPress || rightPress) {
- leftPress = false;
- rightPress = false;
- repaint();
- }
- }
- else if (type == DesktopPane.CANCEL) {
+ // if we started scrolling or opened a popup menu
+ else if (type == DesktopPane.CANCEL || isPopupTrigger(type, keys)) {
Object newVal=null;
if (leftPress) {
leftPress = false;
@@ -164,6 +158,13 @@
}
repaint();
}
+ else if (type == DesktopPane.RELEASED) {
+ if (leftPress || rightPress) {
+ leftPress = false;
+ rightPress = false;
+ repaint();
+ }
+ }
}
// public void setFocusable(boolean s) {
Modified: SwingME/src/net/yura/mobile/gui/components/TextComponent.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/TextComponent.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/TextComponent.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -282,7 +282,7 @@
public void processMouseEvent(int type, int x, int y, KeyEvent keys) {
boolean focusOwner = isFocusOwner();
super.processMouseEvent(type, x, y, keys);
- if (focusOwner && type==DesktopPane.PRESSED
+ if (focusOwner && type == DesktopPane.PRESSED
// && Midlet.getPlatform() != Midlet.PLATFORM_ME4SE) { // hacked me4se so this would not be needed (see javadoc)
) {
// TODO check if we have a qwerty keyboard
Modified: SwingME/src/net/yura/mobile/gui/components/Window.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Window.java 2023-04-15 14:03:34 UTC (rev 2732)
+++ SwingME/src/net/yura/mobile/gui/components/Window.java 2023-04-26 12:14:15 UTC (rev 2733)
@@ -251,8 +251,6 @@
) {
doClose();
}
-
-
}
public Component getComponentAt(final int xclick,final int yclick) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|