?? gmconvpanelcontroller.java
字號:
package siuying.gm.app.gmailer4j.controller;
import EDU.oswego.cs.dl.util.concurrent.*;
import EDU.oswego.cs.dl.util.concurrent.misc.*;
import siuying.gm.app.gmailer4j.ui.GMConvPanel;
import javax.swing.JPanel;
import siuying.gm.GMConversation;
import java.util.logging.Logger;
import siuying.gm.structure.GMConversationEntry;
import siuying.gm.structure.GMThread;
import javax.swing.SwingUtilities;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
/**
* GMThreadPanelController
* Controller of the GMThreadPanel, used to display a conversation,
* user can navigate through the threads in conversation
* @author siuying
* @version 0.2
*/
public class GMConvPanelController {
private JFrame parent;
private GMConvPanel panel;
private GMConversation conversation;
private Logger logger = Logger.getLogger(GMConvPanelController.class.getName());
private JFrame frame;
public GMConvPanelController(JFrame parent) {
this.parent = parent;
// setup UI
frame = new JFrame();
JPanel contentPane = (JPanel) frame.getContentPane();
BorderLayout borderLayout1 = new BorderLayout();
panel = new GMConvPanel();
frame.setSize(new Dimension(640,480));
frame.setIconImage(parent.getIconImage());
contentPane.setLayout(borderLayout1);
contentPane.add(panel, BorderLayout.CENTER);
reset();
}
public GMConversation getConversation(){
return conversation;
}
public JPanel getPanel(){
return panel;
}
/**
* Set the conversation of this panel
* One panel can only display on set of conversation
*/
public void setConversation(GMConversation conv){
if (conv == null){
// no mail message
}else{
conversation = conv;
}
}
/**
* Set the current threads this panel displayed
* Input parameter must be a valid index of the conversation
* @param int index index of current conversation
* @throws IllegalArgumentException If conversation have not been set, or
* index is smaller than 0 or larger than conversation index
*/
public void setCurrentThreads(int index){
if (conversation == null){
logger.warning("Set current threads, but no conversation exist!");
throw new IllegalArgumentException("Set current threads, but no conversation exist!");
}
if (conversation.getEntries().size() <= index ||
index < 0){
logger.warning("Unexpected index entered, id:" + index);
throw new IllegalArgumentException("Unexpected index entered, id:" + index);
}
GMConversationEntry entry = null;
try{
entry = (GMConversationEntry) conversation.getEntries().get(index);
}catch(ClassCastException cce){
logger.warning("Unexpected message, class cast exception!");
}
// set the current message (finally!)
if (entry != null){
String subject = entry.getSubj();
String sender = entry.getSender();
String date = entry.getDt();
String content = entry.getBody();
setPanelText(subject, sender, date, content);
}
}
/**
* Pop up a frame display the Threads
*/
public void show(){
frame.show();
}
/**
* Reset the text of this panel to default string
*/
public void reset(){
setPanelText("Downloading . . . ", "", "", "");
}
public void dispose(){
frame.setVisible(false);
conversation = null;
frame.dispose();
}
/**
* Set the string of the panel to those specified
*/
private void setPanelText(final String subject,
final String sender,
final String date,
final String content){
// prepare a task run in background
Runnable r = new Runnable(){
public void run() {
frame.setTitle(subject);
panel.lblDate.setText("<html><b>Date:</b> " + date + "</html>");
panel.lblSender.setText("<html><b>Sender:</b> " + sender + "</html>");
panel.lblSubject.setText("<html><b>Subject:</b> " + subject + "</html>");
panel.txtContent.setText(content);
logger.info("Current selecting:" + panel.scrollPane.getVerticalScrollBar().getValue());
logger.info("Setting scroll pane to :" + panel.scrollPane.getVerticalScrollBar().getMinimum() +
"; max: " + panel.scrollPane.getVerticalScrollBar().getMaximum());
scrollTop();
}
};
// run the task
SwingUtilities.invokeLater(r);
}
public void scrollTop(){
Runnable r = new Runnable(){
public void run() {
panel.scrollPane.getVerticalScrollBar().setValue(panel.scrollPane.getVerticalScrollBar().getMinimum());
}
};
SwingUtilities.invokeLater(r);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -