⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gmmainframe.java

📁 Gmail API for Java 一个gmail信箱的客户端
💻 JAVA
字号:
package siuying.gm.app.gmailer4j.ui;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import com.jgoodies.uif_lite.component.*;
import com.jgoodies.uif_lite.panel.*;
import siuying.gm.app.gmailer4j.*;
import com.jgoodies.plaf.Options;
import com.jgoodies.looks.demo.Settings;
import com.jgoodies.plaf.plastic.PlasticLookAndFeel;
import com.jgoodies.plaf.windows.ExtWindowsLookAndFeel;

/**
 * GMMainFrame
 * <p>Description: Main Frame of GMailer2, this is the UI code,
 * controller code is at siuying.gm.app.gmailer4j.controller.GMMainFrameController</p>
 * <p>Copyright: GPL</p>
 * <p>Company: siuying.net</p>
 * @author siuying
 * @version 0.3.8
 */
public class GMMainFrame
    extends JFrame {
  /* publicly accessable ui components */
  public UIFSplitPane splitVertical = new UIFSplitPane();
  public UIFSplitPane splitHorizon = new UIFSplitPane();
  public JPanel panelStatus = new JPanel();
  public SimpleInternalFrame panelLeft = new SimpleInternalFrame("Mailbox");
  public SimpleInternalFrame panelRight = new SimpleInternalFrame("Conversation");
  public SimpleInternalFrame panelBottom = new SimpleInternalFrame("Message");
  public JProgressBar progressBar = new JProgressBar();
  public JLabel lblStatus = new JLabel();
  public JPanel toolbarTop = new JPanel();    
  public JLabel lblRight = new JLabel();
  public JLabel lblLeft = new JLabel();
  public JLabel lblBottom = new JLabel();
  public JScrollPane scrollLeft = new JScrollPane();
  public JScrollPane scrollRight = new JScrollPane();
  public JPanel messageArea = new JPanel();
  public JTree treeMailbox = new JTree();
  public JTable tblThreads = new JTable();
  public JConsoleFrame consoleFrame = new JConsoleFrame();

  /* buttons */
  public AbstractButton btnToolbarRefresh;
  public AbstractButton btnToolbarConnect;
  public AbstractButton btnToolbarDisconnect;
  public AbstractButton btnContentClose;
  public AbstractButton btnMailbox;
  public AbstractButton btnSearch;
  public AbstractButton btnLabel;

  /* menu items */
  public JMenuBar menuBar = new JMenuBar();
  public JMenu mnuTools = new JMenu();
  public JMenu mnuFile = new JMenu();
  public JMenuItem itmFileLogin = new JMenuItem();
  public JMenuItem itmFileLogout = new JMenuItem();
  public JMenuItem itmFileExit = new JMenuItem();

  public JMenu mnuHelp = new JMenu();
  public JMenuItem itmHelpAbout = new JMenuItem();
  public JMenuItem itmToolsOption = new JMenuItem();
  public JMenuItem itmToolsConsole = new JMenuItem();
  public JMenuItem itmRefresh = new JMenuItem();
  public JToolBar toolbarMailbox = new JToolBar();
  public JToolBar toolbarContent = new JToolBar();  
  private Settings settings = Utils.DEF_SETTING;

  FlowLayout flowLayout1 = new FlowLayout();
  FlowLayout flowLayout2 = new FlowLayout();
  FlowLayout flowLayout3 = new FlowLayout();
  BorderLayout borderLayout1 = new BorderLayout();
  ImageIcon icon = new ImageIcon(getClass().getResource("star_on_2.gif"));

  Border borderOut;
  Border borderIn;
  Border borderStatus;
  Border borderTooltips;

  public GMMainFrame() {
    try {
      setupToolbars();
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void setupToolbars() {
    /*** toolbarTop ***/
    btnToolbarConnect = Utils.createToolBarButton("connect.png", "Login");
    toolbarTop.add(btnToolbarConnect);

    btnToolbarDisconnect = Utils.createToolBarButton("disconnect.png", "Logout");
    toolbarTop.add(btnToolbarDisconnect);
    btnToolbarDisconnect.setEnabled(false);
    
    toolbarTop.add(Box.createRigidArea(new Dimension(10, 0)));
    
    btnToolbarRefresh = Utils.createToolBarButton("refresh_nav.gif", "Refresh");
    toolbarTop.add(btnToolbarRefresh);    
    
    /*** toolbarMailbox ***/
    ButtonGroup group = new ButtonGroup();
    btnMailbox = Utils.createToolBarRadioButton("mailbox.png", "Mailbox");
    group.add(btnMailbox);
    toolbarMailbox.add(btnMailbox);

    btnLabel = Utils.createToolBarRadioButton("label.png", "Label");
    group.add(btnLabel);
    toolbarMailbox.add(btnLabel);

    btnSearch = Utils.createToolBarRadioButton("search_src.gif",
                                               "Search Results");
    group.add(btnSearch);
    toolbarMailbox.add(btnSearch);

    btnContentClose = Utils.createToolBarButton("close_view.gif", "Close View");
    toolbarContent.add(btnContentClose);
  }

  private void jbInit() throws Exception {
    // initialize and setup properties
    setIconImage(icon.getImage());
    setSize(800, 600);
    borderOut = BorderFactory.createEmptyBorder(2, 2, 2, 2);
    borderStatus = BorderFactory.createCompoundBorder(BorderFactory.
        createEtchedBorder(Color.white, new Color(165, 163, 151)),
        BorderFactory.createEmptyBorder(2, 2, 2, 2));
    borderTooltips = BorderFactory.createEmptyBorder(2,4,0,0);
    borderIn = BorderFactory.createEmptyBorder(2, 0, 2, 0);

    panelLeft.setFrameIcon(Utils.readImageIcon("mailbox.png"));

    // set borders
    splitHorizon.setBorder(borderIn);
    splitVertical.setBorder(borderOut);
    panelStatus.setBorder(borderStatus);
    toolbarTop.setBorder(borderTooltips);

    // set layout
    panelStatus.setLayout(borderLayout1);
    // toolbarTop.setLayout(flowLayout1);
    toolbarTop.setLayout(new BoxLayout(toolbarTop, BoxLayout.X_AXIS));    
    toolbarMailbox.setLayout(flowLayout2);

    flowLayout2.setAlignment(FlowLayout.RIGHT);
    flowLayout2.setHgap(0);
    flowLayout2.setVgap(0);

    // set menus
    mnuFile.setText("File");
    itmFileExit.setText("Exit");
    itmFileLogin.setText("Login");
    itmFileLogout.setText("Logout");
    mnuHelp.setText("Help");
    itmHelpAbout.setText("About");
    mnuTools.setText("Tools");
    itmToolsOption.setText("Option");
    itmToolsConsole.setText("Console");
    itmRefresh.setEnabled(false);
    itmRefresh.setText("Refresh");
    itmFileLogout.setEnabled(false);
    scrollRight.setDoubleBuffered(true);
    treeMailbox.setDoubleBuffered(true);
    menuBar.add(mnuFile);
    menuBar.add(mnuTools);
    menuBar.add(mnuHelp);

    mnuFile.add(itmFileLogin);
    mnuFile.add(itmFileLogout);
    mnuFile.addSeparator();
    mnuFile.add(itmFileExit);
    mnuHelp.add(itmHelpAbout);
    mnuTools.add(itmRefresh);
    mnuTools.add(itmToolsConsole);    
    mnuTools.addSeparator();
    mnuTools.add(itmToolsOption);
    this.setJMenuBar(menuBar);

    // set spilt panel
    splitHorizon.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    splitVertical.setPreferredSize(new Dimension(350, 350));
    splitVertical.setRequestFocusEnabled(true);
    splitVertical.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitVertical.setMinimumSize(new Dimension(350, 350));
    progressBar.setMaximum(100);
    progressBar.setStringPainted(true);

    // Others
    panelBottom.setToolBar(toolbarContent);
    panelLeft.setToolBar(toolbarMailbox);
    lblRight.setHorizontalAlignment(SwingConstants.CENTER);
    lblRight.setText("No messages");
    lblLeft.setHorizontalAlignment(SwingConstants.CENTER);
    lblLeft.setHorizontalTextPosition(SwingConstants.TRAILING);
    lblLeft.setText("No mailbox");
    lblBottom.setHorizontalAlignment(SwingConstants.CENTER);
    lblBottom.setHorizontalTextPosition(SwingConstants.CENTER);
    lblBottom.setText("No content");
    panelStatus.add(lblStatus, BorderLayout.CENTER);
    panelStatus.add(progressBar, BorderLayout.EAST);

    splitHorizon.add(panelLeft, JSplitPane.TOP);
    panelLeft.add(scrollLeft, BorderLayout.CENTER);    
    scrollLeft.getViewport().add(treeMailbox);

    splitHorizon.add(panelRight, JSplitPane.BOTTOM);
    panelRight.add(scrollRight, BorderLayout.CENTER);    
    scrollRight.getViewport().add(tblThreads);

    messageArea.setLayout(new BorderLayout());

    splitVertical.add(panelBottom, JSplitPane.BOTTOM);
    panelBottom.add(messageArea, BorderLayout.CENTER);
    splitVertical.add(splitHorizon, JSplitPane.TOP);

    this.setTitle("GMailer4j");

    this.getContentPane().add(splitVertical, BorderLayout.CENTER);
    this.getContentPane().add(panelStatus, BorderLayout.SOUTH);
    this.getContentPane().add(toolbarTop, BorderLayout.NORTH);

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -