Methods Summary |
---|
public void | addCommand(Command cmd)Adds a command to the Displayable . The
implementation may choose,
for example,
to add the command to any of the available soft buttons or place it
in a menu.
If the added command is already in the screen (tested by comparing the
object references), the method has no effect.
If the Displayable is actually visible on the
display, and this call
affects the set of visible commands, the implementation should update
the display as soon as it is feasible to do so.
if (cmd == null) {
throw new NullPointerException();
}
synchronized (Display.LCDUILock) {
addCommandImpl(cmd);
}
|
void | addCommandImpl(Command cmd)Add a Command to this Displayable
for (int i = 0; i < numCommands; ++i) {
if (commands[i] == cmd) {
return;
}
}
if ((commands == null) || (numCommands == commands.length)) {
Command[] newCommands = new Command[numCommands + 4];
if (commands != null) {
System.arraycopy(commands, 0, newCommands, 0, numCommands);
}
commands = newCommands;
}
commands[numCommands] = cmd;
++numCommands;
updateCommandSet();
|
void | callHideNotify(Display d)Notify this Displayable it is being hidden on the given Display
synchronized (Display.LCDUILock) {
currentDisplay = null;
stopTicker();
}
|
void | callInvalidate(Item src)Called by the event handler to perform an
invalidation of this Displayable
|
void | callItemStateChanged(Item src)Called by the event handler to notify any ItemStateListener
of a change in the given Item
|
void | callKeyPressed(int keyCode)Handle a key press
|
void | callKeyReleased(int keyCode)Handle a key release
|
void | callKeyRepeated(int keyCode)Handle a repeated key press
|
void | callKeyTyped(char c)Handle a key that was typed from the keyboard
|
void | callPaint(Graphics g, java.lang.Object target)Display calls this method on it's current Displayable.
Displayable uses this oppportunity to do necessary stuff
on the Graphics context, this includes,
paint Ticker, paint Title, translate as necessary.
The target Object of this repaint may be some Object
initially set by this Displayable when the repaint was
requested - allowing this Displayable to know exactly
which Object it needs to call to service this repaint,
rather than potentially querying all of its Objects to
determine the one(s) which need painting.
SYNC NOTE: The caller of this method handles synchronization.
/*
System.err.println("Displayable:Clip: " +
g.getClipX() + "," + g.getClipY() + "," +
g.getClipWidth() + "," + g.getClipHeight());
*/
synchronized (Display.LCDUILock) {
if (!(fullScreenMode || (title == null && ticker == null))) {
if (g.getClipY() < totalHeight) {
// We always paint "something" for the ticker, rather
// than make the title paint more complicated. If there
// is no ticker, we draw the darkgray/white saparator line
if (g.getClipY() < tickerHeight) {
paintTicker(g);
}
if (title != null) {
if (g.getClipY() + g.getClipHeight() >
totalHeight - tickerHeight + 1) {
g.translate(0, tickerHeight);
paintTitle(g);
g.translate(0, -tickerHeight);
}
}
}
} else {
g.setColor(Item.DARK_GRAY_COLOR);
g.drawLine(0, 0, Display.WIDTH, 0);
g.setColor(Display.FG_COLOR);
}
} // synchronized
|
void | callPointerDragged(int x, int y)Handle a pointer drag event
|
void | callPointerPressed(int x, int y)Handle a pointer press event
|
void | callPointerReleased(int x, int y)Handle a pointer release event
|
final void | callRepaint(int x, int y, int width, int height, java.lang.Object target)Repaint this Displayable
if (currentDisplay != null) {
// Note: Display will not let anyone but the current
// Displayable schedule repaints
currentDisplay.repaintImpl(paintDelegate, x, y, width, height,
target);
}
|
final void | callRepaint()Repaints this Displayable.
This is the same as calling
callRepaint(0, 0,
viewport[X] + viewport[WIDTH],
viewport[Y] + viewport[HEIGHT], null)
callRepaint(0, 0,
viewport[X] + viewport[WIDTH],
viewport[Y] + viewport[HEIGHT], null);
|
void | callShowNotify(Display d)Notify this Displayable it is being shown on the given Display
synchronized (Display.LCDUILock) {
currentDisplay = d;
// call grab full screen to let the native
// layer know whether to be in
// fullscreen or normal mode.
grabFullScreen(fullScreenMode);
if (sizeChangeOccurred) {
callSizeChanged(viewport[WIDTH], viewport[HEIGHT]);
}
// display the ticker if we have a visible one.
startTicker();
}
|
void | callSizeChanged(int w, int h)Package private equivalent of sizeChanged()
// If there is no Display, or if this Displayable is not
// currently visible, we simply record the fact that the
// size has changed
sizeChangeOccurred =
(currentDisplay == null) || (!currentDisplay.isShown(this));
|
boolean | commandInSetImpl(Command command)Decide if the given Command has been added to this
Displayable's set of abstract commands.
for (int i = 0; i < numCommands; i++) {
if (commands[i] == command) {
return true;
}
}
return false;
|
void | commitPendingInteraction()Called to commit any pending user interaction
|
void | fullScreenMode(boolean onOff)Set the full screen mode of this Displayable. If true,
this Displayable will take up as much screen real estate
as possible
if (fullScreenMode == onOff) {
return;
}
fullScreenMode = onOff;
layout();
updateCommandSet();
callSizeChanged(viewport[WIDTH], viewport[HEIGHT]);
callRepaint();
if (fullScreenMode) {
stopTicker();
} else {
startTicker();
}
|
int | getCommandCount()Get the number of commands that have been added to this Displayable
return numCommands;
|
CommandListener | getCommandListener()Get the CommandListener for this Displayable
return listener;
|
Command[] | getCommands()Get the set of Commands that have been added to this Displayable
return commands;
|
Item | getCurrentItem()Gets item currently in focus. This is will be only applicable to
Form. The rest of the subclasses will return null.
return null;
|
public int | getHeight()Gets the height in pixels of the displayable area available to the
application. The value returned is appropriate for the particular
Displayable subclass. This value may depend
on how the device uses the
display and may be affected by the presence of a title, a ticker, or
commands.
This method returns the proper result at all times, even if the
Displayable object has not yet been shown.
// SYNC NOTE: return of atomic value
return viewport[HEIGHT];
|
public Ticker | getTicker()Gets the ticker used by this Displayable .
// SYNC NOTE: return of atomic value, no locking necessary
return ticker;
|
public java.lang.String | getTitle()Gets the title of the Displayable . Returns
null if there is no title.
// SYNC NOTE: return of atomic value, no lock necessary
return title;
|
int | getVerticalScrollPosition()Get the current vertical scroll position
// SYNC NOTE: return of atomic value
return vScrollPosition;
|
int | getVerticalScrollProportion()Get the current vertical scroll proportion
// SYNC NOTE: return of atomic value
return vScrollProportion;
|
public int | getWidth()Gets the width in pixels of the displayable area available to the
application. The value returned is appropriate for the particular
Displayable subclass. This value may depend
on how the device uses the
display and may be affected by the presence of a title, a ticker, or
commands.
This method returns the proper result at all times, even if the
Displayable object has not yet been shown.
// SYNC NOTE: return of atomic value
return viewport[WIDTH];
|
native void | grabFullScreen(boolean mode)Grabs the requested area of the display
|
void | invalidate(Item src)Called to schedule an "invalidate" for this Displayable. Invalidation
is caused by things like size changes, content changes, or spontaneous
traversal within the Item
Display d = currentDisplay;
if (d != null) {
d.invalidate(src);
}
|
public boolean | isShown()Checks if the Displayable is actually visible
on the display. In order
for a Displayable to be visible, all of the
following must be true:
the Display's MIDlet must be
running in the foreground, the Displayable
must be the Display's current screen, and the
Displayable must not be
obscured by a
system screen.
synchronized (Display.LCDUILock) {
return (currentDisplay == null) ?
false : currentDisplay.isShown(this);
}
|
void | itemStateChanged(Item src)Called to schedule a call to itemStateChanged() due to
a change in the given Item.
Display d = currentDisplay;
if (d != null) {
d.itemStateChanged(src);
}
|
void | layout()Perform any necessary layout, and update the viewport
as necessary
setupViewport();
translateViewport();
|
void | paintTicker(Graphics g)Paint the ticker if it exists, on this graphics object.
// paint the ticker here.
if (ticker != null) {
ticker.paintContent(g);
} else if (title != null) {
g.setColor(Item.DARK_GRAY_COLOR);
g.drawLine(0, 0, Display.WIDTH, 0);
g.setColor(Display.ERASE_COLOR);
g.drawLine(0, 1, Display.WIDTH, 1);
g.setColor(Display.FG_COLOR);
}
|
void | paintTitle(Graphics g)Paints the title of this Displayable, including it's border.
The graphics context is then translated by the height occupied
by the title area.
g.setColor(Item.LIGHT_GRAY_COLOR);
g.fillRect(0, 0, Display.WIDTH, TITLE_HEIGHT - 1);
g.setColor(Display.FG_COLOR);
Text.paint(title, TITLE_FONT, g, Display.WIDTH,
TITLE_HEIGHT, 1, Text.NORMAL, null);
g.setColor(Item.DARK_GRAY_COLOR);
g.drawLine(0, TITLE_HEIGHT - 1, Display.WIDTH, TITLE_HEIGHT - 1);
g.setColor(Display.FG_COLOR);
|
public void | removeCommand(Command cmd)Removes a command from the Displayable .
If the command is not in the Displayable
(tested by comparing the
object references), the method has no effect.
If the Displayable is actually visible on the
display, and this call
affects the set of visible commands, the implementation should update
the display as soon as it is feasible to do so.
If cmd is null , this method
does nothing.
synchronized (Display.LCDUILock) {
removeCommandImpl(cmd);
}
|
void | removeCommandImpl(Command cmd)Remove a Command from this Displayable
for (int i = 0; i < numCommands; ++i) {
if (commands[i] == cmd) {
commands[i] = commands[--numCommands];
commands[numCommands] = null;
updateCommandSet();
break;
}
}
|
final void | repaintContents()Repaint the viewport region of this Displayable
callRepaint(viewport[X], viewport[Y],
viewport[WIDTH], viewport[HEIGHT], null);
|
private void | repaintTickerText()Paints the ticker's text area.
if (currentDisplay != null &&
currentDisplay.isShown(paintDelegate)) {
currentDisplay.repaintImpl(paintDelegate, 0,
Ticker.DECORATION_HEIGHT,
viewport[WIDTH], Screen.CONTENT_HEIGHT,
ticker);
}
|
private void | repaintTitle()Repaint the title area.
if (currentDisplay != null) {
currentDisplay.repaintImpl(paintDelegate, 0,
(ticker != null)
? Ticker.PREFERRED_HEIGHT
: 2,
viewport[WIDTH], TITLE_HEIGHT, title);
}
|
public void | setCommandListener(CommandListener l)Sets a listener for {@link Command Commands} to this
Displayable ,
replacing any previous CommandListener . A
null reference is
allowed and has the effect of removing any existing listener.
synchronized (Display.LCDUILock) {
listener = l;
}
|
public void | setTicker(Ticker ticker)Sets a ticker for use with this Displayable ,
replacing any
previous ticker.
If null , removes the ticker object
from this Displayable . The same ticker may be shared by
several Displayable
objects within an application. This is done by calling
setTicker()
with the same Ticker object on several
different Displayable objects.
If the Displayable is actually visible on the display,
the implementation should update
the display as soon as it is feasible to do so.
The existence of a ticker may affect the size
of the area available for Displayable's contents.
Addition, removal, or the setting of the ticker at runtime
may dynamically change the size of the content area.
This is most important to be aware of when using the
Canvas class.
If the available area does change, the application will be notified
via a call to {@link #sizeChanged(int, int) sizeChanged()}.
synchronized (Display.LCDUILock) {
setTickerImpl(ticker);
}
|
void | setTickerImpl(Ticker t)Set the ticker for this Displayable
// Return early if there's nothing to do
if (this.ticker == t) {
return;
}
Ticker oldTicker = this.ticker;
this.ticker = t;
// CASES:
// 1. Had an invisible non-null ticker, setting a null ticker
// - We need to set the new ticker. There's no need to re-layout
// or start the new ticker
// 2. Had an invisible non-null ticker, setting a non-null ticker
// - We need to set the new ticker. There's no need to re-layout
// or start the new ticker
// 3. Had a visible non-null ticker, setting a null ticker
// - We need to set the new ticker and re-layout. There's no
// need to start the new ticker.
// 4. Had a null ticker, setting a visible non-null ticker
// - We need to set the new ticker, re-layout, and
// start up the new ticker
// 5. Had a visible non-null ticker, setting a non-null ticker
// - We need to set the new ticker. There's no need to re-layout
boolean sizeChange =
((oldTicker != null) && (ticker == null)) ||
((oldTicker == null) && (ticker != null));
if (sizeChange) {
if (ticker != null) {
ticker.reset();
startTicker();
} else {
stopTicker();
}
layout();
callSizeChanged(viewport[WIDTH], viewport[HEIGHT]);
callRepaint();
} else {
ticker.reset();
}
|
public void | setTitle(java.lang.String s)Sets the title of the Displayable . If
null is given,
removes the title.
If the Displayable is actually visible on
the display,
the implementation should update
the display as soon as it is feasible to do so.
The existence of a title may affect the size
of the area available for Displayable content.
Addition, removal, or the setting of the title text at runtime
may dynamically change the size of the content area.
This is most important to be aware of when using the
Canvas class.
If the available area does change, the application will be notified
via a call to {@link #sizeChanged(int, int) sizeChanged()}.
synchronized (Display.LCDUILock) {
setTitleImpl(s);
}
|
void | setTitleImpl(java.lang.String s)Package private unsynchronized version of setTitle(String)
if (title == s || (title != null && title.equals(s))) {
return;
}
String oldTitle = this.title;
this.title = s;
if (fullScreenMode) {
return;
}
boolean sizeChange =
((oldTitle != null) && (title == null)) ||
((oldTitle == null) && (title != null));
if (sizeChange) {
layout();
callSizeChanged(viewport[WIDTH], viewport[HEIGHT]);
callRepaint();
} else {
repaintTitle();
}
|
void | setVerticalScroll(int scrollPosition, int scrollProportion)Set the vertical scroll position and proportion
synchronized (Display.LCDUILock) {
this.vScrollPosition = scrollPosition;
this.vScrollProportion = scrollProportion;
if (currentDisplay != null) {
currentDisplay.setVerticalScroll(scrollPosition,
scrollProportion);
}
}
|
private void | setupViewport()By default, the viewport array is configured to be
at origin 0,0 with width Display.WIDTH and height
either Display.HEIGHT or Display.ADORNEDHEIGHT, depending
on full screen mode.
// setup the default viewport, the size of the Display
if (viewport == null) {
viewport = new int[4];
}
viewport[X] =
viewport[Y] = 0;
viewport[WIDTH] = Display.WIDTH;
viewport[HEIGHT] = (fullScreenMode)
? Display.HEIGHT
: Display.ADORNEDHEIGHT;
|
private boolean | sizeChangeImpl()This method is called from showNotify(Display )
It checks if a size change has occurred since the last time
a size change occurred or since the object was constructed.
If a size change has occurred, it calls callSizeChanged()
for package private handling of size change events, and returns true,
else returns false.
boolean flag = sizeChangeOccurred;
sizeChangeOccurred = false;
if (flag) {
callSizeChanged(viewport[WIDTH], viewport[HEIGHT]);
}
return flag;
|
protected void | sizeChanged(int w, int h)The implementation calls this method when the available area of the
Displayable has been changed.
The "available area" is the area of the display that
may be occupied by
the application's contents, such as Items in a
Form or graphics within
a Canvas . It does not include space occupied
by a title, a ticker,
command labels, scroll bars, system status area, etc. A size change
can occur as a result of the addition, removal, or changed contents of
any of these display features.
This method is called at least once before the
Displayable is shown for the first time.
If the size of a Displayable changes while
it is visible,
sizeChanged will be called. If the size of a
Displayable
changes while it is not visible, calls to
sizeChanged may be deferred. If the size had changed
while the Displayable was not visible,
sizeChanged will be
called at least once at the time the
Displayable becomes visible once
again.
The default implementation of this method in Displayable
and its
subclasses defined in this specification must be empty.
This method is intended solely for being overridden by the
application. This method is defined on Displayable
even though applications are prohibited from creating
direct subclasses of Displayable .
It is defined here so that applications can override it in
subclasses of Canvas and Form .
This is useful for Canvas subclasses to tailor
their graphics and for Forms to modify
Item sizes and layout
directives in order to fit their contents within the the available
display area.
// this method is intended to be overridden by the application
|
private void | startTicker()Starts the "ticking" of the ticker.
if (ticker == null || fullScreenMode) {
return;
}
stopTicker();
tickerPainter = new TickerPainter();
tickerTimer.schedule(tickerPainter, 0, Ticker.TICK_RATE);
|
private void | stopTicker()Stop the ticking of the ticker.
if (tickerPainter == null) {
return;
}
tickerPainter.cancel();
tickerPainter = null;
|
private void | translateViewport()Translate the viewport for any decorations by this Displayable
such as a title or ticker
if (!(fullScreenMode || (title == null && ticker == null))) {
//
// determine the right tickerHeight
//
if (ticker != null) {
tickerHeight = Ticker.PREFERRED_HEIGHT;
} else {
if (title != null) {
tickerHeight = 2;
} else {
tickerHeight = 0;
}
}
//
// add to any title height
//
totalHeight = (title != null)
? TITLE_HEIGHT + tickerHeight
: tickerHeight;
} else {
//
// in fullscreen, or with no title or ticker we have
// a single dark line under the status bar
//
totalHeight = 1;
}
viewport[Y] += totalHeight;
viewport[HEIGHT] -= totalHeight;
|
void | updateCommandSet()Updates command set if this Displayable is visible
// SYNC NOTE: Display requires calls to updateCommandSet to
// be synchronized
synchronized (Display.LCDUILock) {
if ((currentDisplay != null) && currentDisplay.isShown(this)) {
currentDisplay.updateCommandSet();
}
}
|