Revision: 29
http://swingme.svn.sourceforge.net/swingme/?rev=29&view=rev
Author: yuranet
Date: 2008-07-11 10:07:01 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
better softkeys
Modified Paths:
--------------
SwingME/src/net/yura/mobile/gui/DesktopPane.java
SwingME/src/net/yura/mobile/gui/components/Component.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 2008-07-11 16:23:45 UTC (rev 28)
+++ SwingME/src/net/yura/mobile/gui/DesktopPane.java 2008-07-11 17:07:01 UTC (rev 29)
@@ -66,6 +66,7 @@
private int background;
private boolean fullrepaint;
+ private boolean paintSoftKey;
private boolean paintdone=false;
private boolean killflag;
@@ -253,7 +254,7 @@
return;
}
- if (!fullrepaint) {
+ if (!fullrepaint && !paintSoftKey) {
boolean ret = paintWindow(g,currentWindow);
if (!ret) {
fullrepaint=true;
@@ -266,6 +267,7 @@
if (fullrepaint) {
fullrepaint = false;
+ paintFirst(g);
for (int c=0;c<windows.size();c++) {
paintWindow(g,(Window)windows.elementAt(c));
}
@@ -282,23 +284,33 @@
}
drawSoftkeys(g);
+ paintLast(g);
}
- 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);
+ public void paintFirst(Graphics g) { }
+ public void paintLast(Graphics g) { }
+
+ private void drawSoftkeys(Graphics g) {
+
+ Component com1 = getSoftkeyRenderer(0);
+
+ if (com1!=null) {
+
+ g.translate(com1.getX(), com1.getY());
+ com1.paint(g);
+ g.translate(-com1.getX(), -com1.getY());
}
- else {
- com.setBoundsWithBorder((i==1)?(getWidth()-w):0, getHeight()-h, w, h);
+
+ Component com2 = getSoftkeyRenderer(1);
+ if (com2!=null) {
+
+ g.translate(com2.getX(), com2.getY());
+ com2.paint(g);
+ g.translate(-com2.getX(), -com2.getY());
}
- return com;
+ paintSoftKey = false;
+
}
private boolean paintWindow(Graphics g,Window w) {
@@ -323,32 +335,24 @@
g.translate(-wx, -wy);
return ret;
}
-
- /**
- * override this to draw softkeys how you want to
- * @param g The Graphics
- */
- public void drawSoftkeys(Graphics g) {
-
- Component com1 = getSoftkeyRenderer(0);
-
- if (com1!=null) {
-
- g.translate(com1.getX(), com1.getY());
- com1.paint(g);
- g.translate(-com1.getX(), -com1.getY());
+
+ private boolean sideSoftKeys;
+ private Component getSoftkeyRenderer(int i) {
+ // if (theme==null || theme.softkeyRenderer==null) return null; // sometimes throws on emulator
+ 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);
}
-
- Component com2 = getSoftkeyRenderer(1);
- if (com2!=null) {
-
- g.translate(com2.getX(), com2.getY());
- com2.paint(g);
- g.translate(-com2.getX(), -com2.getY());
+ else {
+ com.setBoundsWithBorder((i==1)?(getWidth()-w):0, getHeight()-h, w, h);
}
-
+ return com;
}
+
// #####################################################################
// Different ways of caling repaint
@@ -399,10 +403,17 @@
/**
* Repaint the softkeybar
*/
- public void softkeyRepaint() {
+ public void softkeyRepaint(boolean all) {
// TODO: is this correct, will ANY repaint do?
// by default calling repaint() like this will do a window repaint
- repaint();
+ if (all) {
+ // we ONLY need to repaint all if the renderer does not paint anything on a null softkey
+ fullRepaint();
+ }
+ else {
+ paintSoftKey=true;
+ repaint();
+ }
}
// #####################################################################
@@ -439,8 +450,11 @@
public void setComponentCommand(int i, CommandButton softkey) {
if (componentCommands[i]!=softkey) {
+ CommandButton old = componentCommands[i];
componentCommands[i] = softkey;
- softkeyRepaint();
+ if (getCurrentCommands()[i]==softkey) {
+ softkeyRepaint(old==null || softkey ==null);
+ }
}
}
@@ -556,7 +570,7 @@
((ActionListener)focusedComponent).actionPerformed( componentCommands[i].getActionCommand() );
- if (componentCommands[i].getMenu()!=null) {
+ if (componentCommands[i]!=null && componentCommands[i].getMenu()!=null) {
Component renderer = getSoftkeyRenderer(i);
componentCommands[i].getMenu().openMenu(renderer.getXWithBorder(),renderer.getYWithBorder(),renderer.getWidthWithBorder(),renderer.getHeightWithBorder());
}
@@ -566,7 +580,7 @@
actionListener.actionPerformed( panelCmds[i].getActionCommand() );
- if (panelCmds[i].getMenu()!=null) {
+ if (panelCmds[i]!=null && panelCmds[i].getMenu()!=null) {
Component renderer = getSoftkeyRenderer(i);
panelCmds[i].getMenu().openMenu(renderer.getXWithBorder(),renderer.getYWithBorder(),renderer.getWidthWithBorder(),renderer.getHeightWithBorder());
}
Modified: SwingME/src/net/yura/mobile/gui/components/Component.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-11 16:23:45 UTC (rev 28)
+++ SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-11 17:07:01 UTC (rev 29)
@@ -107,7 +107,7 @@
// override and call super when things HAVE to be painted
public void paint(Graphics g) {
- //System.out.println("paint "+this);
+ System.out.println("paint "+this);
if (border != null) {
border.paintBorder(this, g,width,height);
Modified: SwingME/src/net/yura/mobile/gui/components/Window.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-11 16:23:45 UTC (rev 28)
+++ SwingME/src/net/yura/mobile/gui/components/Window.java 2008-07-11 17:07:01 UTC (rev 29)
@@ -274,9 +274,10 @@
public void setWindowCommand(int i, CommandButton softkey) {
if (panelCmds[i]!=softkey) {
+ CommandButton oldc = panelCmds[i];
panelCmds[i] = softkey;
- if (DesktopPane.getDesktopPane().getSelectedFrame()==this) {
- DesktopPane.getDesktopPane().softkeyRepaint();
+ if (DesktopPane.getDesktopPane().getSelectedFrame()==this && DesktopPane.getDesktopPane().getCurrentCommands()[i]==softkey) {
+ DesktopPane.getDesktopPane().softkeyRepaint(oldc==null || softkey == null);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|