1 2 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 34 Vector commands = new Vector(); 35 CommandListener listener = null; 36 37 38 public void addCommand(Command cmd) 39 { 40 for (int i=0; i<commands.size(); i++) { 42 if (cmd == (Command)commands.elementAt(i)) { 43 return; 45 } 46 } 47 48 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 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 |