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

📄 mainmenu.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
						searchMenu.setSelected(false);
					}
					else if (type==bookmarkMenu)								//TE: bookmark menu action.
					{
                        jxplorer.getTreeTabPane().setSelectedIndex(0);
						goToBookmark(toolTps[list.getSelectedIndex()].toString(), jxplorer.getActiveTree());
						bookmarkMenu.getPopupMenu().setVisible(false);			//TE: kill the menu (wont do it automatically with the list in it).
						bookmarkMenu.setSelected(false);
					}
				}
		}});

		JScrollPane sp = new JScrollPane(list);
		sp.setPreferredSize(new Dimension(100, 300));
		sp.setMinimumSize(new Dimension(100, 300));
		sp.setAlignmentX(LEFT_ALIGNMENT);

		return sp;
	}



   /**
   	*	Sets up the bookmark menu with menu items and listeners.  Dynamically adds bookmark names to the
	*	menu.  If there is more than 15, these names are added to a scrollable list.  If a user selects
	*	one of these names, the tree jumps to that entry.
	*	@param bookmarkMenu the bookmark menu.
	*/

	protected void setupBookmarkMenu(JMenu bookmarkMenu)
	{
		bookmarkMenu.removeAll();

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

                jxplorer.getTreeTabPane().setSelectedIndex(0);

				tree = jxplorer.getActiveTree();

				if (item == editBookmark)
					tree.openEditBookmarkDialog();
				else if (item == addBookmark)
					tree.openAddBookmarkDialog(jxplorer.mrTree.getCurrentDN());
				else if (item == deleteBookmark)
					tree.openDeleteBookmarkDialog();
				else
					goToBookmark(((myJMenuItem)item).name, tree);

				jxplorer.repaint();
			}
		};

		addBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
		new String[] {CBIntText.get("Add Bookmark"),  "Ctrl+B", CBIntText.get("Add a bookmark from the current DN."), "E", dirImages+"plus.gif"} );

        deleteBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
        new String[] {CBIntText.get("Delete Bookmark"),"d", CBIntText.get("Delete a bookmark."), "E", dirImages+"delete.gif"} );

		editBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
		new String[] {CBIntText.get("Edit Bookmark"),"i", CBIntText.get("Edit your bookmarks."), "E", dirImages+"edit.gif"} );


        ButtonRegister br = JXplorer.getButtonRegister();
        br.registerItem(br.BOOKMARKS, addBookmark);

		Properties propertyList = CBUtility.readPropertyFile("bookmarks.txt");

		DXNamingEnumeration keys = new DXNamingEnumeration(propertyList.keys());

        if(keys.size() > 0)
		    setMenuItem(bookmarkMenu, bookmarkListener, new String[] {"-", "", "", "", ""} );

        Hashtable bookmarkTable = new Hashtable();

		while (keys.hasMoreElements())
		{
			String key = keys.nextElement().toString();
			if (key.toLowerCase().startsWith("dn"))
                bookmarkTable.put(key.substring(key.indexOf(".")+1), propertyList.getProperty(key));
		}

        DXNamingEnumeration en = new DXNamingEnumeration(bookmarkTable.keys());
        en.sort();

        int size = en.size();

        String[] bookmarkVals = new String[size];
        String[] bookmarkNams = new String[size];

        int j=0;
        while(en.hasMore())
        {
            bookmarkNams[j] = (String)en.next();
            bookmarkVals[j] = (String)bookmarkTable.get(bookmarkNams[j]);
            j++;
        }

		if (size>15)
		{
			bookmarkMenu.add(getScrollList(bookmarkNams, bookmarkVals, bookmarkMenu));
		}
		else
		{
			for(int i=0; i<bookmarkVals.length; i++)
			{
				myJMenuItem bookmarkMenuItem = new myJMenuItem(bookmarkNams[i]);
				bookmarkMenuItem.name = bookmarkVals[i];
				setMenuItem(bookmarkMenu, bookmarkMenuItem, bookmarkListener, new String[] {"", "", "Go to: " + bookmarkVals[i]+".", "E", ""});
			}
		}
	}



   /**
    *	Enables or disables the bookmark menu items (not the add or edit items - just the actual
	*	saved bookmarks).
	*	@param state disabled if false, enabled if true.
	*/

	public void setBookmarksEnabled(boolean state)
	{
		if(bookmarkMenu==null)
			return;

		int items = bookmarkMenu.getItemCount();

		for(int i=0;i<items;i++)
		{
			JMenuItem temp = bookmarkMenu.getItem(i);

			if(temp instanceof myJMenuItem)
				temp.setEnabled(state);
		}
		bookmarkMenu.repaint();
	}



   /**
	*	Extends JMenuItem to add a public string that can be used to store the
	*	name of the menu item.
	*/

	public class myJMenuItem extends JMenuItem
	{


		public String name;


   	   /**
		*	Constructor that creates a menuItem with text.
		*/

		public myJMenuItem(String s) { super(s); }
	}



   /**
    *	Calls the set up for the bookmark menu.  Used to dynamically update the bookmark names within the bookmark menu.
	*/

	public void updateBookmarkMenu()
	{
		setupBookmarkMenu(bookmarkMenu);
	}



   /**
    *	Tries to display the entry that the user asks for via a bookmark.  It tries to
	*	expand the children of all the parents instead of just displaying the
	*	direct parents of the entry in question.
	*	@param dn the dn of the entry that is to be opened.
	*	@param tree the tree that holds all the entries.
	*
	*/

	public void goToBookmark(String dn, SmartTree tree)
	{
        tree.readAndExpandDN(new DN(dn));
	}



    /**
     *    View menu setup.  Adds two check boxes; the first is for displaying the button bar
     *    and the second is for displaying the search bar in JX.
     */
    protected void setupLookAndFeelMenu(JMenu lookAndFeelMenu)
    {
       String status = ("false".equals(JXplorer.getProperty("gui.buttonbar")))?"U":"C";
       setCheckBoxMenu(lookAndFeelMenu, new String[][] {{CBIntText.get("Show Button Bar"),"B", CBIntText.get("Display the shortcut button toolbar."),   "E", status, dirImages+"blank.gif"}},
            new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected();
                    jxplorer.buttonBar.setVisible(selected);
                    jxplorer.repaint();
                    JXplorer.setProperty("gui.buttonbar", String.valueOf(selected));
                }
            }
        );


        status = ("false".equals(JXplorer.getProperty("gui.searchbar")))?"U":"C";

        setCheckBoxMenu(lookAndFeelMenu, new String[][] {{CBIntText.get("Show Search Bar"),"w", CBIntText.get("Show the quick search tool bar."), "E", status, dirImages+"blank.gif"}},
           	new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected();
                    jxplorer.searchBar.setVisible(selected);
                    jxplorer.repaint();
                    JXplorer.setProperty("gui.searchbar", String.valueOf(selected));
                }
            }
        );

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

				tree = jxplorer.getActiveTree();

		        if (item == refresh)
 					tree.getPopupTool().refresh();

		        jxplorer.repaint();
		    }
		};

		setMenuItem(lookAndFeelMenu, viewListener, new String[] {"-", "", "", "", ""} );

		refresh = setMenuItem(lookAndFeelMenu, viewListener,
			new String[] {CBIntText.get("Refresh"), "Ctrl+R",CBIntText.get("Refreshes an Entry."), "E", dirImages+"refresh.gif"} );

        ButtonRegister br = JXplorer.getButtonRegister();
        br.registerItem(br.REFRESH, refresh);
    }



    /**
     *    This is a bit evil - it links various options, saved in the
     *    dxconfig.txt java properties file, with user menu items.  To
     *    do this requires a few quick utility classes derived from menu
     *    items, which automatically read and set various properties.
     */
    protected void setupOptionsMenu(JMenu optionsMenu)
    {
       // confirm tree operation check box.


        //boolean initStatus =  !("false".equalsIgnoreCase(jxplorer.myProperties.getProperty("option.confirmTreeOperations")));

        /*
         *    A quickie inner class, to give us a JCheckBoxMenuItem that will check
         *    and update from a particular property before repainting (so that if
         *    the property has been changed elsewhere, the menu bar still displays
         *    the correct value...)
         */

        class PropertyCheckBoxMenuItem extends JCheckBoxMenuItem
        {
            final String propName;

            public PropertyCheckBoxMenuItem(String s, String propertyName)
            {
                super(CBIntText.get(s), true);            // state reset on first paint (see below).
                propName = propertyName;

                addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        JXplorer.myProperties.setProperty(propName, String.valueOf(getState()));
                        jxplorer.repaint();
                    }
                });
            }

            // property may be externally changed: recheck every paint!
            public void paint(Graphics g)
            {    // weird !("false"... syntax to force default case to be true...
                boolean state = !("false".equalsIgnoreCase(JXplorer.myProperties.getProperty(propName)));
                if (state != getState()) setState(state);  // nb - this triggers another paint...!
                super.paint(g);
            }
        }

        final PropertyCheckBoxMenuItem confirmOps;
        final PropertyCheckBoxMenuItem confirmTableEditorUpdates;
        final PropertyCheckBoxMenuItem checkSchema;
        final JCheckBoxMenuItem browserSearchAliases;

        confirmOps =
            new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Tree Operations"),  "option.confirmTreeOperations");
        setMenuItemState(optionsMenu, confirmOps, "C", CBIntText.get("Prompt the user whenever the tree will be modified?"), true);

        confirmTableEditorUpdates =
            new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Table Editor Updates"),  "option.confirmTableEditorUpdates");
        setMenuItemState(optionsMenu, confirmTableEditorUpdates, "T", CBIntText.get("Display message to confirm successful updates in Table Editor?"), true);

        checkSchema =
            new PropertyCheckBoxMenuItem(CBIntText.get("Ignore Schema Checking"),  "option.ignoreSchemaOnSubmission");
        setMenuItemState(optionsMenu, checkSchema, "g", CBIntText.get("Don't check entry consistency before submission."), true);

        browserSearchAliases =
            new JCheckBoxMenuItem(CBIntText.get("Resolve Aliases while Browsing"));
        setMenuItemState(optionsMenu, browserSearchAliases, "A", CBIntText.get("Whether to browse the referenced object, or the alias entry itself."), true);
        browserSearchAliases.setState("finding".equals(JXplorer.getProperty("option.ldap.browseAliasBehaviour")));

        //TE: defines a listener for the Advanced Options menu item of the Options menu.
        ActionListener optionsListener = new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JMenuItem item = (JMenuItem)e.getSource();

                if (item == advancedOptions)
                {
                    setUpAdvancedOptions();    //TE: sets up the AdvancedOptions dialog when user clicks on this menu item.
                }
                jxplorer.repaint();
            }
        };

        advancedOptions = setMenuItem(optionsMenu, optionsListener,
                    new String[] {CBIntText.get("Advanced Options"), "d", CBIntText.get("Open the Advanced Options dialog."), "E", ""} );

        // add *another* action listener for specific handling...
        browserSearchAliases.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try
                {
                    if (browserSearchAliases.isSelected())
                    {
                        JXplorer.setProperty("option.ldap.browseAliasBehaviour", "finding");
                        if (jxplorer.jndiBroker.getDirContext() != null)
                        {
                            jxplorer.jndiBroker.getDirContext().addToEnvironment("java.naming.ldap.derefAliases", "finding");
                            //System.out.println("set to: " + jxplorer.jndiBroker.getDirContext().getEnvironment().get("java.naming.ldap.derefAliases"));

⌨️ 快捷键说明

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