Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/microedition/lcdui/Displayable.java


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