use of wekapar.ComboBoxItem in project wekapar by gems-uff.
the class PostprocessAssociationsPanel method loadRules.
/**
* Loads rules into a JTable
*/
public static void loadRules() {
/* Clears table model by setting a new empty one */
table.setModel(new RulesTableModel());
/* Disable components while running loading process */
setEnabledAll(rulesPanel, false);
/* Reset components values */
comboFilter.removeAllItems();
antecedentMap.removeAll();
consequentMap.removeAll();
spinDecimal.reset();
/* Reset counters */
lblTotalRulesValue.setText("0");
lblFilteredRulesValue.setText("0");
/* The association rules */
List<AssociationRule> rulesList = associationRules.getRules();
/* Create a new table model */
final RulesTableModel tableModel = new RulesTableModel();
/* Metric names */
String[] metrics = rulesList.get(0).getMetricNamesForRule();
/* Columns */
tableModel.addColumn("Antecedent (X)");
tableModel.addColumn("Consequent (Y)");
tableModel.addColumn("Support");
for (String m : metrics) {
tableModel.addColumn(m);
}
/* Adds rules to table */
String antecedent = "";
String consequent = "";
double support;
double metricValue;
for (AssociationRule r : rulesList) {
/* Antecedent */
antecedent = "";
for (Item p : r.getPremise()) {
antecedent += p + " ";
antecedentMap.addAttribute(p.toString());
}
/* Consequent */
consequent = "";
for (Item c : r.getConsequence()) {
consequent += c + " ";
consequentMap.addAttribute(c.toString());
}
/* Support */
support = ((double) r.getTotalSupport()) / r.getTotalTransactions();
/* List containing each column's content to be added to table */
List<Object> row = new ArrayList<Object>();
/* Adds antecedent, consequent and support */
row.add(antecedent.trim());
row.add(consequent.trim());
row.add(support);
/* Adds metric values */
for (String m : metrics) {
try {
metricValue = r.getNamedMetricValue(m);
row.add(metricValue);
} catch (Exception e) {
log.statusMessage("FAILED! See log.");
log.logMessage(e.getMessage());
}
}
/* Adds a row with values to table */
tableModel.addRow(row.toArray());
}
/* Set TableModel */
table.setModel(tableModel);
/* Get column model */
final RulesTableColumnModel columnModel = (RulesTableColumnModel) table.getColumnModel();
/* Set minimum widths for antecedent and consequent columns */
columnModel.getColumn(0).setMinWidth(220);
columnModel.getColumn(1).setMinWidth(120);
/* Set custom renderer for antecedent and consequent cells */
columnModel.getColumn(0).setCellRenderer(new RulesTableCellRenderer());
columnModel.getColumn(1).setCellRenderer(new RulesTableCellRenderer());
for (int i = 2; i < table.getColumnCount(); i++) {
/* Set custom renderer for metric's cells */
columnModel.getColumn(i).setCellRenderer(decimalCellRenderer);
/* Set minimum size values for metric's columns */
columnModel.getColumn(i).setPreferredWidth(105);
columnModel.getColumn(i).setMinWidth(70);
columnModel.getColumn(i).setMaxWidth(120);
}
/* Set table's RowSorter for sorting and filterig */
sorter = new TableRowSorter<TableModel>(tableModel);
table.setRowSorter(sorter);
table.getRowSorter().addRowSorterListener(new RowSorterListener() {
// TODO: Improve sorting performance.
@Override
public void sorterChanged(RowSorterEvent e) {
if (e.getType() == Type.SORTED) {
Enumeration<TableColumn> columns = columnModel.getColumns();
TableColumn column;
while (columns.hasMoreElements()) {
column = columns.nextElement();
if (column.getCellRenderer() instanceof ProgressCellRenderer) {
column.setCellRenderer(decimalCellRenderer);
}
}
List<?> sortKeys = e.getSource().getSortKeys();
if (sortKeys.size() > 0) {
RowSorter.SortKey key = (SortKey) sortKeys.get(0);
int keyColumn = key.getColumn();
String columnName = tableModel.getColumnName(keyColumn);
if (columnModel.hasColumn(columnName)) {
int columnIndex = columnModel.getColumnIndex(columnName);
if (tableModel.getColumnClass(columnIndex) == Double.class) {
columnModel.getColumn(columnIndex).setCellRenderer(new ProgressCellRenderer(table, columnIndex));
}
}
}
}
}
});
/* Get total values for results */
lblTotalRulesValue.setText(String.valueOf(rulesList.size()));
lblFilteredRulesValue.setText(String.valueOf(table.getRowCount()));
/* Initializes attribute's component */
comboRuleSide.removeAllItems();
comboRuleSide.addItem(new ComboBoxItem(0, "Antecedent (X)", "X"));
comboRuleSide.addItem(new ComboBoxItem(1, "Consequent (Y)", "Y"));
/* Initializes filter parameters for metrics */
initMetrics();
setEnabledAll(rulesPanel, true);
comboLogicalOperator.setEnabled(false);
btnApply.setEnabled(false);
btnClear.setEnabled(false);
btnApplyMetric.setEnabled(false);
btnResetMetric.setEnabled(false);
}
Aggregations