View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2005 Andres Navarro
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package javax.microedition.lcdui;
21  
22  public abstract class CustomItem extends Item {
23  	protected static final int TRAVERSE_HORIZONTAL = 1;
24  	protected static final int TRAVERSE_VERTICAL = 2;
25  	protected static final int KEY_PRESS = 4;
26  	protected static final int KEY_RELEASE = 8;
27  	protected static final int KEY_REPEAT = 0x10;
28  	protected static final int POINTER_PRESS = 0x20;
29  	protected static final int POINTER_RELEASE = 0x40;
30  	protected static final int POINTER_DRAG = 0x80;
31  	protected static final int NONE = 0x00;
32  
33  	protected CustomItem(String label) {
34  		super(label);
35  	}
36  	
37  	public int getGameAction(int keycode) {
38  		// TODO add support for keypress
39  		return 0;
40  	}
41  	
42  	protected final int getInteractionModes() {
43  		// TODO add support for aditional interaction modes
44  		return NONE;
45  	}
46  	
47  	protected abstract int getMinContentHeight();
48  	
49  	protected abstract int getMinContentWidth();
50  	
51  	protected abstract int getPrefContentHeight(int width);
52  
53  	protected abstract int getPrefContentWidth(int height);
54  
55  	protected void hideNotify() {
56  		// the default implementation of this method
57  		// does nothing
58  	}
59  	
60  	protected final void invalidate() {
61  		repaintOwner();
62  	}
63  
64  	protected void keyPressed(int keyCode) {
65  		// the default implementation of this method
66  		// does nothing
67  	}
68  	
69  	protected void keyReleased(int keyCode) {
70  		// the default implementation of this method
71  		// does nothing
72  	}
73  
74  	protected void keyRepeated(int keyCode) {
75  		// the default implementation of this method
76  		// does nothing
77  	}
78  	
79  	protected abstract void paint(Graphics g, int w, int h);
80  
81  	protected void pointerDragged(int x, int y) {
82  		// the default implementation of this method
83  		// does nothing
84  	}
85  
86  	protected void pointerPressed(int x, int y) {
87  		// the default implementation of this method
88  		// does nothing
89  	}
90  	
91  	protected void pointerReleased(int x, int y) {
92  		// the default implementation of this method
93  		// does nothing
94  	}
95  	
96  	protected final void repaint() {
97  		super.repaint();
98  	}
99  
100 	protected final void repaint(int x, int y, int w, int h) {
101 		// TODO add support for partial repaint
102 		repaint();
103 	}
104 	
105 	protected void showNotify() {
106 		// the default implementation of this method
107 		// does nothing
108 	}
109 
110 	protected void sizeChanged(int w, int h) {
111 		// the default implementation of this method
112 		// does nothing
113 	}
114 	
115 	protected boolean traverse(int dir, int viewportWidth,
116             					int viewportHeight, int[] visRect_inout) {
117 		// the default implementation of this method
118 		// does nothing
119 		return false;
120 	}
121 
122 	protected void traverseOut() {
123 		// the default implementation of this method
124 		// does nothing
125 	}
126 
127 	
128 	// Item methods
129 	
130 	int paint(Graphics g) {
131 		// TODO paint content!!!
132 		super.paintContent(g);
133 		return super.getHeight();
134 	}
135 	
136 	// TODO write overrides for getMinimumWidth, etc
137 }