📄 thebox.java
字号:
int result = cur;
final int shift = direction ? 1 : -1 ;
final int size = storage.getSize();
result += shift;
if ( result == size ) { // if we were at the last message
result = 0; // move to the first one
// when we are at the first item there are no empty items
// at the previous items
empties = 0;
} else if ( result == -1 ) { // if we were at the first message
result = size - 1; // move to the last one (it cannot be empty message)
if ( storage instanceof ThreadedEmails ) {
// when we are at the last item (which cannot be empty), there
// are all empty items at the previous positions
empties = ((ThreadedEmails)storage).getEmptyRootsNumber();
}
}
return result;
}
/**
* Moves cursor with requested shift.
* It's needed to compute {@link #cur} and {@link #empties} too.
*
* @param direction defines the direction, there are just 2 possibilities
* down/up, so I chose boolean, <code>true</code> means move down
*/
public void shiftSelectedIndex( final boolean direction ) { //i is the offset from actual position
if (DEBUG) System.out.println( "DEBUG TheBox.shiftSelectedIndex(direction=" + direction + ")" );
final int size = storage.getSize();
final int shift = direction ? 1 : -1;
if ( size != 0 ) {
cur = moveCurrent(cur, direction);
// additional check is if the message we are at just now is empty
MessageHeader mh = storage.getMessageAt( cur );
while ( mh.isEmpty() ) {
empties += shift;
cur = moveCurrent(cur, direction);
mh = storage.getMessageAt( cur );
}
if (DEBUG) System.out.println( "DEBUG TheBox.shiftSelectedIndex(direction=" + direction + ") - cur=" + cur + ", empties=" + empties );
repaint();
}
}
protected void keyPressed(int keyCode) {
if (DEBUG) System.out.println( "DEBUG TheBox.keyPressed(keyCode=" + keyCode + ") - key name: " + getKeyName(keyCode) );
cancelTicker();
switch (keyCode) {
case '1':
markAsDeleted(getSelectedHeader());
return;
case '*':
eventListener.down();
return;
case '#':
eventListener.up();
return;
}
switch (getGameAction(keyCode)) {
case UP:
eventListener.upQuartersSlash();
break;
case DOWN:
eventListener.downQuartersStar();
break;
case LEFT:
eventListener.left();
break;
case FIRE:
eventListener.fire();
break;
}
repaint();
}
protected void keyRepeated(int keyCode) {
if (DEBUG) System.out.println( "DEBUG TheBox.keyRepeated(keyCode=" + keyCode + ") - key name: " + getKeyName(keyCode) );
/*
* This condition below is little hack :-/
* There was situation in which user pressed for example DOWN key, but
* from somewhere there was SELECT action generated (retrieved from
* DefaultEventHandler).
*
* If there will be problem in future with this method remove it, but
* I really like it O:-)
*
* Betlista
*/
final int gameAction = getGameAction(keyCode);
if ( gameAction == UP || gameAction == DOWN ) {
keyPressed(keyCode);
}
}
//#ifdef MUJMAIL_TOUCH_SCR
public void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
cancelTicker();
System.out.println("Pointer pressed: " + x + "; " + y);
pointerEventTransformer.pointerPressed(x, y);
}
//#endif
protected void hideButtons() {
if (!btnsHidden) {
removeCommand(deleteNow);
removeCommand(viewMessage);
removeCommand(delete);
removeCommand(empty);
removeCommand(sort);
removeCommand(seen);
removeCommand(flagged);
removeCommand(showHeader);
btnsHidden = true;
}
}
protected void showButtons() {
if (btnsHidden) {
addCommand(deleteNow);
addCommand(viewMessage);
addCommand(delete);
addCommand(empty);
addCommand(sort);
addCommand(seen);
addCommand(flagged);
addCommand(showHeader);
btnsHidden = false;
}
}
public void resort() {
cancelTicker();
if ( storage != null ) {
synchronized (storage) {
report(Lang.get(Lang.ALRT_SORTING) + Lang.get(Lang.ALRT_WAIT), SOURCE_FILE);
storage.sort( ComparatorStrategy.getStrategy().getComparator( ordering, criterion ) );
//Functions.sort(storage, (byte) (getSortMode() % 2), (byte) (getSortMode() >> 1));
}
}
cur = 0;
}
protected void hideNotify() {
cancelTicker(); //every time we lose focus, cancel the ticker
}
protected void drawIcons(MessageHeader mail, Graphics g, int x, int y) {
if ( mail.isEmpty() ) {
g.drawImage( imRoot, x, y + 3, Graphics.TOP | Graphics.LEFT );
} else if (mail.sendStatus == MessageHeader.REPLIED) {
g.drawImage(imAnswered, x, y + 3, Graphics.TOP | Graphics.LEFT);
} else if (mail.sendStatus == MessageHeader.FAILED_TO_SEND) {
g.drawImage(imFailedSent, x, y + 3, Graphics.TOP | Graphics.LEFT);
} else if (mail.sendStatus == MessageHeader.SENT) {
g.drawImage(imSent, x, y + 3, Graphics.TOP | Graphics.LEFT);
} else if (mail.readStatus == MessageHeader.READ) {
g.drawImage(imRead, x, y + 3, Graphics.TOP | Graphics.LEFT);
} else {
g.drawImage(imNormal, x, y + 3, Graphics.TOP | Graphics.LEFT);
}
if (mail.deleted) {
g.drawImage(imDeleted, x, y + 3, Graphics.TOP | Graphics.LEFT);
}
}
/**
* Redefine to set another object that paints item below header details to
* the variable MessagePartPainter belowHeaderDetailsPainter.
*
* This method sets MessagePartPainter.DEFFAULT_PAINTER that does not paint
* anything.
*/
protected void setBelowHeaderDetailsPainter() {
belowHeaderDetailsPainter = MessagePartPainter.DEFAULT_PAINTER;
}
/**
* Redefine to set another object that paints header details to the variable
* MessagePartPainter headerDetailsPainter.
*
* This method sets the object of instance HeaderDetailsPainter.
*/
protected void setHeaderDetailsPainter() {
headerDetailsPainter = new HeaderDetailsPainter();
}
/**
* Gets the number of actually painted item.
*
* @param g the graphics object used to paint
* @param screenHeight the height of the screen
* @param headlineHeight the height of the headline
* @return the number of actually painted item
*/
private int getActuallyPaintedItem(Graphics g, int headlineHeight, int subjectHeight, int screenHeight) {
//System.out.println("DEBUG TheBox.getActuallyPaintedItem(Graphics, int, int, int) - start");
int selectedMailHeight = subjectHeight +
headerDetailsPainter.getHeight(g, true) +
belowHeaderDetailsPainter.getHeight(g, true) +
1; // the line separating mails
int notSelectedMailHeight = subjectHeight +
headerDetailsPainter.getHeight(g, false) +
belowHeaderDetailsPainter.getHeight(g, false) +
1; // the line separating mails
// the number of not selected mails in the page
int maxItemsPerPage = (screenHeight - headlineHeight - selectedMailHeight) / notSelectedMailHeight;
maxItemsPerPage++; // one mail is selected
//System.out.println("Max items : " + maxItemsPerPage);
final int size = storage.getSize();
if (pageJump != 0 || cur >= maxItemsPerPage) { //if the user pressed * or # or cursor is doesn't fit to the first page of display
int currentPage = cur / maxItemsPerPage; //change current page
//change the current page if the user wanted to jump to another page.
currentPage = (currentPage + pageJump + size / maxItemsPerPage + 1) % (size / maxItemsPerPage + 1); //+1 to prevent modulo by 0
int actItem = currentPage * maxItemsPerPage; //set the first item to be drawn on the page
//System.out.println("DEBUG TheBox.getActuallyPaintedItem(Graphics, int, int, int) - end (" + actItem + ")");
return actItem;
} else {
//System.out.println("DEBUG TheBox.getActuallyPaintedItem(Graphics, int, int, int) - end (0)");
return 0;
}
}
// private void printDot(final Graphics g, final int x, final int y) {
// g.drawLine(x, y, x, y);
// }
/* *
* This method paints before message the '-' sign if the message is root
* message in threaded emails.
*
* @param g
* @param x
* @param y
*/
// private void printThreadSign(final Graphics g, final int x, final int y) {
// int color = g.getColor();
// g.setColor( 50, 50, 50 );
// g.drawRect( x + 1, y + 3, 8, 8 );
// g.drawLine( x + 3, y + 7, x + 7, y + 7 );
// printDot(g, x + 11, y + 7);
// printDot(g, x + 13, y + 7);
// g.setColor( color );
// }
/* *
*
* @param g
* @param x
* @param y
*/
// private void printDots(final Graphics g, final int x, final int y) {
// final int STEP = 2;
// final int CORNER = 16;
// for (int i = 2; i < CORNER; i += STEP) {
// printDot(g, x, y + i);
// }
// for (int i = 0; i < 11; i += STEP) {
// printDot(g, x + i, y + CORNER);
// }
// }
/**
* Paints the box that is empty or busy.
*/
protected void paintIsBusy() {
}
/**
* Returns title for the box.
* @return
*/
private String getBoxTitle() {
final StringBuffer buff = new StringBuffer( getName() );
// String boxName = size > 0 ? getName() + " (" + (cur + 1) + "/" + (size) + ")" : getName() + " (" + Lang.get(Lang.EMPTY) + ")";
final int storageSize = storage.getSize();
if ( storageSize > 0 ) {
buff.append(" (").append( cur + 1 - empties ) // number of current message
.append('/')
.append( getMessageCount() ) // count of all non empty messages
.append(')');
} else {
buff.append(" (").append( Lang.get(Lang.EMPTY) ).append(')');
}
return buff.toString();
}
private void printTitle( Graphics g ) {
if (Settings.fontSize == Settings.FONT_NORMAL) {
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); //set font size for box's headline
} else {
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE)); //set font size for box's headline
}
int fontHeight = g.getFont().getHeight();
g.setColor(184, 179, 255);
g.fillRect(0, 0, getWidth(), fontHeight + 3);
String boxTitle = getBoxTitle();
g.setColor(0x00000000); // black color
g.drawString(boxTitle, getWidth() / 2 - g.getFont().stringWidth(boxTitle) / 2, 1, Graphics.TOP | Graphics.LEFT);
if (Settings.fontSize == Settings.FONT_NORMAL) {
g.setFont( Font.getDefaultFont() );
} else {
g.setFont( Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE) );
}
}
boolean direction = true;
/**
* Paints the list of headers of mails in this box.
* If there is proceeding some operation beyond the mails in the box,
* displays progress bar.
* @param g
*/
protected void paint(Graphics g) {
try {
if (storage.isEmpty() || isBusy()) {
cancelTicker();
hideButtons();
} else {
showButtons();
if (tStarted) { //if this paint call is from ticker
g.setColor(121, 111, 255);
int cw = getWidth();
int ch = Font.getDefaultFont().getHeight();
g.fillRect(0, tY, cw, ch);
g.setColor(255, 255, 255);
if (Settings.fontSize == Settings.FONT_NORMAL)
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -