private JPopupMenu getSelectionPopupMenu() {
    JPopupMenu popup = new JPopupMenu("Selection");
    // MenuBar -> Selection -> Copy
    JMenuItem menuItemCopy = new JMenuItem("Copy");
    menuItemCopy.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        copySelection();
      } 
    } );
    popup.add(menuItemCopy);
    // MenuBar -> Selection -> Paste
    JMenuItem menuItemPaste = new JMenuItem("Paste");
    menuItemPaste.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        pasteLine(); 
      } 
    } );
    popup.add(menuItemPaste);
    popup.addSeparator();
   
    // MenuBar -> Selection -> Join
    JMenuItem menuItemJoinSelection = new JMenuItem("Join (Channel)");
    menuItemJoinSelection.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        if (!mainFrame.isConnected())
          return;
        String chan = mainFrame.getSelection().trim();
        if (IRCUtil.isChannel(chan)) {
          conn.doJoin(chan); 
        } else if (chan.length() > 0) {
          conn.doJoin("#"+ chan);
        }
      } 
    } );
    popup.add(menuItemJoinSelection);
    // MenuBar -> Selection -> Whois
    JMenuItem menuItemWhoisUser = new JMenuItem("Whois (User)");
    menuItemWhoisUser.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        if (!mainFrame.isConnected())
          return;
        conn.doWhois(mainFrame.getSelection()); 
      } 
    } );
    popup.add(menuItemWhoisUser);
    popup.addSeparator();
    // MenuBar -> Selection -> ChanCenter
    JMenuItem menuItemChanCenter = new JMenuItem("Control Center");
    menuItemChanCenter.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        Component component = mainFrame.getSelectedComponent();
        if (component instanceof ChanPanel) 
          ((ChanPanel)component).openControlCenter();
      }
    } );
    popup.add(menuItemChanCenter);
    JMenuItem menuItemPasteDialog = new JMenuItem("Full Message");
    menuItemPasteDialog.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        Component component = mainFrame.getSelectedComponent();
        if (component instanceof ChanPanel || component instanceof QueryPanel) {
          String chan = ((PanelTemplate)component).getWindowName();
          new PasteDialog(mainFrame, chan);
        }
      }
    } );
    popup.add(menuItemPasteDialog);
    return popup;
  }