📄 artable.java
字号:
/*---------------------------------------------------------------------- File : ARTable.java Contents: association rule visualization table Author : Christian Borgelt History : 06.07.2004 file created----------------------------------------------------------------------*/package arview;import java.io.*;import java.awt.*;import java.util.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.event.*;/*--------------------------------------------------------------------*/class ARModel extends AbstractTableModel {/*--------------------------------------------------------------------*/ private ARSet arset; /* rule set to display */ private int cnt; /* number of table columns */ private String[] names; /* names of columns */ /*------------------------------------------------------------------*/ public ARModel (ARSet arset) { /* --- create a table model */ this.arset = arset; /* note the association rule set */ this.cnt = ((arset.getCount() > 0) && (arset.getRule(0).getAREM() > -Float.MAX_VALUE)) ? 6 : 5; this.names = new String[this.cnt]; this.names[0] = "consequent"; this.names[1] = "antecedent"; this.names[2] = "support"; this.names[3] = "confidence"; this.names[4] = "lift value"; if (this.cnt > 5) this.names[5] = "add. eval."; } /* ARModel() */ /* create the column names */ /*------------------------------------------------------------------*/ public int getRowCount () { return this.arset.getCount(); } public int getColumnCount () { return this.cnt; } public String getColumnName (int i) { return this.names[i]; } /*------------------------------------------------------------------*/ public Object getValueAt (int row, int col) { /* --- get value of table field */ int i, n; /* loop variables */ float x; /* buffer for add. evaluation */ ARule rule; /* rule corresponding to row */ StringBuffer b; /* buffer for rule body */ rule = this.arset.getRule(row); switch (col) { /* evaluate the column */ case 0: return rule.getHead(); case 1: b = new StringBuffer(); for (n = rule.getSize(), i = 0; i < n; i++) { if (i > 0) b.append(", "); b.append(rule.getBody(i)); } return b.toString(); case 2: return rule.getSupp() +"/" +rule.getSAbs(); case 3: return "" +rule.getConf(); case 4: return "" +rule.getLift(); default: x = rule.getAREM(); return (x > -Float.MAX_VALUE) ? "" +x : ""; } } /* getValueAt() */} /* ARModel *//*--------------------------------------------------------------------*/public class ARTable extends JTable {/*--------------------------------------------------------------------*/ private ARSet arset; /* rule set to display */ private ARModel model; /* table model */ /*------------------------------------------------------------------*/ public ARTable (ARSet arset) { /* --- create an ass. rule table */ super(); this.setARSet(arset); } /* ARTable() */ /*------------------------------------------------------------------*/ public ARTable () { this(null); } /*------------------------------------------------------------------*/ public ARSet getARSet () { return this.arset; } /*------------------------------------------------------------------*/ public void setARSet (ARSet arset) { /* --- set new rule set */ Dimension size; /* table size */ this.arset = (arset == null) ? new ARSet() : arset; this.setModel(this.model = new ARModel(this.arset)); size = this.getPreferredSize(); if (size.width > 800) size.width = 800; if (size.height > 600) size.height = 600; this.setPreferredScrollableViewportSize(size); } /* setARSet() */ /*------------------------------------------------------------------*/ public void sort (int field) { /* --- sort the association rules */ this.arset.sort(field); /* sort the rules and redraw table */ this.tableChanged(new TableModelEvent(this.model)); } /* sort() */ /*------------------------------------------------------------------*/ public static void main (String args[]) { /* --- main function for testing */ int i; /* loop variable */ ARSet arset; /* created association rule set */ ARTable table; /* table for the rule set */ JFrame frame; /* surrounding frame */ try { /* create an association rule set */ if (args.length <= 0) /* if no arguments given */ arset = new ARSet("a <- b c (1%/3, 20%, 80%, 150%)"); else /* if a file argument is given */ arset = new ARSet(new FileInputStream(args[0])); } catch (IOException ioe) { System.err.println(ioe.getMessage()); return; } table = new ARTable(arset); frame = new JFrame(); /* create the frame for display */ frame.getContentPane().add(new JScrollPane(table)); frame.setLocation(50, 50); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } /* main() */} /* ARTable */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -