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

📄 nodepanel.java

📁 Libgist is an implementation of the Generalized Search Tree, a template index structure that makes i
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
public splitActionListener sal;public pathActionListener pal;public hsubActionListener hsal;public JMenuItem dump, path, split, viewItem;public JMenu view, hsub;public NodePanel(Node anode, SuperNode parent, int id) {    int i;    this.node   = anode;    this.parent = parent;    this.id     = id;        // setFont(new Font("Dialog", Font.PLAIN, 10));        //     if (parent.children[id] != null)    // 	open = parent.children[id].open;    //     else    // 	open = false;    open = anode.open;    // onpath = false;    fontinit = false;    pagenos = true;    addMouseListener(this);    if (parent.td.fm != null) {	fontinit = true;	initFontStuff(parent.td.fm);    }        dump = new JMenuItem("Node Contents");    popup = new JPopupMenu();    popup.add(dump);    val = new viewActionListener(parent.td.tv.desktop, node, this);    JMenuItem menuItem;    // add as many options as there are levels ...    // if only one level, don't add any options at all.    int level = node.topViews.length;    if (level > 1) {		// add submenu if needed ...	view = new JMenu("Subtree View");	view.addActionListener(val);	popup.add(view);	menuItem = new JMenuItem("all");	menuItem.addActionListener(val);	view.add(menuItem);    } else {	// otherwise only add item ...	viewItem = new JMenuItem("Node View");	viewItem.addActionListener(val);	popup.add(viewItem);    }    level--;    for (i = 0; i < level; i++) {	menuItem = new JMenuItem(Integer.toString(i+1));	menuItem.addActionListener(val);	view.add(menuItem);    }    hsub = new JMenu("Highlight Subtree");    path = new JMenuItem("Highlight Path");    split = new JMenuItem("Highlight Split");    dal = new dumpActionListener(parent.td.tv.desktop, node);    dump.addActionListener(dal);    pal = new pathActionListener(node, parent);    path.addActionListener(pal);    sal = new splitActionListener(node, this);    split.addActionListener(sal);    hsal = new hsubActionListener(node);    hsub.addActionListener(hsal);    for (i = 0; i < node.nViews.size(); i++) {	menuItem = new JMenuItem(	    ((NodeView) node.nViews.elementAt(i)).getViewName());	menuItem.addActionListener(hsal);	hsub.add(menuItem);    }    if (node.nViews.size() == 0)	hsub.setEnabled(false);    //    popup.add(view);    popup.add(hsub);    popup.add(path);    popup.add(split);    popup.setInvoker(parent.td.tv);}public void setNode(Node anode, SuperNode parent, int id) {          this.node   = anode;    this.parent = parent;    this.id     = id;        //       if (parent.children[id] != null)    // 	  open = parent.children[id].open;    //       else    // 	  open = false;        open = anode.open;        dal.node = anode;    val.node = anode;    pal.node = anode;    sal.node = anode;    hsal.node = anode;    int i;    JMenuItem menuItem;        // Node we don't have to change anything in view because    // this NodePanel only ever gets set to another node at the same    // level.    // Remove components in the menu ...    hsub.removeAll();    for (i = 0; i < node.nViews.size(); i++) {	menuItem = 	    new JMenuItem(((NodeView) node.nViews.elementAt(i)).getViewName());	menuItem.addActionListener(hsal);	hsub.add(menuItem);    }    if (node.nViews.size() == 0)	hsub.setEnabled(false);    else	hsub.setEnabled(true);}public void paint(Graphics g) {        int width  = getBounds().width;    int height = getBounds().height;    Color back = g.getColor();    int x,y;    float stat;    Color statColor = null;        pallette = parent.td.tv.pallette;        if ((getPreferredSize().width != width) ||	(getPreferredSize().height != height)) {	setSize(getPreferredSize());	// invalidate();	getTopLevelAncestor().validate();	// validate();    }    if (parent.td.shownodes) {		String tipText = "node: " + node.nodenum;		// DbgOutput.println(1,getBounds());	x = (width) / 2 - 5;	y = (height) / 2 - 5;		if (node.onpath) 	    g.setColor(Color.red);	else	    g.setColor(Color.white);		//if (node.onpath)	//g.setColor(new Color(255,0,node.stat));		g.fillRect(x, y, 10, 10);		if (parent.td.tv.showstats) {	    stat = parent.td.tv.stats[node.nodenum];	    if ((Float.isInfinite(stat)) || (Float.isNaN(stat)))		statColor = back;	    else {		// make sure we don't have maxStat == minStat		if (parent.td.tv.ratio > 0) {		    		    int index;		    		    index = (int) Math.floor(			(double) (stat - parent.td.tv.minStat) *			parent.td.tv.ratio);		    if (index > 255)			index = 255;		    else if (index < 0)			index = 0;		    // index = (index == 256) ? 255 : index;		    statColor = pallette[index];		} else		    // if so arbitrarily assign the color.		    statColor = pallette[0];	    }	    g.setColor(statColor);	    setToolTipText(tipText + " stat: " + stat);	    g.fillRect(x+1,y+1,8,8);	} else	    setToolTipText(tipText);		if (open)	    g.drawLine(width/2, y + 10, width/2, height);	    } else {		g.setFont(parent.td.font);		if (!fontinit) {	    initFontStuff(g.getFontMetrics());	}		setToolTipText(null);		x = (width - 1 - bw - border) / 2;	y = (height - 1 - sh - border) / 2;		if (node.onpath) 	    g.setColor(Color.red);	else	    g.setColor(Color.black);		g.drawRect(x,y,bw + 2*inborder, sh + 2*inborder);	// g.drawRect(0,0,width,height);		stat = 0;		if (!parent.td.tv.showstats)	    g.setColor(Color.white);	else {	    stat = parent.td.tv.stats[node.nodenum];	    if ((Float.isInfinite(stat)) || (Float.isNaN(stat)))		statColor = back;	    else {		// make sure we don't have maxStat == minStat		if (parent.td.tv.ratio > 0) {		    		    int index;		    		    index = (int) Math.floor(			(double) (stat - parent.td.tv.minStat) *			parent.td.tv.ratio);		    if (index > 255)			index = 255;		    else if (index < 0)			index = 0;		    // index = (index == 256) ? 255 : index;		    		    statColor = pallette[index];		    		} else		    // if so arbitrarily assign the color ...		    statColor = pallette[0];	    }	    g.setColor(statColor);	    	    setToolTipText("stat: " + stat);	}		g.fillRect(x+1,y+1,bw + 2*inborder - 1, sh + 2*inborder - 1);		if (parent.td.tv.showstats) {	    	    float[] hsb = new float[3];	    int rgb = statColor.getRGB();	    	    Color.RGBtoHSB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF,		rgb & 0xFF, hsb);	    	    if (hsb[2] >= 0.6) {		if (hsb[1] <= 0.9)		    g.setColor(Color.black);		else 		    g.setColor(Color.white);	    }	    else		g.setColor(Color.white);	} else	    g.setColor(Color.black);		g.drawString(Integer.toString(node.nodenum),	    x + inborder + 1 + ((bw - sw) / 2), y + inborder + sh - descent);		if (open)	    g.drawLine(width/2, y + sh + 2*inborder, width/2, height);    }        g.setColor(back);}// Stuff needed to be done so we can correctly format our text.public void initFontStuff(FontMetrics fm) {        if (!fontinit)	parent.td.fm = fm;        sw = fm.stringWidth(Integer.toString(node.nodenum));    bw = fm.getMaxAdvance() * parent.maxwidth;    sh = fm.getHeight();    descent = fm.getDescent();        panelSize = new Dimension(2*(border + inborder) + bw, 	2*(border + inborder) + sh);        setSize(panelSize);        if (!fontinit) {	getParent().getParent().setSize(	    getParent().getParent().getPreferredSize());	getParent().getParent().setVisible(false);	getTopLevelAncestor().validate();	getParent().getParent().setVisible(true);    }        fontinit = true;}public Dimension getPreferredSize() {        if (parent.td.shownodes) 	return npanelSz;    else	return panelSize;}public Dimension getMinimumSize() {        if (parent.td.shownodes)	return npanelSz;    else	return panelSize;}public void mouseClicked(MouseEvent e) {    boolean result;        if (SwingUtilities.isLeftMouseButton(e) && (e.getSource() == this)) {	if (open)	    result = parent.closeSub(id);	else	    result = parent.openSub(id);		if (open != result) {	    open = result;	    node.open = open;	    parent.td.tv.hitcomp = parent;	    parent.td.tv.centerhit = true;	    invalidate();	    // getTopLevelAncestor().validate();	    // getTopLevelAncestor().repaint();	    parent.td.repaint();	    parent.td.tv.eq.postEvent(parent.td.tv.ae);	}    } else if (SwingUtilities.isMiddleMouseButton(e)) {	try {	    parent.td.tv.showPath(node.nodenum);	    // parent.td.tv.showPath(node.nodenum);	    // parent.td.tv.center();	    	} catch (Exception ex) {	    System.out.println("Couldn't show path to " + node.nodenum);	    System.out.println(ex);	}    }        }public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mousePressed(MouseEvent e) {        if (SwingUtilities.isRightMouseButton(e)) {	Point p = e.getPoint();	SwingUtilities.convertPointToScreen(p, this);	popup.setLocation(p.x, p.y);	popup.setVisible(true);    }    }public void mouseReleased(MouseEvent e) {    //       if (SwingUtilities.isRightMouseButton(e)) {    // 	  popup.setVisible(false);    //       }}}

⌨️ 快捷键说明

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