📄 decisiontreetreeviewcellrenderer.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Created on Jul 7, 2005
*
*/
package eti.bi.alphaminer.patch.standard.operation.result.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;
import eti.bi.common.Locale.Resource;
import eti.bi.util.NumberFormatter;
import weka.classifiers.trees.j48.ClassifierTree;
/**
* Each of the tree node content will be rendered in a JPanel. In the JPanel,
* the splitting conditions, results(total_cases/wrong cases), cases per class/cases percentage
* will be shown. Icons can be added if necessary.
*
* @author TWang. June 7, 2005.
*/
public class DecisionTreeTreeViewCellRenderer extends JPanel implements
TreeCellRenderer {
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel m_ConditionsLabel;
private JLabel m_StatisticsLabel;
private double[] m_Stat;
private int m_Index;
private double m_Total;
private StringBuffer m_StatisticsBuff;
public DecisionTreeTreeViewCellRenderer() {
super();
setLayout(new BorderLayout());
setBorder(BorderFactory.createEtchedBorder());
m_ConditionsLabel = new JLabel(Resource.srcStr("DECISIONTREE_CONDITIONS"));
m_StatisticsLabel = new JLabel("statics");
// m_Icon = new JLabel(ResourceLoader.getImageIcon(m_IconPath));
m_StatisticsBuff = new StringBuffer("");
add(m_ConditionsLabel, BorderLayout.NORTH);
add(m_StatisticsLabel, BorderLayout.CENTER);
}
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean isSelected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
Object content = ((DefaultMutableTreeNode) value).getUserObject();
if(content instanceof ClassifierTree){
m_ConditionsLabel.setText(((ClassifierTree)content).getM_NodeContent());
m_Stat = ((ClassifierTree)content).getM_localModel().distribution().getClassDist();
m_StatisticsBuff.delete(0, m_StatisticsBuff.length());
m_Total = 0;
for(m_Index=0; m_Index<m_Stat.length; m_Index++){
m_Total += m_Stat[m_Index];
}
m_StatisticsBuff.append("<html><font color=\"#0000FF\"> Total (" + NumberFormatter.decimalFormat(m_Total,0)+ ")</font> ");
for(m_Index=0; m_Index<m_Stat.length; m_Index++){
try {
m_StatisticsBuff.append(" <font color=\"#0000FF\">"+ ((ClassifierTree)content).getClassLabel(m_Index) +"</font>("+ NumberFormatter.decimalFormat(m_Stat[m_Index],0)+" , "+ weka.core.Utils.roundDouble(100*m_Stat[m_Index]/m_Total, NumberFormatter.MAX_FRACTION_DIGIT)+"%)");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
m_StatisticsBuff.append("</html>");
m_StatisticsLabel.setText(m_StatisticsBuff.toString());
// Visual effects
setEnabled(tree.isEnabled());
if (isSelected) {
setForeground(Color.BLUE);
} else {
// setBackground(m_treeNodeBackCol);
setBackground(tree.getBackground());
setForeground(tree.getForeground());
}
}
else{
m_ConditionsLabel.setText("");
m_StatisticsLabel.setText(content.toString());
}
return this;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -