KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > microedition > lcdui > Displayable


1
2 /*
3  * MicroEmulator
4  * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20  
21 package javax.microedition.lcdui;
22
23 import java.util.Vector;
24
25
26 public abstract class Displayable
27 {
28
29     Display currentDisplay = null;
30
31     /**
32      * @associates Command
33      */

34     Vector commands = new Vector();
35     CommandListener listener = null;
36
37
38     public void addCommand(Command cmd)
39     {
40     // Check that its not the same command
41
for (int i=0; i<commands.size(); i++) {
42       if (cmd == (Command)commands.elementAt(i)) {
43         // Its the same just return
44
return;
45             }
46         }
47
48     // Now insert it in order
49
boolean inserted = false;
50     for (int i=0; i<commands.size(); i++) {
51       if (cmd.getPriority() < ((Command)commands.elementAt(i)).getPriority()) {
52         commands.insertElementAt(cmd, i);
53         inserted = true;
54         break;
55       }
56     }
57     if (inserted == false) {
58       // Not inserted just place it at the end
59
commands.addElement(cmd);
60     }
61
62         if (isShown()) {
63             currentDisplay.updateCommands();
64         }
65     }
66
67
68     public void removeCommand(Command cmd)
69     {
70         commands.removeElement(cmd);
71
72         if (isShown()) {
73             currentDisplay.updateCommands();
74         }
75     }
76
77
78     public boolean isShown()
79     {
80         if (currentDisplay == null) {
81             return false;
82         }
83         return currentDisplay.isShown(this);
84     }
85
86
87     public void setCommandListener(CommandListener l)
88     {
89         listener = l;
90     }
91
92
93     CommandListener getCommandListener()
94     {
95         return listener;
96     }
97
98
99     Vector getCommands()
100     {
101         return commands;
102     }
103
104
105     void hideNotify()
106     {
107     }
108
109
110     final void hideNotify(Display d)
111     {
112         hideNotify();
113     }
114
115
116     void keyPressed(int keyCode)
117     {
118     }
119
120
121     void keyReleased(int keyCode)
122     {
123     }
124
125
126     abstract void paint(Graphics g);
127
128
129     void repaint()
130     {
131         if (currentDisplay != null) {
132             currentDisplay.repaint(this);
133         }
134     }
135
136
137     void showNotify()
138     {
139     }
140
141
142     final void showNotify(Display d)
143     {
144         currentDisplay = d;
145         showNotify();
146     }
147
148 }
149
Popular Tags