Revision: 24
http://swingme.svn.sourceforge.net/swingme/?rev=24&view=rev
Author: yuranet
Date: 2008-07-09 07:56:51 -0700 (Wed, 09 Jul 2008)
Log Message:
-----------
better painting
Modified Paths:
--------------
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
Modified: SwingME/src/net/yura/mobile/gui/components/Component.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-09 12:18:14 UTC (rev 23)
+++ SwingME/src/net/yura/mobile/gui/components/Component.java 2008-07-09 14:56:51 UTC (rev 24)
@@ -146,15 +146,19 @@
public void focusGained() {
// default focusGained action, make me visible
- scrollRectToVisible(
+ makeVisible();
+
+ }
+
+ public void makeVisible() {
+ scrollRectToVisible(
(border!=null)?-border.getLeft():0,
(border!=null)?-border.getTop():0,
getWidthWithBorder(),
getHeightWithBorder(),
false);
+ }
- }
-
public void doLayout() { }
public void setBackground(int a) {
Modified: SwingME/src/net/yura/mobile/gui/components/Panel.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/Panel.java 2008-07-09 12:18:14 UTC (rev 23)
+++ SwingME/src/net/yura/mobile/gui/components/Panel.java 2008-07-09 14:56:51 UTC (rev 24)
@@ -98,7 +98,7 @@
public void remove(Component component) {
components.removeElement(component);
- //component.setOwner( null );
+ component.setOwnerAndParent(null,null);
constraints.remove(component);
}
@@ -126,31 +126,37 @@
public void paint(Graphics g) {
super.paint(g);
-
- //System.out.println("painting"+components);
-
+
paintChildren(g);
-
-
- //g.translate(-posX, -posY);
}
public void paintChildren(Graphics g){
- for(int i = 0; i < components.size(); i++){
- Component component = (Component)components.elementAt(i);
+
+ int clipX = g.getClipX();
+ int clipY = g.getClipY();
+ int clipWidth = g.getClipWidth();
+ int clipHeight = g.getClipHeight();
+
+ for(int i = 0; i < components.size(); i++){
+ Component component = (Component)components.elementAt(i);
- //if((doFullRepaint || repaintComponent == component) && focusComponent != component){
-
- int cx=component.getX();
- int cy=component.getY();
-
- g.translate(cx,cy );
-
- component.paint(g);
-
- g.translate(-cx, -cy);
- //}
- }
+ int rx = component.getXWithBorder();
+ int ry = component.getYWithBorder();
+
+ if (!(rx>clipX+clipWidth || ry >clipY+clipHeight || rx+component.getWidthWithBorder()<clipX || ry+component.getHeightWithBorder()<clipY)) {
+
+ int cx=component.getX();
+ int cy=component.getY();
+
+ g.translate(cx,cy );
+ component.paint(g);
+ g.translate(-cx, -cy);
+ }
+ //else {
+ // System.out.println("Wont paint "+component);
+ //}
+
+ }
}
// does nothing, but can be overridden
@@ -230,7 +236,9 @@
}
else if (newone instanceof Panel) {
- ((Panel)newone).breakOutAction(null,direction,scrolltothere);
+ ((Panel)newone).breakOutAction(null,direction,false);
+ // here we do NOT pass scrolltothere onto the child panel
+ // dont scroll if we go to a child, only scroll if we hit a parent
}
else if (newone!=component) {// this is just a check so it cant go into a infinite loop
@@ -287,44 +295,43 @@
public boolean repaintComponent(Graphics g, Component focusComponent) {
- for(int i = 0; i < components.size(); i++){
- Component component = (Component)components.elementAt(i);
+ for(int i = 0; i < components.size(); i++){
+ Component component = (Component)components.elementAt(i);
- int x=component.getX();
- int y=component.getY();
-
- if (component == focusComponent){
+ int x=component.getX();
+ int y=component.getY();
- g.translate(x,y);
- component.paint(g);
- g.translate(-x,-y);
-
- return true;
- }
- else if (component instanceof Panel){
-
- g.translate(x,y);
- boolean good = ((Panel)component).repaintComponent(g,focusComponent);
- g.translate(-x,-y);
-
- if (good) { return good; }
- }
- }
+ if (component == focusComponent){
+
+ g.translate(x,y);
+ component.paint(g);
+ g.translate(-x,-y);
+
+ return true;
+ }
+ else if (component instanceof Panel){
+
+ g.translate(x,y);
+ boolean good = ((Panel)component).repaintComponent(g,focusComponent);
+ g.translate(-x,-y);
+
+ if (good) { return good; }
+ }
+ }
return false;
}
public void removeAll() {
-
- // TODO not recursive
+
for(int i = 0; i < components.size(); i++){
- Component component = (Component)components.elementAt(i);
+ Component component = (Component)components.elementAt(i);
if (component.getOwner() == owner) {
component.setOwnerAndParent(null,null);
}
}
components.removeAllElements();
-
+ constraints.clear();
}
public void setName(String n) {
Modified: SwingME/src/net/yura/mobile/gui/components/ScrollPane.java
===================================================================
--- SwingME/src/net/yura/mobile/gui/components/ScrollPane.java 2008-07-09 12:18:14 UTC (rev 23)
+++ SwingME/src/net/yura/mobile/gui/components/ScrollPane.java 2008-07-09 14:56:51 UTC (rev 24)
@@ -120,34 +120,6 @@
a.setScrollPanel(null);
}
- //public void setOwner(MPanel owner){
- // super.setOwner(owner);
- //
- // component.setOwner(owner);
- //}
-
- public boolean makeVisible(Component newone,boolean smartscroll) {
-
- if (getComponent().getHeight() > getHeight() ||
- getComponent().getWidth() > getWidth()
- ) {
-
- return makeVisible(
- newone.getXWithBorder(),
- newone.getYWithBorder(),
- newone.getWidthWithBorder(),
- newone.getHeightWithBorder(),
- smartscroll
- );
- }
-
- // everything is ok and we dont have to scroll
- return true;
-
- }
-
-
-
public boolean makeVisible(int x,int y,int w,int h,boolean smartscroll) {
Component component = getComponent();
@@ -171,24 +143,31 @@
int viewHeight = getViewPortHeight();
int viewWidth = getViewPortWidth(viewHeight);
+ // check if the viewport is maybe already looks at part of this bigger area
+ // if it is, then we dont want to scroll to any part of it
+ if (!(x<=componentX+viewX && right>=componentX+viewX+viewWidth)) {
+ if (right > (viewX + componentX + viewWidth)){
+ componentX = right - viewWidth;
+ }
+
+ if (x < (viewX + componentX)){
+ componentX = x-viewX;
+ }
+ }
+
+ if (!(y<=componentY+viewY && bottom>=componentY+viewY+viewHeight)) {
+ if (bottom > (viewY + componentY + viewHeight)){
+ componentY = bottom - viewHeight;
+ }
+
+ if (y < (viewY + componentY)){
+ componentY = y-viewY;
+ }
+ }
+
+
- if (right > (viewX + componentX + viewWidth)){
- componentX = right - viewWidth;
- }
-
- if (bottom > (viewY + componentY + viewHeight)){
- componentY = bottom - viewHeight;
- }
-
- if (x < (viewX + componentX)){
- componentX = x-viewX;
- }
-
- if (y < (viewY + componentY)){
- componentY = y-viewY;
- }
-
// check we r not scrolling off the content panel
if ((viewX+componentX+viewWidth)>component.getWidth()) { componentX=component.getWidth()-viewWidth-viewX; }
if ((viewY+componentY+viewHeight)>component.getHeight()) { componentY=component.getHeight()-viewHeight-viewY; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|