Revision: 28
http://swingme.svn.sourceforge.net/swingme/?rev=28&view=rev
Author: yuranet
Date: 2008-07-11 09:23:45 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
menus and much more
Modified Paths:
--------------
SwingME/src/net/yura/mobile/gui/CommandButton.java
SwingME/src/net/yura/mobile/gui/DesktopPane.java
SwingME/src/net/yura/mobile/gui/KeyEvent.java
SwingME/src/net/yura/mobile/gui/Theme.java
SwingME/src/net/yura/mobile/gui/components/Button.java
SwingME/src/net/yura/mobile/gui/components/CheckBox.java
SwingME/src/net/yura/mobile/gui/components/ComboBox.java
SwingME/src/net/yura/mobile/gui/components/Component.java
SwingME/src/net/yura/mobile/gui/components/Panel.java
SwingME/src/net/yura/mobile/gui/components/ScrollPane.java
SwingME/src/net/yura/mobile/gui/components/TextField.java
SwingME/src/net/yura/mobile/gui/components/Window.java
SwingME/src/net/yura/mobile/test/MainPane.java
Added Paths:
-----------
SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultSoftkeyRenderer.java
SwingME/src/net/yura/mobile/gui/components/Menu.java
SwingME/src/net/yura/mobile/gui/components/TitleBar.java
Modified: SwingME/src/net/yura/mobile/gui/CommandButton.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/CommandButton.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/CommandButton.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -18,6 +18,7 @@
package net.yura.mobile.gui;
import javax.microedition.lcdui.Command;
+import net.yura.mobile.gui.components.Menu;
/**
* @author Yura Mamyrin
@@ -25,7 +26,8 @@
public class CommandButton extends Command {
private String actionCommand;
-
+ private Menu menu;
+
public CommandButton(String label,String com) {
super(label, Command.OK, 1);
@@ -33,6 +35,11 @@
}
+ public CommandButton(String label,String com,Menu m) {
+ this(label,com);
+ menu = m;
+ }
+
public void setActionCommand(String ac) {
actionCommand=ac;
@@ -43,8 +50,21 @@
return actionCommand;
}
+
+ public int hashCode() {
+ int hash = 7;
+ hash = 47 * hash + (this.actionCommand != null ? this.actionCommand.hashCode() : 0);
+ return hash;
+ }
public boolean equals(Object a){
return (a instanceof CommandButton && ((CommandButton) a).getActionCommand().equals(actionCommand));
}
+
+ public Menu getMenu() {
+ return menu;
+ }
+ public String toString() {
+ return getLabel();
+ }
}
Modified: SwingME/src/net/yura/mobile/gui/DesktopPane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/DesktopPane.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/DesktopPane.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -25,6 +25,7 @@
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import net.yura.mobile.gui.border.LineBorder;
+import net.yura.mobile.gui.cellrenderer.DefaultSoftkeyRenderer;
import net.yura.mobile.gui.components.Component;
import net.yura.mobile.gui.components.MultilineLabel;
import net.yura.mobile.gui.components.Panel;
@@ -68,7 +69,7 @@
private boolean paintdone=false;
private boolean killflag;
- private CommandButton[] omponentCommands;
+ private CommandButton[] componentCommands;
// to avoid creating new array every time
private CommandButton[] currentCommands;
@@ -85,7 +86,7 @@
background = back;
splash = sph;
- omponentCommands = new CommandButton[2];
+ componentCommands = new CommandButton[2];
currentCommands = new CommandButton[2];
setFullScreenMode(true);
@@ -185,9 +186,7 @@
if (theme.font==null) {
theme.font=new Font();
}
- if (theme.barHeight==0) {
- theme.barHeight=theme.font.getHeight();
- }
+
if (theme.defaultWidth==0) {
theme.defaultWidth = getWidth()-ScrollPane.getBarThickness(getWidth(), getHeight());
}
@@ -206,7 +205,11 @@
}
- currentWindow.setSize(getWidth(),getHeight()-theme.barHeight);
+ if (theme.softkeyRenderer==null) {
+ theme.softkeyRenderer = new DefaultSoftkeyRenderer();
+ }
+
+ currentWindow.setSize(getWidth(),getHeight());
}
@@ -282,6 +285,22 @@
}
+ private boolean sideSoftKeys;
+ private Component getSoftkeyRenderer(int i) {
+ if (theme.softkeyRenderer==null) return null;
+ Component com = theme.softkeyRenderer.getListCellRendererComponent(null, getCurrentCommands()[i], i, false, false);
+ if (com==null) return null;
+ int h = com.getHeightWithBorder();
+ int w = com.getWidthWithBorder();
+ if (sideSoftKeys) {
+ com.setBoundsWithBorder(getWidth()-w, (i==0)?(getHeight()-h):0, w, h);
+ }
+ else {
+ com.setBoundsWithBorder((i==1)?(getWidth()-w):0, getHeight()-h, w, h);
+ }
+ return com;
+ }
+
private boolean paintWindow(Graphics g,Window w) {
//System.out.println("paintWindow window:"+ w+" component:"+repaintComponent );
@@ -310,29 +329,24 @@
* @param g The Graphics
*/
public void drawSoftkeys(Graphics g) {
+
+ Component com1 = getSoftkeyRenderer(0);
- Font f = getDefaultTheme().font;
+ if (com1!=null) {
- g.setColor( getDefaultTheme().background );
- g.fillRect(0, getHeight() - f.getHeight(), getWidth(), f.getHeight());
+ g.translate(com1.getX(), com1.getY());
+ com1.paint(g);
+ g.translate(-com1.getX(), -com1.getY());
+ }
- g.setColor( f.getColors()[0] );
+ Component com2 = getSoftkeyRenderer(1);
+ if (com2!=null) {
- CommandButton[] buttons = getCurrentCommands();
- String s;
-
- if (buttons[0]!=null) {
-
- s= buttons[0].getLabel();
-
- f.drawString(g,s , ((getWidth()/2)-( f.getWidth(s) ))/2, getHeight() - f.getHeight() , Graphics.TOP | Graphics.LEFT );
+ g.translate(com2.getX(), com2.getY());
+ com2.paint(g);
+ g.translate(-com2.getX(), -com2.getY());
}
- if (buttons[1]!=null) {
- s= buttons[1].getLabel();
-
- f.drawString(g,s ,(getWidth()/2)+ ((getWidth()/2)-( f.getWidth(s) ))/2, getHeight() - f.getHeight() , Graphics.TOP | Graphics.LEFT );
- }
}
// #####################################################################
@@ -414,8 +428,8 @@
}
public CommandButton[] getCurrentCommands(){
- currentCommands[0] = omponentCommands[0] == null ? currentWindow.getWindowCommands()[0] : omponentCommands[0];
- currentCommands[1] = omponentCommands[1] == null ? currentWindow.getWindowCommands()[1] : omponentCommands[1];
+ currentCommands[0] = componentCommands[0] == null ? currentWindow.getWindowCommands()[0] : componentCommands[0];
+ currentCommands[1] = componentCommands[1] == null ? currentWindow.getWindowCommands()[1] : componentCommands[1];
return currentCommands;
}
@@ -424,8 +438,8 @@
*/
public void setComponentCommand(int i, CommandButton softkey) {
- if (omponentCommands[i]!=softkey) {
- omponentCommands[i] = softkey;
+ if (componentCommands[i]!=softkey) {
+ componentCommands[i] = softkey;
softkeyRepaint();
}
@@ -436,54 +450,31 @@
try {
if(keyevent.isDownKey(Canvas.KEY_STAR)){
-
mem = (Runtime.getRuntime().freeMemory() >> 10) +"K/" +(Runtime.getRuntime().totalMemory() >> 10)+"K";
fullRepaint();
}
else {
-
mem = null;
-
}
- CommandButton[] panelCmds = currentWindow.getWindowCommands();
- ActionListener actionListener = currentWindow.getActionListener();
-
- boolean softkey1Action = keyevent.isDownKey(KeyEvent.KEY_SOFTKEY1) || keyevent.justReleasedKey(KeyEvent.KEY_SOFTKEY1);
- boolean softkey2Action = keyevent.isDownKey(KeyEvent.KEY_SOFTKEY2) || keyevent.justReleasedKey(KeyEvent.KEY_SOFTKEY2);
-
- // ############# we use justReleasedKey for firing actions, this means the action is ONLY
- // ############# fired off when the key is released!!!
-
- if (
- focusedComponent!=null && focusedComponent instanceof ActionListener && (
- (omponentCommands[0]!=null && softkey1Action ) ||
- (omponentCommands[1]!=null && softkey2Action )
- )
- ) {
+ CommandButton[] cmds = getCurrentCommands();
- if (omponentCommands[0]!=null && keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY1)) {
- ((ActionListener)focusedComponent).actionPerformed( omponentCommands[0].getActionCommand() );
- }
- else if (omponentCommands[1]!=null && keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY2)) {
- ((ActionListener)focusedComponent).actionPerformed( omponentCommands[1].getActionCommand() );
- }
- }
- else if (
- actionListener!=null && (
- (panelCmds[0]!=null && softkey1Action ) ||
- (panelCmds[1]!=null && softkey2Action )
- )
- ) {
+ if (
+ ( cmds[0]!=null && (keyevent.isDownKey(KeyEvent.KEY_SOFTKEY1) || keyevent.justReleasedKey(KeyEvent.KEY_SOFTKEY1)) ) ||
+ ( cmds[1]!=null && (keyevent.isDownKey(KeyEvent.KEY_SOFTKEY2) || keyevent.justReleasedKey(KeyEvent.KEY_SOFTKEY2)) )
+ ) {
+
+ // ############# we use justReleasedKey for firing actions, this means the action is ONLY
+ // ############# fired off when the key is released!!!
- if (panelCmds[0]!=null && keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY1)) {
- actionListener.actionPerformed( panelCmds[0].getActionCommand() );
- }
- else if (panelCmds[1]!=null && keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY2)) {
- actionListener.actionPerformed( panelCmds[1].getActionCommand() );
- }
-
- }
+ if (keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY1)) {
+ softKeyActivated(0);
+ }
+ else if (keyevent.justPressedKey(KeyEvent.KEY_SOFTKEY2)) {
+ softKeyActivated(1);
+ }
+
+ }
else if (focusedComponent!=null) {
boolean consumed = focusedComponent.keyEvent(keyevent);
@@ -546,6 +537,47 @@
}
}
+
+
+
+
+
+
+ private void softKeyActivated(int i) {
+
+ CommandButton[] panelCmds = currentWindow.getWindowCommands();
+ ActionListener actionListener = currentWindow.getActionListener();
+
+ if (
+ componentCommands[i]!=null &&
+ focusedComponent!=null &&
+ focusedComponent instanceof ActionListener
+ ) {
+
+ ((ActionListener)focusedComponent).actionPerformed( componentCommands[i].getActionCommand() );
+
+ if (componentCommands[i].getMenu()!=null) {
+ Component renderer = getSoftkeyRenderer(i);
+ componentCommands[i].getMenu().openMenu(renderer.getXWithBorder(),renderer.getYWithBorder(),renderer.getWidthWithBorder(),renderer.getHeightWithBorder());
+ }
+
+ }
+ else if (actionListener!=null && panelCmds[i]!=null) {
+
+ actionListener.actionPerformed( panelCmds[i].getActionCommand() );
+
+ if (panelCmds[i].getMenu()!=null) {
+ Component renderer = getSoftkeyRenderer(i);
+ panelCmds[i].getMenu().openMenu(renderer.getXWithBorder(),renderer.getYWithBorder(),renderer.getWidthWithBorder(),renderer.getHeightWithBorder());
+ }
+
+ }
+
+ }
+
+
+
+
// if no command listener is used key events fall though to this method
// used for adding global shortcut keys
public void keyEvent(KeyEvent kypd) { }
@@ -735,7 +767,8 @@
public static final int DRAGGED = 0;
public static final int PRESSED = 1;
public static final int RELEASED = 2;
-
+ private Component pointerComponent;
+
public void pointerDragged(int x, int y) {
pointerEvent(DRAGGED,x,y);
}
@@ -752,7 +785,29 @@
private void pointerEvent(int type, int x, int y){
try {
- currentWindow.pointerEvent(type, x - currentWindow.getX(), y - currentWindow.getY());
+
+ if (type == PRESSED) {
+
+ // check if pressing on a softkey
+ for (int c=0;c<componentCommands.length;c++) {
+ Component comp = getSoftkeyRenderer(c);
+ if (comp!=null) {
+ int cx = comp.getXWithBorder();
+ int cy = comp.getYWithBorder();
+ if (comp!=null && x>=cx && x<=cx+comp.getWidthWithBorder() && y>=cy && y<=cy+comp.getHeightWithBorder()) {
+ softKeyActivated(c);
+ return;
+ }
+ }
+ }
+
+
+ pointerComponent = currentWindow.getComponentAt( x - currentWindow.getX(), y - currentWindow.getY());
+ }
+
+ if (pointerComponent!=null) {
+ pointerComponent.pointerEvent(type, x - currentWindow.getX()-pointerComponent.getXInWindow(), y - currentWindow.getY()-pointerComponent.getYInWindow());
+ }
}
catch(Throwable th) {
th.printStackTrace();
@@ -765,13 +820,23 @@
// other events from the canvas
// #####################################################################
- protected void sizeChanged(int w, int h){
+ protected void sizeChanged(int w, int h) {
+ //#debug
+ System.out.println("sizeChanged!!");
+ if (w>h) {
+ sideSoftKeys = true;
+ }
+ else {
+ sideSoftKeys = false;
+ }
for (int c=0;c<windows.size();c++) {
Window window = (Window)windows.elementAt(c);
- // TODO RESIZE
-
+ // TODO RESIZE better
+ if (window.getX()==0 && window.getY()==0) {
+ window.setSize(w, h);
+ }
}
}
@@ -791,4 +856,5 @@
}
+
}
\ No newline at end of file
Modified: SwingME/src/net/yura/mobile/gui/KeyEvent.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/KeyEvent.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/KeyEvent.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -127,15 +127,15 @@
private static final char[] CHARS_42 = new char[] {'*'};
private static final char[] CHARS_35 = new char[] {'#'};
private static final char[] CHARS_48 = new char[] {' ','0'};
- private static final char[] CHARS_49 = new char[] {'.',',','?','!','1'};
- private static final char[] CHARS_50 = new char[] {'a','b','c'};
- private static final char[] CHARS_51 = new char[] {'d','e','f'};
- private static final char[] CHARS_52 = new char[] {'g','h','i'};
- private static final char[] CHARS_53 = new char[] {'j','k','l'};
- private static final char[] CHARS_54 = new char[] {'m','n','o'};
- private static final char[] CHARS_55 = new char[] {'p','q','r','s'};
- private static final char[] CHARS_56 = new char[] {'t','u','v'};
- private static final char[] CHARS_57 = new char[] {'w','x','y','z'};
+ private static final char[] CHARS_49 = new char[] {'.',',','?','!','1','@','\'','-','_'};
+ private static final char[] CHARS_50 = new char[] {'a','b','c','2'};
+ private static final char[] CHARS_51 = new char[] {'d','e','f','3'};
+ private static final char[] CHARS_52 = new char[] {'g','h','i','4'};
+ private static final char[] CHARS_53 = new char[] {'j','k','l','5'};
+ private static final char[] CHARS_54 = new char[] {'m','n','o','6'};
+ private static final char[] CHARS_55 = new char[] {'p','q','r','s','7'};
+ private static final char[] CHARS_56 = new char[] {'t','u','v','8'};
+ private static final char[] CHARS_57 = new char[] {'w','x','y','z','9'};
public static char[] getChars(int keycode,int mode) {
Modified: SwingME/src/net/yura/mobile/gui/Theme.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/Theme.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/Theme.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -19,6 +19,7 @@
import net.yura.mobile.gui.border.Border;
import net.yura.mobile.gui.border.LineBorder;
+import net.yura.mobile.gui.cellrenderer.ListCellRenderer;
public class Theme {
@@ -37,18 +38,18 @@
public int defaultWidth;
public int defaultSpace;
- public int barHeight;
+ public ListCellRenderer softkeyRenderer;
+
public Theme(){
- this(null,0,0);
+ this(null,0);
// these will have defaults setup anyway
}
- public Theme(Font font,int barHeight,int a) {
+ public Theme(Font font,int a) {
this.font = font;
- this.barHeight = barHeight;
defaultWidth = a;
background = 0x00FFFFFF;
@@ -56,7 +57,6 @@
normalBorder = new LineBorder(0x00808080);
activeBorder = new LineBorder(0);
-
}
}
Added: SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultSoftkeyRenderer.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultSoftkeyRenderer.java (rev 0)
+++ SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultSoftkeyRenderer.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -0,0 +1,34 @@
+package net.yura.mobile.gui.cellrenderer;
+
+import javax.microedition.lcdui.Graphics;
+import net.yura.mobile.gui.DesktopPane;
+import net.yura.mobile.gui.components.Component;
+import net.yura.mobile.gui.components.List;
+import net.yura.mobile.gui.Font;
+/**
+ * @author Yura Mamyrin
+ */
+public class DefaultSoftkeyRenderer extends Component implements ListCellRenderer {
+
+ private String text;
+
+ public DefaultSoftkeyRenderer() {
+ setBackground(0x00FFFFFF);
+ }
+
+ public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ if (value==null) return null;
+ text = value.toString();
+ height = DesktopPane.getDefaultTheme().font.getHeight();
+ width = DesktopPane.getDesktopPane().getWidth()/2 - 10;
+ return this;
+ }
+
+ public void paintComponent(Graphics g) {
+ g.setColor(0x00000000);
+ Font f = DesktopPane.getDefaultTheme().font;
+ f.drawString(g, text, (width-f.getWidth(text))/2, (height-f.getHeight())/2, Graphics.TOP | Graphics.LEFT);
+
+ }
+
+}
Property changes on: SwingME/src/net/yura/mobile/gui/cellrenderer/DefaultSoftkeyRenderer.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: SwingME/src/net/yura/mobile/gui/components/Button.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Button.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/Button.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -120,6 +120,9 @@
actionCommand=ac;
}
+ public ActionListener getActionListener() {
+ return al;
+ }
public boolean keyEvent(KeyEvent keyEvent) {
@@ -142,8 +145,11 @@
selected=true;
}
else if (selected && type == DesktopPane.RELEASED) {
- fireActionPerformed();
+ if (x>=0 && x<=width && y>=0 && y<=height) {
+ fireActionPerformed();
+ }
}
+
}
public void fireActionPerformed() {
Modified: SwingME/src/net/yura/mobile/gui/components/CheckBox.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/CheckBox.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/CheckBox.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -47,6 +47,10 @@
}
+ public void setSelected(boolean selected) {
+ super.setSelected(selected);
+ oldState = selected;
+ }
public void paintExtra(Graphics g) {
Modified: SwingME/src/net/yura/mobile/gui/components/ComboBox.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/ComboBox.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/ComboBox.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -102,7 +102,7 @@
y = getYInWindow() + height;
}
- scroll.setPosition(getXInWindow(), y);
+ scroll.setLocation(getXInWindow(), y);
owner.setGlassPaneComponent(scroll);
pbuttons = new CommandButton[2];
Modified: SwingME/src/net/yura/mobile/gui/components/Component.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -91,7 +91,7 @@
}
public void setBounds(int posX, int posY, int width, int height) {
- setPosition(posX,posY);
+ setLocation(posX,posY);
setSize(width,height);
}
@@ -100,7 +100,7 @@
this.height = height;
}
- public void setPosition(int posX, int posY){
+ public void setLocation(int posX, int posY){
this.posX = posX;
this.posY = posY;
}
@@ -133,9 +133,17 @@
}
public void pointerEvent(int type, int x, int y) {
- if (selectable && type == DesktopPane.PRESSED) {
- DesktopPane.getDesktopPane().setFocusedComponent(this);
+ if (selectable) {
+ if (type == DesktopPane.PRESSED) {
+ DesktopPane.getDesktopPane().setFocusedComponent(this);
+ }
}
+ else if (parent!=null) {
+ parent.pointerEvent(type,x+posX,y+posY);
+ }
+ else {
+ owner.pointerEvent(type,x+getXInWindow(),y+getYInWindow());
+ }
}
public void animate() { }
Added: SwingME/src/net/yura/mobile/gui/components/Menu.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Menu.java (rev 0)
+++ SwingME/src/net/yura/mobile/gui/components/Menu.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -0,0 +1,85 @@
+package net.yura.mobile.gui.components;
+
+import javax.microedition.lcdui.Graphics;
+import javax.microedition.lcdui.Image;
+import net.yura.mobile.gui.ActionListener;
+import net.yura.mobile.gui.CommandButton;
+import net.yura.mobile.gui.DesktopPane;
+import net.yura.mobile.gui.layout.BoxLayout;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class Menu extends Button {
+
+ private Window popup;
+ private Panel panel;
+ private Menu parentMenu;
+
+ public Menu(String string) {
+ super(string);
+ makeWindow();
+ }
+
+ public void fireActionPerformed() {
+
+ openMenu(getXInWindow()+owner.getX(), getYInWindow()+owner.getY(), width, height);
+
+ }
+
+ public void openMenu(int x, int y, int width, int height) {
+ popup.setBoundsWithBorder(0, 0, 50, 50);
+ DesktopPane.getDesktopPane().add(popup);
+ }
+
+ private void makeWindow() {
+
+ popup = new Window();
+ //popup.setWindowCommand(0, new CommandButton(getText(), "select"));
+ popup.setWindowCommand(1, new CommandButton("Cancel", "cancel"));
+ popup.setActionListener(this);
+ panel = popup.getContentPane();
+ panel.setLayout(new BoxLayout(Graphics.VCENTER));
+ popup.setContentPane(new ScrollPane(panel));
+
+ }
+
+ public void actionPerformed(String actionCommand) {
+
+ DesktopPane.getDesktopPane().remove(popup);
+ super.fireActionPerformed();
+
+ if (!"cancel".equals(actionCommand)) {
+ ActionListener al = getActionListener();
+ if (al!=null) {
+ al.actionPerformed(actionCommand);
+ }
+ }
+
+ // cancel the parent menu
+ if (parentMenu!=null) { parentMenu.actionPerformed("cancel"); }
+
+ }
+
+ public void add(Component c) {
+ panel.add(c);
+
+ if (c instanceof Menu) {
+ ((Menu)c).setParentMenu(this);
+ }
+
+ }
+
+ private void setParentMenu(Menu m) {
+ parentMenu = m;
+ }
+
+ public void addMenuItem(String name,Image icon,String command) {
+
+ Button b = new Button(name,icon);
+ b.setActionCommand(command);
+ b.addActionListener(this);
+ add(b);
+ }
+
+}
Property changes on: SwingME/src/net/yura/mobile/gui/components/Menu.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: SwingME/src/net/yura/mobile/gui/components/Panel.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Panel.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/Panel.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -180,26 +180,6 @@
}
}
-
-
-
-
- public void pointerEvent(int type, int x, int y) {
-
- for(int i = 0; i < components.size(); i++){
- Component component = (Component)components.elementAt(i);
- int x1 = component.getX();
- int y1 = component.getY();
- int x2 = x1 + component.getWidth();
- int y2 = y1 + component.getHeight();
- if( (x > x1 && x < x2) && (y > y1 && y < y2)){
- component.pointerEvent(type, x-x1, y-y1 );
- }
- }
-
- }
-
-
// BREAK OUT!!!
// find next component in this panel
@@ -339,6 +319,24 @@
parent.clip(g);
}
}
+
+ public Component getComponentAt(int x, int y) {
+ for(int i = 0; i < components.size(); i++){
+ Component component = (Component)components.elementAt(i);
+ int x1 = component.getXWithBorder();
+ int y1 = component.getYWithBorder();
+ int x2 = x1 + component.getWidthWithBorder();
+ int y2 = y1 + component.getHeightWithBorder();
+ if( x >= x1 && x <= x2 && y >= y1 && y <= y2){
+
+ if (component instanceof Panel) {
+ return ((Panel)component).getComponentAt( x-component.getX(), y-component.getY() );
+ }
+ return component;
+ }
+ }
+ return this;
+ }
}
Modified: SwingME/src/net/yura/mobile/gui/components/ScrollPane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/ScrollPane.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/ScrollPane.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -99,7 +99,7 @@
// ((Panel)a).setScrollPanel(this);
//}
- a.setPosition(getViewPortX(), getViewPortY());
+ a.setLocation(getViewPortX(), getViewPortY());
a.setScrollPanel(this);
Modified: SwingME/src/net/yura/mobile/gui/components/TextField.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/TextField.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/TextField.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -125,8 +125,9 @@
private void autoAccept() {
if (tmpChar!=0) {
- insertNewCharacter(tmpChar);
+ char tmp = tmpChar;
tmpChar=0;
+ insertNewCharacter(tmp);
}
}
Added: SwingME/src/net/yura/mobile/gui/components/TitleBar.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/TitleBar.java (rev 0)
+++ SwingME/src/net/yura/mobile/gui/components/TitleBar.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -0,0 +1,148 @@
+package net.yura.mobile.gui.components;
+
+import javax.microedition.lcdui.Canvas;
+import javax.microedition.lcdui.Graphics;
+import javax.microedition.lcdui.Image;
+import net.yura.mobile.gui.ActionListener;
+import net.yura.mobile.gui.DesktopPane;
+import net.yura.mobile.gui.KeyEvent;
+import net.yura.mobile.gui.layout.BorderLayout;
+import net.yura.mobile.gui.layout.GridLayout;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class TitleBar extends Panel implements ActionListener {
+
+ public TitleBar(String title,Image icon,boolean resize,boolean move,boolean hide,boolean max,boolean close) {
+
+ super(new BorderLayout());
+
+
+ Panel buttonPanel = new Panel( new GridLayout(1,0,2) );
+ if (resize) {
+ Button b = new Button("#");
+ buttonPanel.add(b);
+ b.addActionListener(this);
+ b.setActionCommand("resize");
+ }
+ if (move) {
+ Button b = new Button("+");
+ buttonPanel.add(b);
+ b.addActionListener(this);
+ b.setActionCommand("move");
+ }
+ if (hide) {
+ Button b = new Button("_");
+ b.addActionListener(this);
+ b.setActionCommand("hide");
+ buttonPanel.add(b);
+ }
+ if (max) {
+ Button b = new Button("[]");
+ b.addActionListener(this);
+ b.setActionCommand("max");
+ buttonPanel.add(b);
+ }
+ if (close) {
+ Button b = new Button("X");
+ b.addActionListener(this);
+ b.setActionCommand("close");
+ buttonPanel.add(b);
+
+ }
+
+ add(new Label( title,icon ));
+ add(buttonPanel,Graphics.RIGHT);
+ setBackground(0x00AAAAFF);
+
+ }
+
+ private int oldX,oldY;
+ private boolean move,resize;
+ private Component old;
+
+ public void pointerEvent(int type, int x, int y) {
+
+ if (type == DesktopPane.PRESSED) {
+ oldX=x;
+ oldY=y;
+
+ }
+ else if (type == DesktopPane.DRAGGED) {
+
+ owner.setLocation(owner.getX()+(x-oldX),owner.getY()+(y-oldY));
+ DesktopPane.getDesktopPane().fullRepaint();
+
+ }
+
+ }
+
+ public boolean keyEvent(KeyEvent keypad) {
+
+ if (keypad.isDownAction(Canvas.LEFT)) {
+
+ if (move) { owner.setLocation(owner.getX()-2,owner.getY()); }
+ else if (resize) { owner.setSize(owner.getWidth()-2, owner.getHeight()); }
+ DesktopPane.getDesktopPane().fullRepaint();
+ return true;
+ }
+ if (keypad.isDownAction(Canvas.RIGHT)) {
+
+ if (move) { owner.setLocation(owner.getX()+2,owner.getY()); }
+ else if (resize) { owner.setSize(owner.getWidth()+2, owner.getHeight()); }
+ DesktopPane.getDesktopPane().fullRepaint();
+ return true;
+ }
+ if (keypad.isDownAction(Canvas.UP)) {
+
+ if (move) { owner.setLocation(owner.getX(),owner.getY()-2); }
+ else if (resize) { owner.setSize(owner.getWidth(), owner.getHeight()-2); }
+ DesktopPane.getDesktopPane().fullRepaint();
+ return true;
+ }
+ if (keypad.isDownAction(Canvas.DOWN)) {
+
+ if (move) { owner.setLocation(owner.getX(),owner.getY()+2); }
+ else if (resize) { owner.setSize(owner.getWidth(), owner.getHeight()+2); }
+ DesktopPane.getDesktopPane().fullRepaint();
+ return true;
+ }
+ if (keypad.isDownAction(Canvas.FIRE)) {
+
+ move = false;
+ resize = false;
+ DesktopPane.getDesktopPane().setFocusedComponent(old);
+ return true;
+ }
+ return false;
+ }
+
+ // if we loseFocus to some random component then resize or move can STILL be true
+ public void actionPerformed(String actionCommand) {
+
+ if (resize || move) {
+ move = false;
+ resize = false;
+ }
+ else if ("move".equals(actionCommand)) {
+
+ old = DesktopPane.getDesktopPane().getFocusedComponent();
+ DesktopPane.getDesktopPane().setFocusedComponent(this);
+ move = true;
+
+ }
+ else if ("resize".equals(actionCommand)) {
+
+ old = DesktopPane.getDesktopPane().getFocusedComponent();
+ DesktopPane.getDesktopPane().setFocusedComponent(this);
+ resize = true;
+
+ }
+ else {
+ owner.actionPerformed(actionCommand);
+ }
+ }
+
+
+}
Property changes on: SwingME/src/net/yura/mobile/gui/components/TitleBar.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: SwingME/src/net/yura/mobile/gui/components/Window.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -20,14 +20,11 @@
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
-
-import javax.microedition.lcdui.Image;
import net.yura.mobile.gui.ActionListener;
import net.yura.mobile.gui.CommandButton;
import net.yura.mobile.gui.DesktopPane;
import net.yura.mobile.gui.border.Border;
import net.yura.mobile.gui.layout.BorderLayout;
-import net.yura.mobile.gui.layout.GridLayout;
/**
* @author Yura Mamyrin
@@ -65,39 +62,6 @@
panelCmds = new CommandButton[2];
setBorder(b);
}
-
- public void makeDecoration(String title,Image icon,boolean move,boolean hide,boolean close) {
-
- // TODO
- // Font and color need to be changable
- // move button needs to work, also moving with pointer needs to work
-
- Panel buttonPanel = new Panel( new GridLayout(1,0,2) );
- if (move) {
- buttonPanel.add(new Button("O"));
- }
- if (hide) {
- Button b = new Button("_");
- b.addActionListener(this);
- b.setActionCommand("hide");
- buttonPanel.add(b);
-
- }
- if (close) {
- Button b = new Button("X");
- b.addActionListener(this);
- b.setActionCommand("close");
- buttonPanel.add(b);
-
- }
-
- Panel decoration = new Panel( new BorderLayout() );
- decoration.add(new Label( title,icon ));
- decoration.add(buttonPanel,Graphics.RIGHT);
- decoration.setBackground(0x00AAAAFF);
-
- contentPane.add(decoration,Graphics.TOP);
- }
public void setupFocusedComponent() {
@@ -277,21 +241,27 @@
}
-
- public void pointerEvent(int type, int x, int y){
+ public void pointerEvent(int type, int x, int y) {
- if (glasspanecomponent!=null) {
-
- glasspanecomponent.pointerEvent(type, x - glasspanecomponent.getX(), y - glasspanecomponent.getY());
- }
- else {
-
- contentPane.pointerEvent(type, x, y);
-
- }
- }
+ // TODO to resize the window
+ // if we drag next to the border
+ }
+
+ public Component getComponentAt(int x, int y) {
+
+
+ if (glasspanecomponent!=null) {
+ return glasspanecomponent.getComponentAt( x - glasspanecomponent.getX(), y - glasspanecomponent.getY());
+ }
+ else {
+ return contentPane.getComponentAt( x, y);
+
+ }
+
+ }
+
public void paintComponent(Graphics g) { }
public CommandButton[] getWindowCommands() {
@@ -326,25 +296,37 @@
}
}
+
+ public void actionPerformed(String actionCommand) {
+
+ if ("close".equals(actionCommand)) {
- public void actionPerformed(String actionCommand) {
- if ("close".equals(actionCommand)) {
-
- if (parent==null) {
- DesktopPane.getDesktopPane().remove(this);
+ if (parent==null) {
+ DesktopPane.getDesktopPane().remove(this);
+ }
+ else {
+ parent.remove(this);
+ }
}
- else {
- parent.remove(this);
- }
- }
- if ("hide".equals(actionCommand)) {
-
- if (parent==null) {
- Vector windows = DesktopPane.getDesktopPane().getAllFrames();
- if (windows.size()>1) {
- DesktopPane.getDesktopPane().setSelectedFrame((Window)windows.elementAt(windows.size()-2));
+ else if ("hide".equals(actionCommand)) {
+
+ if (parent==null) {
+ Vector windows = DesktopPane.getDesktopPane().getAllFrames();
+ if (windows.size()>1) {
+ DesktopPane.getDesktopPane().setSelectedFrame((Window)windows.elementAt(windows.size()-2));
+ }
}
}
- }
- }
+ else if ("max".equals(actionCommand)) {
+
+ setBounds(0,0,DesktopPane.getDesktopPane().getWidth(), DesktopPane.getDesktopPane().getHeight());
+ repaint();
+ }
+ else {
+ System.out.println("?? "+actionCommand);
+ }
+
+
+ }
+
}
Modified: SwingME/src/net/yura/mobile/test/MainPane.java
===================================================================
--- SwingME/src/net/yura/mobile/test/MainPane.java 2008-07-10 23:34:23 UTC (rev 27)
+++ SwingME/src/net/yura/mobile/test/MainPane.java 2008-07-11 16:23:45 UTC (rev 28)
@@ -48,6 +48,8 @@
import net.yura.mobile.gui.layout.FlowLayout;
import net.yura.mobile.gui.KeyEvent;
import net.yura.mobile.gui.border.MatteBorder;
+import net.yura.mobile.gui.components.Menu;
+import net.yura.mobile.gui.components.TitleBar;
import net.yura.mobile.util.Option;
/**
@@ -60,6 +62,7 @@
private Panel info;
private Panel border;
private Panel tabPanel;
+ private Menu menu;
private Image image;
private MultilineLabel infoLabel;
@@ -130,7 +133,7 @@
else if ("windowTest1".equals(actionCommand)) {
Window test1 = new Window( new LineBorder() );
- test1.makeDecoration("Window Title",image,true,true,true);
+ test1.getContentPane().add( new TitleBar("Window Title",image,true,true,true,true,true),Graphics.TOP);
test1.getContentPane().add(new Label("LALAL TEST 1"));
test1.setBounds(10, 10, getWidth()-20, getHeight()/2);
test1.getContentPane().doLayout();
@@ -156,6 +159,7 @@
default: infoLabel.append("Unknown"); break;
}
infoLabel.repaint();
+
}
public boolean keyEvent(KeyEvent keypad) {
int code1 = keypad.getJustPressedKey();
@@ -235,9 +239,19 @@
componentTest.add( new MultilineLabel("a MultilineLabel with a very long bit of text that will need to go onto more then 1 line") );
componentTest.add( new List(items,new DefaultListCellRenderer(),false) );
+
+ menu = new Menu("M1");
+ menu.add(new Button("bob"));
+
+ Menu menu2 = new Menu("Sub");
+ menu2.addActionListener(this);
+ menu2.add(new Button("fred"));
+ menu2.addMenuItem("item", null, "action");
+ menu.add(menu2);
+
}
- addToScrollPane(componentTest, null, new CommandButton("Back","mainmenu") );
+ addToScrollPane(componentTest, new CommandButton("Menu","popmenu",menu), new CommandButton("Back","mainmenu") );
}
else if ("loadpanel".equals(actionCommand)) {
@@ -288,18 +302,18 @@
test2.setBorder(new MatteBorder("/skin1.skin"));
border.add(test2);
- Panel menu = new Panel(new FlowLayout(Graphics.VCENTER,0));
- menu.setBorder(new MatteBorder("/skin2.skin"));
- menu.add(new Button("menu TEST item 1"));
- menu.add(new Button("menu TEST item 2"));
- menu.add(new Button("menu TEST item 3"));
- menu.add(new Button("menu TEST item 4"));
- border.add(menu);
+ Panel menuTest = new Panel(new FlowLayout(Graphics.VCENTER,0));
+ menuTest.setBorder(new MatteBorder("/skin2.skin"));
+ menuTest.add(new Button("menu TEST item 1"));
+ menuTest.add(new Button("menu TEST item 2"));
+ menuTest.add(new Button("menu TEST item 3"));
+ menuTest.add(new Button("menu TEST item 4"));
+ border.add(menuTest);
- menu = new Panel(new FlowLayout(Graphics.VCENTER,0));
- menu.setBorder(new MatteBorder(10,20,30,40,image));
- menu.add(new Button("MatteBorderTest"));
- border.add(menu);
+ menuTest = new Panel(new FlowLayout(Graphics.VCENTER,0));
+ menuTest.setBorder(new MatteBorder(10,20,30,40,image));
+ menuTest.add(new Button("MatteBorderTest"));
+ border.add(menuTest);
}
addToScrollPane(border, null , new CommandButton("Back","mainmenu") );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|