1. Java Rosa
  2. javarosa-pending

Commits

csims  committed 658e68c

[r6] [JavaProtocolSupport] Added a huge level of structure to the Custom UI elements.

  • Participants
  • Parent commits 1e0afb7
  • Branches default

Comments (0)

Files changed (6)

File src/org/dimagi/view/Component.java

View file
+package org.dimagi.view;
+
+import java.util.Vector;
+
+import javax.microedition.lcdui.Graphics;
+
+import org.dimagi.utils.ViewUtils;
+
+import de.enough.polish.util.VectorIterator;
+
+public class Component {
+	
+	protected Vector _components = new Vector();
+	
+	protected Vector _sizeChangedListeners = new Vector();
+	
+	protected int _x;
+	protected int _y;
+	
+	protected int _width;
+	protected int _height;
+	
+	protected int _backgroundColor = ViewUtils.TRANSPARENT;
+	
+	public void add(Component c) {
+		_components.addElement(c);
+	}
+	
+	public void setX(int x) {
+		_x = x;
+	}
+	
+	public void setY(int y) {
+		_y = y;
+	}
+	
+	public void setWidth(int width) {
+		_width = width;
+		refresh();
+		fireSizeChangedListeners();
+	}
+	
+	public void setHeight(int height) {
+		_height = height;
+		refresh();
+		fireSizeChangedListeners();
+	}
+	
+	public void resizeSelfOptimally() {
+		
+	}
+	
+	public void setBackgroundColor(int backgroundColor) {
+		_backgroundColor = backgroundColor;
+	}
+	
+	public int getWidth() {
+		return _width;
+	}
+
+	public int getHeight() {
+		return _height;
+	}
+	
+	public int getX() {
+		return _x;
+	}
+	
+	public int getY() {
+		return _y;
+	}
+	
+	public int getBackgroundColor() {
+		return _backgroundColor;
+	}
+	
+	public void addSizeChangeListener(ISizeChangeListener l) {
+		_sizeChangedListeners.addElement(l);
+	}
+	
+	private void fireSizeChangedListeners() {
+		VectorIterator iter = new VectorIterator(_sizeChangedListeners);
+		while(iter.hasNext()) {
+			ISizeChangeListener listener = (ISizeChangeListener)iter.next();
+			
+			listener.sizeChanged();
+			
+		}
+	}
+	
+	public void removeSizeChangeListener(ISizeChangeListener l) {
+		_sizeChangedListeners.removeElement(l);
+	}
+	
+	public void draw(Graphics g) {
+		g.translate(_x,_y);	
+		if(_backgroundColor != ViewUtils.TRANSPARENT){
+			g.setColor(_backgroundColor);
+			g.fillRect(0, 0, _width, _height);
+		}	
+		drawInternal(g);
+		VectorIterator iter = new VectorIterator(_components);
+		while(iter.hasNext()) {
+			Component component = (Component)iter.next();
+			
+			component.draw(g);
+		}
+		g.translate(-_x, -_y);
+	}
+	
+	public void drawInternal(Graphics g){}
+	
+	public void refresh() {}
+}

File src/org/dimagi/view/DButton.java

View file
+package org.dimagi.view;
+
+import javax.microedition.lcdui.Graphics;
+
+import org.dimagi.utils.ViewUtils;
+
+public class DButton extends Component {
+	
+	private String _text;
+	
+	public DButton(String text) {
+		_text = text;
+	}
+	
+
+	public void drawInternal(Graphics g) {
+		//Finish by drawing the border	
+		g.setColor(ViewUtils.BLACK);
+		int buffer = g.getFont().getHeight()/3;
+		
+		int textY = this.getHeight()/2 - g.getFont().getHeight()/2; 
+		
+		g.drawString(_text,this.getWidth()/2,textY,Graphics.TOP |Graphics.HCENTER);
+		
+		//Finish by drawing the border
+		g.setColor(ViewUtils.BLACK);
+		g.drawRect(0, 0, _width, _height);
+	}
+}

File src/org/dimagi/view/DProgressBar.java

View file
+package org.dimagi.view;
+
+import javax.microedition.lcdui.Graphics;
+
+import org.dimagi.utils.ViewUtils;
+
+public class DProgressBar extends Component {
+
+	int _progress;
+	int _capacity;
+	
+	public DProgressBar(int capacity) {
+		_capacity = capacity;
+	}
+	
+	public void setProgress(int progress) {
+		_progress = progress;
+		refresh();
+	}
+	
+	public void setCapacity(int capacity) {
+		_capacity = capacity;
+		refresh();
+	}
+
+	public void drawInternal(Graphics g) {
+		//Draw the Background
+		g.setColor(ViewUtils.LIGHT_GREY);
+		g.fillRect(0, 0, _width, _height);
+		
+		//Draw the amount filled
+		int filledWidth = (_width*_progress)/_capacity;
+		
+		g.setColor(ViewUtils.PINK_GREY);
+		g.fillRect(0,0,filledWidth,_height);
+		
+		//Finish by drawing the border
+		g.setColor(ViewUtils.BLACK);
+		g.drawRect(0, 0, _width, _height);
+	}
+	
+	public void refresh() {
+		
+	}
+
+}

File src/org/dimagi/view/ISizeChangeListener.java

View file
+package org.dimagi.view;
+
+public interface ISizeChangeListener {
+	
+	public void sizeChanged();
+}

File src/org/dimagi/view/NavBar.java

View file
+package org.dimagi.view;
+
+import org.dimagi.utils.ViewUtils;
+
+public class NavBar extends Component implements ISizeChangeListener {
+	DProgressBar progressBar = new DProgressBar(100);
+	
+	DButton backButton = new DButton("Back");
+	DButton nextButton = new DButton("Next");
+	
+	public NavBar() {
+		setupComponents();
+		this.addSizeChangeListener(this);
+	}
+	
+	private void setupComponents() {
+		backButton.setBackgroundColor(ViewUtils.LIGHT_GREY);
+		nextButton.setBackgroundColor(ViewUtils.LIGHT_GREY);
+		this.add(progressBar);
+		this.add(backButton);
+		this.add(nextButton);
+	}
+	
+	public void sizeChanged() {
+		int yBuffer = this.getHeight()/5;
+		progressBar.setWidth(this.getWidth()/2);
+		progressBar.setHeight(this.getHeight() - yBuffer);
+		progressBar.setY(yBuffer/2);
+		progressBar.setX(this.getWidth()/4);
+		
+		backButton.setWidth(this.getWidth()/5);
+		backButton.setHeight(this.getHeight() - yBuffer);
+		backButton.setY(yBuffer/2);
+		backButton.setX(this.getWidth()/7 - backButton.getWidth()/2);
+		
+		nextButton.setWidth(this.getWidth()/5);
+		nextButton.setHeight(this.getHeight() - yBuffer);
+		nextButton.setY(yBuffer/2);
+		nextButton.setX(6*this.getWidth()/7 - backButton.getWidth()/2);
+	}
+}

File src/org/dimagi/view/Widget.java

View file
+package org.dimagi.view;
+
+public abstract class Widget extends Component {
+
+	
+}