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

📄 nodepanel.java

📁 Libgist is an implementation of the Generalized Search Tree, a template index structure that makes i
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// NodePanel.java// Copyright (c) 1998, Regents of the University of California// $Id: NodePanel.java,v 1.2 1999/06/27 00:17:38 marcel Exp $import javax.swing.*;import java.awt.*;import java.awt.event.*;public class NodePanel extends JComponent implements MouseListener {  public static int border   = 2;  public static int inborder = 1;  public Dimension panelSize = new Dimension(100,100);  public Dimension npanelSz  = new Dimension(14,14);  public Dimension borderSz;  // font stuff ;  public int sh, sw, bw, descent;  public int id;  public Node node;// public boolean onpath;  public boolean open, pagenos, fontinit;  public SuperNode parent;  public Color[] pallette;  public JPopupMenu popup;// This class handles the what happens when "dump" is selected// from popup-menu.class dumpActionListener implements ActionListener {public JDesktopPane desktop;public Node         node;public dumpActionListener(JDesktopPane desktop, Node node) {    this.desktop = desktop;    this.node    = node;}public void actionPerformed(ActionEvent e) {        // If the node doesn't have contents window associated ... add one.    if (node.nDump == null) {	node.nDump = new NodeDump(node, parent.td.tv);	desktop.add(node.nDump, JLayeredPane.PALETTE_LAYER);    }        // If we removed the node window from the desktop ... add it.    if (!desktop.isAncestorOf(node.nDump)) {	// DbgOutput.println(1,"HEY5");			    	desktop.add(node.nDump, JLayeredPane.PALETTE_LAYER);	try {	    node.nDump.setClosed(false);	} catch (Exception ex) {	    System.out.println("PROP: " + ex);	}    }        try {	if (node.nDump.isIcon())	    node.nDump.setIcon(false);	else	    // If we hid the dump window, make is visible.	    if (!node.nDump.isVisible())		node.nDump.setVisible(true);    } catch (Exception ex) {	System.out.println("Couldn't deiconify: " + ex);    }    // Make sure the window pops to the front, otherwise    // sometimes it is hard to find.    node.nDump.toFront();}}// This class handles the what happens when "view" is selected// from popup-menu.class viewActionListener implements ActionListener {  public JDesktopPane desktop;public Node         node;public NodePanel    panel;public viewActionListener(JDesktopPane desktop, Node node, NodePanel panel) {    this.desktop = desktop;    this.node    = node;    this.panel   = panel;}public void addToViewsBelow(NodeView aView, int numLevels, NodePanel aPanel) {    // DbgOutput.println(1,"Level: " + numLevels);    if (numLevels == 0)	return;    addViewToPanel(aPanel, aView);    //    DbgOutput.println(1,"Node: " + aPanel.node.nodenum);    SuperNode child = aPanel.parent.children[aPanel.id];    int i;//     if (child != null)// 	DbgOutput.println(1,"Child: " + aPanel.node.nodenum);//     else// 	DbgOutput.println(1,"Null child");    if (child != null && numLevels > 1) {	for (i = 0; i < child.min; i++) {	    child.nodes[i].nViews.addElement(aView);	}	for (i = 0; i < child.numPanels ; i++) {	    if (child.panels[i] == null)		DbgOutput.println(1,"Child of: " + aPanel.node.nodenum + 				   " Panel: " + i + 				   " numPanels: " + child.numPanels);	    addToViewsBelow(aView, numLevels - 1, child.panels[i]);	    // child.panels[i].node.nodeViews.addElement(aView);	}	for (i = child.min + child.panels.length; 	     i < child.nodes.length; i++) {	    child.nodes[i].nViews.addElement(aView);	}    }}public void addViewToPanel(NodePanel aPanel, NodeView aView) {    // Since we are going to add the node view, we must enable    // the menu.    if (aPanel == null) {	DbgOutput.println(1,"NULL PANEL: ");	return;    }    if (aPanel.node.nViews.size() == 0)	aPanel.hsub.setEnabled(true);    // Add the menu item to the list for this node ...    JMenuItem menuItem = 	new JMenuItem(aView.getViewName());    menuItem.addActionListener(aPanel.hsal);    aPanel.hsub.add(menuItem);    aPanel.node.nViews.addElement(aView);}public void actionPerformed(ActionEvent e) {    // Same template as the dump class.    String command;    int viewIndex;    command = e.getActionCommand();    DbgOutput.println(1,node.nodenum + " : " + command);        try {	if (command.equals("all") || command.equals("Node View"))	    viewIndex = 0;	else	    viewIndex = Integer.parseInt(command);    } catch (Exception ex) {	System.out.println("Didn't understand view command: " + command);	System.out.println(ex);	return;    }    if (node.topViews[viewIndex] == null) {		int depth;	if (command.equals("all") || command.equals("Node View"))	    depth = Libgist.getLevel(node.nodenum);	else	    depth = viewIndex;	node.topViews[viewIndex] = new NodeView(node, parent.td.tv, viewIndex);	node.topViews[viewIndex].path = parent.td.tv.path;	// Since we are going to add the node view, we must enable	// the menu.// 	if (node.nViews.size() == 0)// 	    panel.hsub.setEnabled(true);	// Add the menu item to the list for this node ...// 	JMenuItem menuItem = // 	    new JMenuItem(node.topViews[viewIndex].getViewName());// 	menuItem.addActionListener(panel.hsal);	// 	panel.hsub.add(menuItem);// 	node.nViews.addElement(node.topViews[viewIndex]);	// addViewToPanel(panel, node.topViews[viewIndex]);	//	// Make calls here to add the view to nodes below this view.	//	addToViewsBelow(node.topViews[viewIndex], depth, panel);	desktop.add(node.topViews[viewIndex], JLayeredPane.PALETTE_LAYER);    }    if (!desktop.isAncestorOf(node.topViews[viewIndex])) {	desktop.add(node.topViews[viewIndex], JLayeredPane.PALETTE_LAYER);	try {	    // If it was showing a node split before ... remove it	    // and show the path.	    if (node.topViews[viewIndex].can.showSplit)		node.topViews[viewIndex].showPathChild();	    node.topViews[viewIndex].setClosed(false);	} catch (Exception ex) {	    System.out.println("Couldn't add existing view: " + ex);	}    }    try {	if (node.topViews[viewIndex].isIcon())	    node.topViews[viewIndex].setIcon(false);	else if (!node.topViews[viewIndex].isVisible())	    node.topViews[viewIndex].setVisible(true);    } catch (Exception ex) {	System.out.println("Couldn't deiconify: " + ex);    }    node.topViews[viewIndex].toFront();    if (false) {	if (node.nView == null) {	    node.nView = new NodeView(node, parent.td.tv, 0);	    node.nView.path = parent.td.tv.path;	    desktop.add(node.nView, JLayeredPane.PALETTE_LAYER);	}		if (!desktop.isAncestorOf(node.nView)) {	    // DbgOutput.println(1,"HEY5");			    	    desktop.add(node.nView, JLayeredPane.PALETTE_LAYER);	    try {		if (node.nView.can.showSplit)		    node.nView.showPathChild();		node.nView.setClosed(false);	    } catch (Exception ex) {		DbgOutput.println(1,"PROP: " + ex);	    }	}		if (!node.nView.isVisible())	    node.nView.setVisible(true);		node.nView.toFront();    }}    }class hsubActionListener implements ActionListener {public Node node;public hsubActionListener(Node node) {    this.node = node;}public void actionPerformed(ActionEvent e) {        String viewName = e.getActionCommand();    int i;    NodeView view = null;    for (i = 0; i < node.nViews.size(); i++) {	view = (NodeView) node.nViews.elementAt(i);	if (viewName.equals(view.getViewName()))	    break;    }    if (view != null) {	int nlevels;	// this node's height is node.topViews.length	// So the number of levels you want to show is		nlevels = view.levels - (view.node.topViews.length - 	    node.topViews.length);	if (nlevels > 0) {	    view.highlightSubtree(node.nodenum, nlevels);	    view.repaint();	}	else	    DbgOutput.println(1,"Not right number of levels: " + nlevels);    } else 	DbgOutput.println(1,"Don't understand command: " + viewName);}}// This class handles the what happens when "split" is selected// from popup-menu.class splitActionListener implements ActionListener {public NodePanel    panel;public Node         node;public int splitItems[];private ActionEvent nodeViewAction;private ActionEvent allViewAction;public splitActionListener(Node node, NodePanel panel) {    splitItems = new int[Libgist.maxChildren()];    this.node = node;    this.panel = panel;    nodeViewAction = 	new ActionEvent(panel.dump, ActionEvent.ACTION_PERFORMED, "1");    allViewAction =	new ActionEvent(panel.dump, ActionEvent.ACTION_PERFORMED, "all");}public void actionPerformed(ActionEvent e) {        try {	NodeView aView;		int nl = Libgist.getLevel(node.nodenum);	if (nl == 1)	    aView = node.topViews[0]; // location should contain Node View	else	    aView = node.topViews[1];	// If a view doesn't already exist, add one	// for this node.	if (aView == null) {	    if (nl == 1) {		panel.val.actionPerformed(allViewAction);			aView = node.topViews[0]; // location should contain Node View	    }	    else {		panel.val.actionPerformed(nodeViewAction);		aView = node.topViews[1];	    }	}	if (aView.isClosed())	    aView.setClosed(false);	else if (aView.isIcon())	    aView.setIcon(false);	else	    aView.setVisible(true);		int num;		final int nodenum = node.nodenum;		num = Libgist.pickSplit(nodenum, splitItems);		aView.showSplit(splitItems, num);		aView.toFront();		aView.repaint();    } catch (Exception ex) {	System.out.println("split action: " + ex);    }}}// This class handles the what happens when "path" is selected// from popup-menu.class pathActionListener implements ActionListener {public SuperNode parent;public Node node;public pathActionListener(Node node, SuperNode parent) {        this.node = node;    this.parent = parent;}public void actionPerformed(ActionEvent e) {        try {	// DbgOutput.println(1,"PATH: " + node.nodenum);	parent.td.tv.showPath(node.nodenum);    } catch (LibgistException ex) {	System.out.println("Error showing path: " + ex);    }    }}public dumpActionListener dal;public viewActionListener val;

⌨️ 快捷键说明

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