📄 funcanvasmessagelist.java
字号:
/**
* add a new messageInfo to the messagelist or overwrite the messageinfo
* if exists
*
* @param message the message used to create the messaginfo info to be added
*/
public void addMessage(Message message) {
try {
addMessage(new MessageInfo(message, new FolderInfo(
message.getParent().getName(), StoreFactory.getStore())));
} catch (MailException ex) {
ex.printStackTrace();
Log.error("Error adding message " + message.getSubject()
+ "to message list");
}
}
/**
* @return the index of the messageinfo with the same messagid as
* the given messageinfo, or -1 if not found.
*/
public int search(String msgId) {
int position = -1;
for (int i =0; i< elements.length; i++) {
if (getMessageInfoAt(i).messageId.equals(msgId)) {
position = i;
break;
}
}
return position;
}
/**
* handle the keypress events, should be overridden
*/
protected void handleKey(int keyCode) {
}
/**
*this method is called by implementation when the commands need to be
* initialized (in the constructor), should be overridden. After this element
* the commands referenced in addCommands, addItemCommands, removeItemcommands
* must be not null
*/
void initCommands() {
}
/**
*this method is called by implementation when the generic commands need to be
* added (in the constructor), should be overridden.
*/
void addCommands() {
}
/**
*this method is called by implementation when the item commands need to be
* added (i.e. while setting a non empty elements array. should be ovverridden
*/
void removeItemCommands() {
}
/**
*this method is called by implementation when the item commands need to be
* removed (i.e. while setting an empty elements array). should be ovverridden
*/
void addItemCommands() {
}
/**
* paint the background
*/
void paintBackground(Graphics graphics) {
drawer.drawCanvasBackground(graphics, getWidth(), getHeight());
}
/**
* remove the messageinfo in the given position from the visualized list.
* This function will NOT delete the message from the folder
*
* @param position the position of the messageinfo to be removed
*/
public void deleteMessageAt(int position) {
//#ifdef low_mem
//# UIController.freeMemory(); //XXX
//#endif
// Update elements.
MessageInfo[] newElements = new MessageInfo[elements.length -1];
for (int i=0, j=0, l=elements.length; i<l ; i++) {
if (position != i) {
newElements[j++] = (MessageInfo) elements[i];
}
}
this.elements = newElements;
// Update messageList.
messageList.removeElementAt(position);
for (int i = position; i< messageList.size(); i++) {
((CanvasMessageItem) messageList.elementAt(i)).setId(i);
}
// If the deleted message was the last, set the new last as
// active.
if (getActiveElement() >= elements.length) {
setActiveElement(elements.length-1);
}
repaint();
}
/**
* delete the message with the given msgID from the elements array, if present
* this method does not delete the message from the rms!
*
* @param msgId the messageid of the message to be deleted
*/
public void deleteMessage(String msgId) {
int p = search(msgId);
if ( p >= 0) {
deleteMessageAt(p);
}
}
/**
* return the messageInfoList
*/
public MessageInfo[] getMessageInfoList(){
return (MessageInfo[])this.elements;
}
/**
* return the messageInfo element at the given position
* @param position the position of the element to be returned
*/
public MessageInfo getMessageInfoAt(int position) {
return ((MessageInfo)elements[position]);
}
//------------------------ CanvasMessageItem ---------------------------------//
/**
* this class draws the message item
*/
class CanvasMessageItem {
MessageInfo message;
private int id;
private int lastw;
private String date;
/**
* the subject that fits on a single line
*/
private String shortSubject;
/**
* the address that fits on a single line
*/
private String shortAddress;
/**
* the height of this element when not expanded
*/
private int unexpanded_h;
/**
* the height of this element when expanded
*/
private int expanded_h;
/**
* track if the last time we painted the item the read flag was
* set or not (to recalculate the short strings if necessary)
*/
private boolean lastReadFlag ;
CanvasMessageItem(MessageInfo msgInfo, int id) {
this.message = msgInfo;
this.id = id;
}
private boolean isActive(){
return id == getActiveElement();
}
/**
* paint the messageitem
*/
public int paint(Graphics graphics) {
//we need to calculate the short strings
int w = getWidth();
int h = calculateHeight();
calculateShortStrings();
//we draw the background, image and date
drawer.drawBackground(graphics,w,h,isActive());
graphics.drawImage(Theme.getSTATE_IMAGES_VECTOR()[getFlagValue()],MARGIN,MARGIN,Graphics.TOP|Graphics.LEFT);
drawer.drawString(getDate(),graphics,w-MARGIN,MARGIN,Graphics.TOP|Graphics.RIGHT,isActive());
//if this is a read message we use normal font, otherwhise we use the bold font
if (isRead()) {
drawer.drawString(shortAddress, graphics, Theme.getIMAGE_PART_WIDTH()+
2*MARGIN, MARGIN, isActive());
} else {
drawer.drawBoldString(shortAddress, graphics, Theme.getIMAGE_PART_WIDTH()+
2*MARGIN, MARGIN, isActive());
}
//if expanded we draw the second line
if (isExpanded()) {
drawer.drawString(shortSubject, graphics, MARGIN, getUnexpandedh(), isActive());
}
return h;
}
/**
* return the flag value used to identify the image in the image array
*/
private int getFlagValue() {
int flags=message.flags.getFlags();
//we mask the flag to be sure we have a return value <32
flags = (flags&0x0000001f);
return flags;
}
/**
* calculate the short version of address and subject and
* store them in shortAddress and shortSubject
*/
private void calculateShortStrings() {
if (shortAddress == null || shortSubject == null || lastReadFlag != isRead() ) {
int w = getWidth();
int firstlineSpace = w - 4*MARGIN - Theme.getIMAGE_PART_WIDTH() - font.stringWidth(getDate());
int secondlineSpace = w - MARGIN;
shortSubject=UiUtils.cutString(message.subject,secondlineSpace, font);
String address = (isIncomingMessage()) ? message.from.getVisibleName() :
message.to.getVisibleName() ;
if (isRead()) {
shortAddress=UiUtils.cutString(address, firstlineSpace, font);
lastReadFlag = true;
} else {
shortAddress=UiUtils.cutString(address, firstlineSpace, boldFont);
lastReadFlag = false;
}
}
}
/**
* @return true if message is in the inbox
*/
private boolean isIncomingMessage() {
return (Store.INBOX.equals(message.parent.getName()));
}
/**
* @return true if the message has been opened
*/
private boolean isRead() {
return message.flags.isSet(MessageFlags.OPENED) ;
}
/**
* return true if this item is expanded, false otherwise
*/
public boolean isExpanded() {
boolean ret;
//#ifdef MessageItemAlwaysExpanded
//# ret = true;
//#else
ret = isActive();
//#endif
return ret;
}
/**
* compute height using information from the bean,
* the drawer and the icon size
*/
private int calculateHeight() {
if (isExpanded()) {
return getExpandedh();
} else {
return getUnexpandedh();
}
}
/**
* @retunr the height of this element not expanded
*/
private int getUnexpandedh() {
if (unexpanded_h==0) {
unexpanded_h= MARGIN;
unexpanded_h+=Math.max(
Math.max(font.getHeight(),boldFont.getHeight()), Theme.getIMAGE_PART_HEIGHT());
//unselected_h+=MARGIN;
}
return unexpanded_h;
}
/**
* @retunr the height of this element expanded
*/
private int getExpandedh() {
if (expanded_h==0) {
expanded_h= getUnexpandedh();
expanded_h+=font.getHeight();
expanded_h+=MARGIN;
}
return expanded_h;
}
// new Vector()
/**
* return the date as a formatted string
*/
private String getDate() {
if (date == null) {
date = UiUtils.formatDate(message.received);
}
return date;
}
/**
*
*/
private void setId(int newId) {
this.id = newId;
}
}
boolean isVisible(int elementId) {
return elements[elementId] != null;
//return true;
}
boolean isActivable(int elementId) {
return elements[elementId] != null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -