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

📄 dirpanel.java

📁 J[2]EE JavaJNDI jndi-1_1-ea2-demo
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    waitCursor();	    DirTreeNode target = 		(DirTreeNode)evt.getPath().getLastPathComponent();	    target.loadChildren(false);	}	public void loadCompleted(boolean ok) {	    if (ok) {		resetStatus();	    }	    restoreCursor();	}	public void treeCollapsed(TreeExpansionEvent evt) {	    resetStatus();   // Reset status line	}    }*/    /**     * Double-clicking on a list item displays its attributes.     */    class DoubleClickHandler extends MouseAdapter {	public void mouseClicked(MouseEvent evt) {	    if (evt.getClickCount() == 2) {		int index = list.locationToIndex(evt.getPoint());		ListModel lm = list.getModel();		DirTreeNode target = (DirTreeNode)lm.getElementAt(index);		showAttributes(target);	    }	}    }    /**     * Creates the toolbar.     */    JButton configButton;    JToolBar constructToolBar() {	JToolBar toolBar = new JToolBar();	// eliminate 	toolBar.setMargin(new Insets(0, 0, 0, 0));	addTool(toolBar, "class", "Class", new ShowClassAction(),	    "show class");	addTool(toolBar, "attributes", "Attributes", new ShowAttributesAction(),	    "show attributes");	addTool(toolBar, "search", "Search", new SearchAction(),	    "perform search");	addTool(toolBar, "schema", "Schema", new SchemaAction(),	    "get schema");	toolBar.addSeparator();	addTool(toolBar, "new", "New", new CreateChildAction(), 	    "create new child"); 	addTool(toolBar, "remove", "Remove", new RemoveAction(), 	    "remove selected node");	toolBar.addSeparator();	addTool(toolBar, "reload", "Reload", new ReloadAction(), 	    "reload selected node");	configButton = 	    addTool(toolBar, "configure", "Configure", new ConfigAction(), 	    "configure root and environment properties");	addTool(toolBar, "console", "Console", new ConsoleAction(),	    "display console window");	addTool(toolBar, "help", "Help", new HelpAction(), "how to use browser");	return toolBar;    }    /**     * Adds an item to the toolbar.     */    void addTool(JToolBar toolBar, String name, String label, ActionListener act) {	addTool(toolBar, name, label, act, name);    }    /**     * Adds an item to the toolbar.     */    JButton addTool(JToolBar toolBar, String name, String label,  	ActionListener act, String tooltip) {	JButton b = (JButton) toolBar.add(	    new JButton(		Browser.browser.loadImageIcon(name + ".gif", tooltip)));	b.setHorizontalTextPosition(AbstractButton.CENTER);	b.setVerticalTextPosition(AbstractButton.BOTTOM);	b.setToolTipText(tooltip);	if (act != null)	    b.addActionListener(act);	return b;    }    /**      * Show attributes of currently selected list node.      */    class ShowAttributesAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    ListModel lm = list.getModel();	    int target = list.getSelectedIndex();	    if (target >= 0) {		showAttributes((DirTreeNode)lm.getElementAt(target));		return;	    }	    // no item in list is selected, try selected tree node	    DirTreeNode node = (DirTreeNode)getSelectedNode();	    if (node != null) {		showAttributes(node);	    } else {		setStatus("Select an item in tree or list first.");	    }	}    }    /**     * Moves component (x,y) relative to top-left corner of this panel.     */    void moveWindow(Component c) {	Point pt = getLocationOnScreen();	Dimension dim = getSize();		c.setLocation(pt.x+(dim.width/2), pt.y+(dim.height/2));    }    /**      * Show attributes in 2-column table in a popup window.      */    void showAttributes(DirTreeNode target) {	try {	    waitCursor();	    Context parentCtx = getParentContext(target);	    if (parentCtx instanceof DirContext) {		String name = 		    ((DirData)(target.getUserObject())).getName();DirPanel.debugName("Get Attributes", name);		Attributes attrs = ((DirContext)parentCtx).getAttributes(name);		moveWindow(new AttrDialog((DirContext)parentCtx, name, attrs));	    } else {		setStatus("Can only get attributes from DirContext");	    }	} catch (NamingException e) {	    if (debug) e.printStackTrace();	    setStatus(e);	} finally {	    restoreCursor();	}    }    /**      * Create new child for currently selected tree node.      */    class CreateChildAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    DirTreeNode target = (DirTreeNode)getSelectedNode();	    // If no node has been selected, return	    if (target == null) {		setStatus("Select an item in tree.");		return;	    }	    // Can only create a child if node is a context	    Object obj = ((DirData)target.getUserObject()).getObject();	    if (!(obj instanceof Context)) {		setStatus("A leaf cannot have a child.");		return;	    }	    waitCursor();	    // Get any attributes this node has and use as	    // template for child.	    Attributes attrs = null;	    String name = 		((DirData)(target.getUserObject())).getName();	    try {		Context parentCtx = getParentContext(target);		if (parentCtx instanceof DirContext) {DirPanel.debugName("Getting Attributes for Creating Child", name);		    attrs = ((DirContext)parentCtx).getAttributes(name);		}	    } catch (NamingException e) {} // ignore	    // Create frame 	    CreateDialog d = 		new CreateDialog((Context)obj, name, attrs);	    moveWindow(d);	    d.addCreateListener(new CreateResultAction(target));	    restoreCursor();	}    }    /**     * Action handler for updating tree view when node has been created     */    class CreateResultAction implements CreateListener {	DirTreeNode parentNode;	public CreateResultAction(DirTreeNode n) {	    parentNode = n;	}	// Invoked to update tree and list views when a new node has been created	public void objectCreated(String name, Context obj, Attributes attrs) {	    // %%% Currently nothing is done about attrs	    DirTreeNode child = new DirTreeNode(new DirData(name, obj, attrs));	    // Update tree	    treeModel.insertNodeInto(child, parentNode, 0);	    // Update list	    DefaultListModel lm = (DefaultListModel)list.getModel();	    lm.addElement(child);	}    }    /**     * Creates search window for specifying search.     */    class SearchAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    // Search selected node	    DirTreeNode target = (DirTreeNode)getSelectedNode();	    if (target == null) {		setStatus("Select a tree node first.");		return;	    }	    try {		waitCursor();		Context parentCtx = getParentContext(target);		if (parentCtx instanceof DirContext) {		    // should pass status as param		    SearchDialog s =			new SearchDialog((DirContext)parentCtx, 			    ((DirData)(target.getUserObject())).getName());		    moveWindow(s);		    s.addSearchListener(new SearchResultAction(target));		} else {		    setStatus("Can only search a DirContext");		}	    } catch (NamingException e) {		if (debug) e.printStackTrace();		setStatus(e);	    } finally {		restoreCursor();	    }	}    }    /**     * Action Handler for updating display after search completes.     */    class SearchResultAction implements SearchListener {	DirTreeNode parentNode;	public SearchResultAction(DirTreeNode n) {	    parentNode = n;	}	// Invoked to update the list view to display search results	public void searchCompleted(NamingEnumeration results) {	    DefaultListModel lm = (DefaultListModel)list.getModel();	    lm.clear();	    waitCursor();	    try {		while(results.hasMoreElements()) {		    SearchResult r = (SearchResult)results.next();		    DirTreeNode fakeNode = new DirTreeNode(new DirData(			r.getName(), r.getClassName(), r.getObject(), 			r.getAttributes()));		    fakeNode.setParent(parentNode);		    lm.addElement(fakeNode);		}		resetStatus();	    } catch (NamingException e) {		if (debug) e.printStackTrace();		setStatus(e);	    } finally {		restoreCursor();	    }	    // Refresh list area	    list.invalidate();	    list.validate();	}    }        // Invoked when environment properties have been changed    public void configurationUpdated(String newRoot, Hashtable newEnv) {	reinitialize(newRoot, newEnv);    }    // Create window for updating environment properties    class ConfigAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    waitCursor();	    // Create frame for configuring environment properties	    ConfigDialog config = new ConfigDialog(root, env);	    moveWindow(config);	    // Add self for receiving updates from frame	    config.addConfigListener(DirPanel.this);	    restoreCursor();	}    }    // Create window for displaying console messages    class ConsoleAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    waitCursor();	    moveWindow(new ConsoleDialog(Browser.console));	    restoreCursor();	}    }    // Create window for viewing schema of selected node    class SchemaAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    // Search selected node	    DirTreeNode target = (DirTreeNode)getSelectedNode();	    if (target == null) {		setStatus("Select a tree node first.");		return;	    }	    try {		waitCursor();		DirData data = (DirData)target.getUserObject();		Object obj = data.getObject();		if (!(obj instanceof DirContext)) {		    setStatus("Can only get schema from a DirContext.");		    return;		}		Context parentCtx = getParentContext(target);		DirContext schema = ((DirContext)obj).getSchema("");		if (schema == null) {		    setStatus("No schema available for '" + 			data.getName() + "'");		    return;		}		moveWindow(new SchemaDialog(schema, data.getName(), env));	    } catch (NamingException e) {		if (debug) e.printStackTrace();		setStatus(e);	    } finally {		restoreCursor();	    }	}    }    // Show class name of selected list or tree node    class ShowClassAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {	    DirTreeNode target;	    // Try list first	    ListModel lm = list.getModel();	    int ind = list.getSelectedIndex();	    if (ind > 0) {		target = (DirTreeNode)lm.getElementAt(ind);	    } else {	    // Try tree		target = (DirTreeNode)getSelectedNode();		if (target == null) {		    setStatus("Select a tree node first.");		    return;		}	    }	    JOptionPane.showMessageDialog(		DirPanel.this, 		((DirData)target.getUserObject()).getClassName(),		"Class of '" + ((DirData)(target.getUserObject())).getName() +		"'",		JOptionPane.PLAIN_MESSAGE);	}    }    class HelpAction implements ActionListener {	public void actionPerformed(ActionEvent evt) {

⌨️ 快捷键说明

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