📄 bluedumpgui.java
字号:
//------------------------------------------------------------------
//Copyright (c) 2004 Jyperion SARL
// France
//
//This software is provided "AS IS," without a warranty of any kind.
//ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
//INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
//PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
//
//------------------------------------------------------------------
package example.bluetooth.dump;
import javax.microedition.lcdui.*;
import java.io.IOException;
import java.util.*;
/**
* Be in charge of the Graphic User Interface
* This canvas will display all the messages from the Vector data structure
*
* @author Guillaume Compagnon
*
*/
public class BlueDumpGUI extends Canvas {
/** maximum number of messages lines to be displayed
* in order not to overflow the memory with too much messages
*/
public static final int MAX_MESSAGES = 100;
public static final Integer RED = new Integer(0xFF0000);
public static final Integer BLACK = new Integer(0x000000);
public static final Integer BLUE = new Integer(0x0000FF);
/** List of messages to be displayed */
Vector messages;
/** List of the color for each messages */
Vector messagesColors;
/** pointer to the first message that will be displayed, as the last should always be on the screen */
int pointer = 0;
/**
* graphic width and height of the screen
*/
int width, height;
/** font used to write on the screen */
Font font;
/** font height */
int fontHeight;
Image screen;
Image connectImage;
Image connectingImage;
Image disconnectImage;
private int iconWidth;
private int iconHeight;
int x0=0, y0=0;
public BlueDumpGUI()
{
width = getWidth();
height = getHeight();
font = Font.getFont( Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL );
fontHeight = font.getHeight();
// Create off-screen image and paint it white.
screen = Image.createImage(width , height);
messages = new Vector(MAX_MESSAGES*height / fontHeight);
messagesColors = new Vector(MAX_MESSAGES*height / fontHeight);
// Create the icon images
try{
connectImage = Image.createImage("/images/connected.png");
disconnectImage = Image.createImage("/images/disconnected.png");
connectingImage = Image.createImage("/images/connecting.png");
iconHeight = connectImage.getHeight();
iconWidth = connectImage.getWidth();
}catch(IOException ioe){
BlueDump.display("Icons not found",RED);
BlueDump.fireExitAlert();
}
clearScreen(false);
}
/** paint method called by the device for the refresh of the screen */
protected void paint(Graphics g)
{
g.drawImage(screen, 0, 0, Graphics.TOP|Graphics.LEFT);
// Draw status icon in upper left-hand corner based on state.
if (BlueDump.singleton.getState() == BlueDump.CONNECT && connectImage != null) {
g.drawImage(connectImage, 0, 0, Graphics.TOP|Graphics.LEFT);
}
else if (BlueDump.singleton.getState() == BlueDump.CONNECTING && connectingImage != null) {
g.drawImage(connectingImage, 0, 0, Graphics.TOP|Graphics.LEFT);
}
else if (disconnectImage != null) {
g.drawImage(disconnectImage, 0, 0, Graphics.TOP|Graphics.LEFT);
}
//
// detemine midx based on the screen height and number of message
/*
midx = msgs.size() - (h/fh) ;
if ( midx < 0 )
midx = 0;
*/
int y = fontHeight; // 1st line y value
// message will be rendered in black color, on top of white backgound
g.translate(-x0, -y0);
// render the messages on screen
for ( int i= 0; i< messages.size(); i++ )
{
String s = (String)messages.elementAt(i);
Integer color = (Integer)messagesColors.elementAt(i);
g.setColor(color.intValue());
g.drawString( s, iconWidth, y, Graphics.BASELINE | Graphics.LEFT );
y += fontHeight;
}
}
/** Listener method implementation for the key events on the Canvas */
public void keyPressed( int key )
{
if ( ( getGameAction( key ) == Canvas.RIGHT ) )//&&
//x0<0 )
{
x0+=20;
} else if ( getGameAction( key ) == Canvas.LEFT )
{
x0-=20;
} else if ( ( getGameAction( key ) == Canvas.UP ) &&
y0>0 )
{
y0-=fontHeight;
} else if ( ( getGameAction( key ) == Canvas.DOWN ) &&
y0 < (messages.size()*fontHeight) )
{
y0+=fontHeight;
}
repaint();
}
/**
* Clear the whole screen
*/
public void clearScreen(boolean repaint) {
// remove all stored messages
messages.removeAllElements();
messagesColors.removeAllElements();
Graphics g = screen.getGraphics();
// set RGB to maximum values, equivalent to the white colour
g.setColor( 0xFF, 0xFF, 0xFF );
g.fillRect( 0, 0, width, height );
// set RGB to maximum values, equivalent to the black colour
g.setColor(0);
g.setFont( font );
if (repaint) {
repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -