Example usage for javax.swing.table TableRowSorter TableRowSorter

List of usage examples for javax.swing.table TableRowSorter TableRowSorter

Introduction

In this page you can find the example usage for javax.swing.table TableRowSorter TableRowSorter.

Prototype

public TableRowSorter() 

Source Link

Document

Creates a TableRowSorter with an empty model.

Usage

From source file:put.semantic.fcanew.ui.MainWindow.java

private void continueStart() {
    final List<Attribute> forced = getAttributes(2);
    if (forced.isEmpty()) {
        forced.addAll(getAttributes(1));
    }/*w  w  w . j a v a  2  s.  c om*/
    logger.trace("START");
    for (Attribute a : getUsedAttributes()) {
        logger.trace("ATTR: {}", a);
    }
    context = new PartialContext(new SimpleSetOfAttributes(getUsedAttributes()), kb);
    context.addProgressListener(progressListener);
    context.updateContext();
    contextTable.setRowSorter(new TableRowSorter<>());
    contextTable.setModel(new ContextDataModel(context));
    contextTable.setDefaultRenderer(Object.class, new PODCellRenderer(kb.getReasoner()));
    Enumeration<TableColumn> e = contextTable.getColumnModel().getColumns();
    JComboBox comboBox = new JComboBox(new Object[] { "+", "-", " " });
    while (e.hasMoreElements()) {
        TableColumn col = e.nextElement();
        col.setHeaderRenderer(new VerticalTableHeaderCellRenderer());
        col.setCellEditor(new DefaultCellEditor(comboBox));
        if (col.getModelIndex() >= 1) {
            col.setPreferredWidth(20);
        }
    }
    List<? extends FeatureCalculator> calculators = availableCalculatorsModel.getChecked();
    for (FeatureCalculator calc : calculators) {
        if (calc instanceof EndpointCalculator) {
            ((EndpointCalculator) calc).setMappings(mappingsPanel1.getMappings());
        }
    }
    Classifier classifier = (Classifier) classifierToUse.getSelectedItem();
    classifier.setRejectedWeight((Double) rejectedWeight.getValue());
    mlExpert = new MLExpert(classifier, (Integer) credibilityTreshold.getValue(), calculators,
            getIgnoreTreshold(), context, getAutoAcceptTreshold());
    mlExpert.addEventListener(new MLExpertEventListener() {

        @Override
        public void implicationAccepted(ImplicationDescription i, boolean autoDecision) {
            logger.trace("ACCEPT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.ACCEPT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.ACCEPT);
        }

        @Override
        public void implicationRejected(ImplicationDescription i, boolean autoDecision) {
            logger.trace("REJECT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.REJECT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.REJECT);
        }

        private TableModel getFeaturesTableModel(Map<String, Double> features) {
            DefaultTableModel model = new DefaultTableModel(new String[] { "feature", "value" }, 0);
            for (Map.Entry<String, Double> f : features.entrySet()) {
                model.addRow(new Object[] { f.getKey(), f.getValue() });
            }
            return model;
        }

        @Override
        public void ask(ImplicationDescription i, String justification) {
            logger.trace("ASK: {}", i.getImplication());
            highlightButton(i.getSuggestion());
            ((ContextDataModel) contextTable.getModel()).setCurrentImplication(i.getImplication());
            justificationText.setText(justification);
            implicationText.setText(String.format("<html>%s</html>", i.getImplication().toString()));
            {
                Map<String, String> desc = i.getImplication().describe(kb);
                String s = "<html><table border=\"1\">";
                s += "<tr><th>Attribute</th><th>Label</th></tr>";
                for (Map.Entry<String, String> e : desc.entrySet()) {
                    s += String.format("<tr><td>%s</td><td><pre>%s</pre></td></tr>", e.getKey(), e.getValue());
                }
                s += "</table></html>";
                implicationText.setToolTipText(s);
            }
            setButtonsEnabled(true);
            featuresTable.setModel(getFeaturesTableModel(i.getFeatures()));
        }
    });
    learningExamplesTable.setModel(classifier.getExamplesTableModel());
    fca = new FCA();
    fca.setContext(context);
    fca.setExpert(mlExpert);
    new SwingWorker() {
        @Override
        protected Object doInBackground() throws Exception {
            fca.reset(forced);
            fca.run();
            return null;
        }

        @Override
        protected void done() {
            try {
                get();
                logger.trace("FINISHED");
                if (script != null) {
                    String name = JOptionPane.showInputDialog(MainWindow.this,
                            "Jeeli chcesz otrzyma punkty z TSiSS, podaj swoje imi, nazwisko i nr indeksu",
                            "TSiSS", JOptionPane.QUESTION_MESSAGE);
                    if (name != null) {
                        logger.trace("NAME: {}", name);
                    }
                    script.submitLog(new File("fca.log"));
                }
                implicationText.setText("Bye-bye");
            } catch (InterruptedException | ExecutionException ex) {
                implicationText.setText(ex.getLocalizedMessage());
                ex.printStackTrace();
            }
        }
    }.execute();
}