📄 comparisonstree.java
字号:
if (isHashPrinted && mismEqRecs[i].hasParts()) continue; count++; // number of classes might have been limited if (count > len) break; // list of mismatched NetObjects List<List<NetObjReport>> mism = mismEqRecs[i].getNotMatchedNetObjs(); JLabel labels[] = new JLabel[4]; String descr[] = new String[2]; // get names of the first wires in both cells String instDescr = null; for (int cell=0; cell < 2; cell++) { if (mism.get(cell).size() == 0) { descr[cell] = "{ }"; } else if (mism.get(cell).size() > 0) { instDescr = mism.get(cell).get(0).instanceDescription(); descr[cell] = createFirstWireOverview(instDescr, (mism.get(cell).size() > 1)); } } // create count of Wires in the class StringBuffer lab3Name = new StringBuffer(24); lab3Name.append("["); int size; if (isHashPrinted) size = mismEqRecs[i].maxSize(); else size = Math.max(mism.get(0).size(), mism.get(1).size()); if (size > MAX_LIST_ELEMENTS) lab3Name.append("first " + MAX_LIST_ELEMENTS + " of "); lab3Name.append(size + "]"); StringBuffer name = new StringBuffer(32); // class sequence number labels[0] = new JLabel("#" + count + " : "); labels[0].setHorizontalAlignment(SwingConstants.RIGHT); name.append(labels[0].getText() + " "); maxWidth0 = Math.max(labels[0].getPreferredSize().width, maxWidth0); // name of the first Wire from the first Cell labels[1] = new JLabel(descr[0]); name.append(descr[0] + " "); maxWidth1 = Math.max(labels[1].getPreferredSize().width, maxWidth1); // name of the first Wire from the second Cell labels[2] = new JLabel(descr[1]); name.append(descr[1] + " "); maxWidth2 = Math.max(labels[2].getPreferredSize().width, maxWidth2); // max size of classes (count) labels[3] = new JLabel(lab3Name.toString()); name.append(labels[3].getText()); for (int j=0; j<4; j++) { labels[j].setBorder(border); labels[j].setFont(font); } data.setFullName(name.toString()); wireClassNodes[compNdx][count-1] = new WireClassNode(labels, areLeaves); if (count == 1) height = labels[0].getPreferredSize().height; } // apply the computed dimensions to all Wire class nodes if (count > 0) { Dimension dim[] = new Dimension[3]; dim[0] = new Dimension(maxWidth0 , height); dim[1] = new Dimension(maxWidth1 + 10, height); dim[2] = new Dimension(maxWidth2 + 10, height); for (int j=0; j<count; j++) wireClassNodes[compNdx][j].setTextLabelDimension(dim); } } private String createFirstWireOverview(String instDescr, boolean hasMore) { // get the name of the first Wire in the class String descr = parentPane.cleanNetObjectName(instDescr); int ind = descr.indexOf(" in Cell: "); if (ind > 0) descr = descr.substring(0, ind).trim(); // limit name length if (descr.length() > MAX_NAME_LEN) descr = descr.substring(0, MAX_NAME_LEN) + "..."; // surround name by brackets if (hasMore) // if more than one Wire belongs to the class descr = "{ " + descr + ",...}"; else descr = "{ " + descr + " }"; return descr; } /** * This mouse adapter is used to get right mouse click events and * trigger the popup menu. */ private class TreeMouseAdapter extends MouseAdapter { public void mousePressed(MouseEvent e) { if (! (e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3)) return; JTree aTree = (JTree)e.getSource(); if (aTree.getRowForLocation(e.getX(), e.getY()) != -1) { TreePath selPath = aTree.getPathForLocation(e.getX(), e.getY()); DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent(); TreeNode data = (TreeNode)node.getUserObject(); // extract node name to be copied to clipboard clipboard = data.toString(); popup.show(e.getComponent(), e.getX(), e.getY()); } } } /** * This class is a container of a tree node data. Each DefaultMutableTreeNode in * ComparisonTree has a TreeNode as a data object. */ static class TreeNode { /* --- node types ---*/ public static final int TITLE = 0; public static final int COMP_TITLE = 1; public static final int EXPORTS = 2; public static final int PART = 3; public static final int WIRE = 4; public static final int PARTLEAF = 5; public static final int WIRELEAF = 6; public static final int SIZES = 7; public static final int EXPORT_ASSERTS = 8; public static final int EXPORT_NET_CONF = 9; public static final int EXPORT_CHR_CONF = 10; public static final int UNRECOG_PART = 11; /** comparison index */ public final int compNdx; /** equiv. class */ public final int eclass; /** type */ public final int type; /** parent node */ private TreeNode parent; /** full name. Used in tree node names */ private String fullName; /** full name. Used in right pane row names */ private String shortName; /** If this node represents a wire class, then wireClassNum is the * index of this class in EquivRecReport array of the corresponding * NccComparisonResult object. Otherwise is -1. */ private int wireClassNum = -1; public TreeNode(TreeNode parent, String fullName, int compNdx, int eclass, int type) { this.parent = parent; this.fullName = fullName; shortName = fullName; this.compNdx = compNdx; this.eclass = eclass; this.type = type; } public void setFullName(String n) { fullName = n; } public void setShortName(String n) { shortName = n;} /** Only for nodes with type WIRE */ public void setWireClassNum(int num) { if (type != WIRE) return; wireClassNum = num; } public String getFullName() { return fullName; } public String getShortName() { return shortName; } public TreeNode getParent() { return parent; } public int getWireClassNum() { return wireClassNum; } public String toString() { return fullName; } } /** * This class encapsulates a Wire class tree node * Specifically, it encapsulates the panel with labels used as its name */ private static class WireClassNode { /** top-level panel */ private JPanel treeNodePanel; /** text-only panel */ private JPanel textPanel; /** icon label */ private JLabel iconLabel; /** text labels */ private JLabel textLabels[]; /** true if node is leaf */ private boolean isLeaf; /** true if node is expanded */ private boolean expanded = false; /** true if node is selected */ private boolean selected = false; /** true if shared data was initialized */ private static boolean inited = false; /* --- shared data --- */ private static Color selBackgnd, deselBackgnd, selText, deselText; private static Icon leafIcon, openIcon, closedIcon; private static Border border = BorderFactory.createEmptyBorder(); public WireClassNode(JLabel labels[], boolean leaf) { if (!inited) init(); textLabels = labels; isLeaf = leaf; textPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); textPanel.setBorder(border); textPanel.setBackground(deselBackgnd); for (int j=0; j<4; j++) textPanel.add(textLabels[j]); treeNodePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); treeNodePanel.setBorder(border); treeNodePanel.setBackground(deselBackgnd); if (isLeaf) iconLabel = new JLabel(leafIcon); else iconLabel = new JLabel(closedIcon); iconLabel.setBorder(border); iconLabel.setText(" "); treeNodePanel.add(iconLabel); treeNodePanel.add(textPanel); } /** * Get colors and icons from default renderer * @param renderer instance of the default tree node renderer */ private static void init() { DefaultTreeCellRenderer defCellRenderer = new DefaultTreeCellRenderer(); selBackgnd = defCellRenderer.getBackgroundSelectionColor(); deselBackgnd = defCellRenderer.getBackgroundNonSelectionColor(); selText = defCellRenderer.getTextSelectionColor(); deselText = defCellRenderer.getTextNonSelectionColor(); leafIcon = defCellRenderer.getDefaultLeafIcon(); openIcon = defCellRenderer.getDefaultOpenIcon(); closedIcon = defCellRenderer.getDefaultClosedIcon(); inited = true; } public void select() { if (selected) return; textPanel.setBackground(selBackgnd); for (int i=0; i<4; i++) textLabels[i].setForeground(selText); selected = true; } public void deselect() { if (!selected) return; textPanel.setBackground(deselBackgnd); for (int i=0; i<4; i++) textLabels[i].setForeground(deselText); selected = false; } public void expand() { if (isLeaf || expanded) return; iconLabel.setIcon(openIcon); expanded = true; } public void collapse() { if (isLeaf || !expanded) return; iconLabel.setIcon(closedIcon); expanded = false; } public void setTextLabelDimension(Dimension[] dim) { for (int j=0; j<dim.length; j++) { textLabels[j].setMinimumSize(dim[j]); textLabels[j].setPreferredSize(dim[j]); } } /** * Get top-level panel with all labels and icon * @return the top-level panel to be rendered to a tree node */ public JPanel getPanel() { return treeNodePanel; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -