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

📄 mainmenu.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.ca.directory.jxplorer;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.Logger;

import com.ca.directory.jxplorer.search.*;
import com.ca.commons.naming.*;
import com.ca.directory.jxplorer.tree.*;
import com.ca.commons.cbutil.*;
import com.ca.commons.security.KeystoreGUI;

import java.io.File;
import java.io.IOException;


public class MainMenu extends JMenuBar
{

     //XXX in a fantasy alternate universe this could be rewritten as Action object
     //thingumies so that enabling/disabling stuff could be echoed to the button bar. or not.
     //XXX in the same fantasy universe instantiation of menuitems might be delayed until
     // the user actually selected the main menu item, thus shaving a few milliseconds
     // from the load lag time.

    private static Logger log = Logger.getLogger(MainMenu.class.getName());

    JXplorer jxplorer;
    JXOpenConWin getConnection = null;  // the connection window

    JMenu fileMenu;
    JMenuItem connect, disconnect, print, refreshTree, exit;

    JMenu editMenu;
    JMenuItem cut, copy, paste, delete, rename, copyDN, newEntry, pasteAlias;

    JMenu ldifMenu;
    JMenuItem fullExport, subExport, importFile, viewOffline;

    JMenu searchMenu;
    JMenuItem search, deleteFilter, attrList;

    JMenu bookmarkMenu;
    JMenuItem editBookmark, addBookmark, deleteBookmark;

    JMenu lookAndFeelMenu;
	JMenuItem refresh;

    JMenu optionsMenu, toolsMenu;
    JMenuItem advancedOptions;

    JMenu sslMenu;
    JMenuItem simpleSSL, authSSL, keystoreOptions;

    JMenu helpMenu;
    JMenuItem helpContents, helpSearch, helpAbout;

	SmartTree tree;

	String dirIcons;
	String dirImages;
	String dirTemplates;

    public static Properties myProperties;   // global variables for the browser, read from...
    public static String propertyFile;       // ...a user configurable file storing default properties.
    public static String localDir;           // local directory the browser is being run from...
    public static String fileURLPrefix;      // a prefix that converts local files into a url (e.g. file:///)

    public MainMenu(JXplorer jxplorer)
    {
        super();
        this.jxplorer = jxplorer;

		setImageDirs();	//TE: gets the image and icon dirs.

        /*
         *    This is a long ftn that sets up lots and lots
         *    of menu items.
         */

        // String constants for menu items

        // Set up the file menu item
        fileMenu = new JMenu(CBIntText.get("File"));
        fileMenu.setMnemonic('F');
        setupFileMenu(fileMenu);


        editMenu = new JMenu(CBIntText.get("Edit"));
        editMenu.setMnemonic('E');
        setupEditMenu(editMenu);

        // Set up the look and feel view menu
        lookAndFeelMenu = new JMenu(CBIntText.get("View"));
        lookAndFeelMenu.setMnemonic('V');
        setupLookAndFeelMenu(lookAndFeelMenu);

        // Set up the ldif menu item
        ldifMenu = new JMenu(CBIntText.get("LDIF"));
        ldifMenu.setMnemonic('L');
        setupLdifMenu(ldifMenu);

        // Set up the search menu item
        searchMenu = new JMenu(CBIntText.get("Search"));
        searchMenu.setMnemonic('S');
        setupSearchMenu(searchMenu);

		 // Set up the bookmark menu item
        bookmarkMenu = new JMenu(CBIntText.get("Bookmark"));
        bookmarkMenu.setMnemonic('B');
        setupBookmarkMenu(bookmarkMenu);

        // Set up the options menu item
        optionsMenu = new JMenu(CBIntText.get("Options"));
        optionsMenu.setMnemonic('O');
        setupOptionsMenu(optionsMenu);

        // Set up the tools menu item
        toolsMenu = new JMenu(CBIntText.get("Tools"));
        toolsMenu.setMnemonic('T');
        setupToolsMenu(toolsMenu);

        // Set up the options menu item
        sslMenu = new JMenu(CBIntText.get("Security"));
        sslMenu.setMnemonic('i');
        setupSSLMenu(sslMenu);

        // Set up the help menu item
        helpMenu = new JMenu(CBIntText.get("Help"));
        helpMenu.setMnemonic('H');
        setupHelpMenu(helpMenu);

        // Set the overall Menu Bar
        this.add(fileMenu);
        this.add(editMenu);
        this.add(lookAndFeelMenu);
		this.add(bookmarkMenu);
        this.add(searchMenu);
        this.add(ldifMenu);
        this.add(optionsMenu);
        this.add(toolsMenu);
        this.add(sslMenu);
        this.add(helpMenu);

        jxplorer.setJMenuBar(this);

        setDisconnected();
    }

/*    protected void processEvent(AWTEvent e)
    {
System.out.println(CBIntText.get("snaffled event ") + e.toString());
        super.processEvent(e);

    }
*/

    protected void setupFileMenu(JMenu fileMenu)
    {
        // setup common menu listener

        ActionListener fileListener =  new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JMenuItem src = ((JMenuItem)e.getSource());

				tree = jxplorer.getActiveTree();

                if (src == connect)
                    connect();
                else if (src == disconnect)
                    disconnect();
                else if (src == print)
                    print();
                else if (src == refreshTree)
                    jxplorer.mrTree.collapse();
                else if (src == exit)
                    jxplorer.shutdown();

                jxplorer.repaint();
            }
        };

        // initialise menu items

        connect = setMenuItem(fileMenu, fileListener,
            new String[] {CBIntText.get("Connect"), "C", CBIntText.get("Connect to a directory server."), "E", dirImages+"connect.gif" } );

        disconnect = setMenuItem(fileMenu, fileListener,
            new String[] {CBIntText.get("Disconnect"), "D", CBIntText.get("Disconnect from a directory server."), "E", dirImages+"disconnect.gif" } );

        print = setMenuItem(fileMenu, fileListener,
            new String[] {CBIntText.get("Print"),   "P", CBIntText.get("Print out the current entry."), "E", dirImages+"print.gif" } );

        setMenuItem(fileMenu, fileListener, new String[] {"-", "",  "", "" } );

        refreshTree = setMenuItem(fileMenu, fileListener,
            new String[] {CBIntText.get("Refresh Tree"), "R", CBIntText.get("Forces the tree to be reloaded from the directory."), "E", dirImages+"refresh_all.gif" } );

        setMenuItem(fileMenu, fileListener, new String[] {"-", "",  "", "" } );

        exit = setMenuItem(fileMenu, fileListener,
            new String[] {CBIntText.get("Exit"),    "x", CBIntText.get("Quit the JXplorer application."), "E", dirImages+"blank.gif" } );

        ButtonRegister br = JXplorer.getButtonRegister();
        br.registerItem(br.CONNECT, connect);
        br.registerItem(br.DISCONNECT, disconnect);
        br.registerItem(br.PRINT, print);
        br.registerItem(br.REFRESH_TREE, refreshTree);
    }

    public void connect()
    {
        CBCache.cleanCache();    //TE: deletes any temp files.

        if (getConnection == null)
        {
			//TE: the new connection class extends CBOpenConWin...
            getConnection = new JXOpenConWin(jxplorer, jxplorer.displayLabel,
												JXplorer.getProperty("option.ssl.clientcerts"),
												JXplorer.getProperty("option.ssl.cacerts"),
												JXplorer.getProperty("option.ldap.referral"),
												JXplorer.getProperty("option.ldap.searchAliasBehaviour"));
            getConnection.setSize(450,340);
            CBUtility.center(getConnection, jxplorer);
        }
        else
        {
            getConnection.reinit( JXplorer.getProperty("option.ssl.clientcerts"),
                                  JXplorer.getProperty("option.ssl.cacerts"),
                                  JXplorer.getProperty("option.ldap.referral"),
                                  JXplorer.getProperty("option.ldap.searchAliasBehaviour"));

        }

        getConnection.resetTitleAndPassword();
        getConnection.setVisible(true);
    }

    /**
     *    Called by JX to turn appropriate buttons on.
     */

    public void setConnected(boolean searchActive)
    {
        editMenu.setEnabled(true);
        searchMenu.setEnabled(searchActive);
        toolsMenu.setEnabled(true);
		bookmarkMenu.setEnabled(true);
    }

    public void disconnect()
    {
        jxplorer.disconnect();
    }

    public void setDisconnected()
    {
        editMenu.setEnabled(false);
        searchMenu.setEnabled(false);
        toolsMenu.setEnabled(false);
		bookmarkMenu.setEnabled(false);
    }

    public void print()
    {
        jxplorer.pushStatus("Printing...");
        jxplorer.mainViewer.print();
        jxplorer.popStatus();
    }

    public void setupEditMenu(JMenu editMenu)
    {
        // set up a common listener for this menu

        ActionListener editListener = new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JMenuItem item = (JMenuItem)e.getSource();

				tree = jxplorer.getActiveTree();

                if (item == cut)
                    tree.getPopupTool().cut();
                else if (item == copy)
                    tree.getPopupTool().copy();
                else if (item == paste)
                    tree.getPopupTool().paste();
                else if (item == delete)
                    tree.getPopupTool().delete();
                else if (item == rename)
                    tree.getPopupTool().rename();
                else if (item == copyDN)
                    tree.getPopupTool().copyDN();
                else if (item == newEntry)
                    tree.getPopupTool().newEntry();
                else if (item == pasteAlias)
                    tree.getPopupTool().pasteAlias();
            }
        };

        // define the individual menu items

        newEntry = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("New"), "Ctrl+N", CBIntText.get("Create a new entry."), "E", dirImages+"new.gif"} );

        copyDN = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Copy DN"), "Ctrl+Y", CBIntText.get("Copy the Distinguished Name of an entry to the clipboard."), "E", dirImages+"copy_dn.gif"} );

	    setMenuItem(editMenu, editListener, new String[] {"-", "", "", ""} );

        cut = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Cut Branch"), "Ctrl+U", CBIntText.get("Select a subtree to move."), "E", dirImages+"cut.gif"} );

        copy = setMenuItem(editMenu, editListener,
            new String[]  {CBIntText.get("Copy Branch"), "Ctrl+O", CBIntText.get("Select a subtree to copy."), "E", dirImages+"copy.gif"});

        paste = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Paste Branch"), "Ctrl+P", CBIntText.get("Paste a previously selected subtree."), "E", dirImages+"paste.gif"} );

        pasteAlias = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Paste Alias"), "", CBIntText.get("Paste an Alias."), "E", dirIcons+"alias.gif"} );

        setMenuItem(editMenu, editListener, new String[] {"-", "", "", ""} );

        delete = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Delete"), "Ctrl+D", CBIntText.get("Delete an entry."), "E", dirImages+"delete.gif"} );

        rename = setMenuItem(editMenu, editListener,
            new String[] {CBIntText.get("Rename"), "Ctrl+M", CBIntText.get("Rename an entry."), "E", dirImages+"rename.gif"} );

        ButtonRegister br = JXplorer.getButtonRegister();
        br.registerItem(br.PASTE, paste);
        br.registerItem(br.PASTE_ALIAS, pasteAlias);
        br.registerItem(br.COPY, copy);
        br.registerItem(br.COPY_DN, copyDN);
        br.registerItem(br.CUT, cut);
        br.registerItem(br.DELETE, delete);
        br.registerItem(br.NEW, newEntry);
        br.registerItem(br.RENAME, rename);

        br.setItemEnabled(br.PASTE, false);
        br.setItemEnabled(br.PASTE_ALIAS, false);
    }

    public void setupLdifMenu(JMenu ldifMenu)

⌨️ 快捷键说明

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