Example usage for javax.swing DefaultListModel clear

List of usage examples for javax.swing DefaultListModel clear

Introduction

In this page you can find the example usage for javax.swing DefaultListModel clear.

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:dbseer.gui.actions.ExplainChartAction.java

private void updateExplanations() {
    JTextField confidenceThresholdTextField = panel.getControlPanel().getConfidenceThresholdTextField();
    if (!UserInputValidator.validateNumber(confidenceThresholdTextField.getText().trim(),
            "Confidence Threshold", true)) {
        return;//from www. ja v a2  s.c o  m
    }
    confidenceThreshold = Double.parseDouble(confidenceThresholdTextField.getText().trim());
    if (confidenceThreshold < 0 || confidenceThreshold > 100) {
        JOptionPane.showMessageDialog(null, "Confidence threshold must be between 1 and 100.", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel();
            explanationListModel.clear();

            int rank = 1;
            for (DBSeerCausalModel explanation : explanations) {
                if (explanation.getConfidence() > confidenceThreshold) {
                    String output = String.format("%d. %s\n", rank++, explanation.toString());
                    explanationListModel.addElement(output);
                }
            }
        }
    });
}

From source file:dbseer.gui.actions.ExplainChartAction.java

public void printPredicates() {
    final StatisticalPackageRunner runner = DBSeerGUI.runner;
    int predicateColumnCount = 5;

    DefaultListModel predicateListModel = panel.getControlPanel().getPredicateListModel();
    predicateListModel.clear();

    try {//w w w.j a v a  2s . c  o  m
        Object[] predicates = (Object[]) runner.getVariableCell("predicates");
        int predicateRowCount = predicates.length / predicateColumnCount;
        String[] predicateNames = new String[predicateRowCount];
        double[] lowerBounds = new double[predicateRowCount];
        double[] upperBounds = new double[predicateRowCount];
        double[] relativeRatio = new double[predicateRowCount];

        if (predicateRowCount == 0) {
            console.append("There is no valid predicate.\n");
            return;
        }

        for (int r = 0; r < predicateRowCount; ++r) {
            predicateNames[r] = (String) predicates[r];
            if (predicateNames[r].contains("numTrans_")) {
                Pattern p = Pattern.compile("\\d+");
                Matcher m = p.matcher(predicateNames[r]);
                if (m.find()) {
                    int txIndex = Integer.parseInt(m.group());

                    predicateNames[r] = String.format("# of '%s' transactions",
                            DBSeerGUI.currentDataset.getTransactionTypeNames().get(txIndex - 1));
                }
            }
            double[] range = (double[]) predicates[r + predicateRowCount * 1];
            double[] ratio = (double[]) predicates[r + predicateRowCount * 2];
            lowerBounds[r] = range[0];
            upperBounds[r] = range[1];
            relativeRatio[r] = ratio[0];
        }

        // print x greater than y first.
        for (int r = 0; r < predicateRowCount; ++r) {
            if (!Double.isInfinite(lowerBounds[r]) && Double.isInfinite(upperBounds[r])) {
                String output = null;
                if (isPredicateAbsolute)
                    output = String.format("%s > %.2f\n", predicateNames[r], lowerBounds[r]);
                else {
                    String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER";
                    if (relativeRatio[r] == 0) {
                        output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]);
                    } else {
                        output = String.format("%s is %.2f%% %s than normal", predicateNames[r],
                                Math.abs(relativeRatio[r]), higher_lower);
                    }
                }
                predicateListModel.addElement(output);
            }
        }

        // print x less than y.
        for (int r = 0; r < predicateRowCount; ++r) {
            if (Double.isInfinite(lowerBounds[r]) && !Double.isInfinite(upperBounds[r])) {
                String output = null;
                if (isPredicateAbsolute)
                    output = String.format("%s < %.2f\n", predicateNames[r], upperBounds[r]);
                else {
                    String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER";
                    if (relativeRatio[r] == 0) {
                        output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]);
                    } else {
                        output = String.format("%s is %.2f%% %s than normal", predicateNames[r],
                                Math.abs(relativeRatio[r]), higher_lower);
                    }
                }
                predicateListModel.addElement(output);
            }
        }

        // print a < x < b
        for (int r = 0; r < predicateRowCount; ++r) {
            if (!Double.isInfinite(lowerBounds[r]) && !Double.isInfinite(upperBounds[r])) {
                String output = null;
                if (isPredicateAbsolute)
                    output = String.format("%.2f < %s < %.2f\n", lowerBounds[r], predicateNames[r],
                            upperBounds[r]);
                else {
                    String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER";
                    if (relativeRatio[r] == 0) {
                        output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]);
                    } else {
                        output = String.format("%s is %.2f%% %s than normal", predicateNames[r],
                                Math.abs(relativeRatio[r]), higher_lower);
                    }
                }
                predicateListModel.addElement(output);
            }
        }
    } catch (Exception e) {
        DBSeerExceptionHandler.handleException(e);
    }
}

From source file:dbseer.gui.actions.ExplainChartAction.java

public void printExplanations() {
    final StatisticalPackageRunner runner = DBSeerGUI.runner;
    int explanationColumnCount = 6;
    int predicateColumnCount = 5;

    int explanationRowCount = 0;
    int predicateRowCount = 0;
    double maxConfidence = Double.MIN_VALUE;

    this.explanations.clear();
    DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel();
    explanationListModel.clear();

    JTextField confidenceThresholdTextField = panel.getControlPanel().getConfidenceThresholdTextField();
    if (!UserInputValidator.validateNumber(confidenceThresholdTextField.getText().trim(),
            "Confidence Threshold", true)) {
        return;// w  ww. j a va 2  s.co m
    }
    confidenceThreshold = Double.parseDouble(confidenceThresholdTextField.getText().trim());
    if (confidenceThreshold < 0 || confidenceThreshold > 100) {
        JOptionPane.showMessageDialog(null, "Confidence threshold must be between 1 and 100.", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    try {
        Object[] explanations = (Object[]) runner.getVariableCell("explanations");
        explanationRowCount = explanations.length / explanationColumnCount;
        for (int r = 0; r < explanationRowCount; ++r) {
            String causeName = (String) explanations[r];
            double[] confidence = (double[]) explanations[r + explanationRowCount * 1];
            Object[] predicates = (Object[]) explanations[r + explanationRowCount * 5];

            if (runner instanceof OctaveRunner) {
                for (int i = 0; i < predicates.length; ++i) {
                    if (predicates[i] instanceof OctaveString) {
                        OctaveString str = (OctaveString) predicates[i];
                        predicates[i] = str.getString();
                    } else if (predicates[i] instanceof OctaveDouble) {
                        OctaveDouble val = (OctaveDouble) predicates[i];
                        predicates[i] = val.getData();
                    }
                }
            }

            DBSeerCausalModel explanation = new DBSeerCausalModel(causeName, confidence[0]);
            explanation.getPredicates();

            predicateRowCount = predicates.length / predicateColumnCount;
            for (int p = 0; p < predicateRowCount; ++p) {
                String predicateName = (String) predicates[p];
                double[] bounds = (double[]) predicates[p + predicateRowCount * 1];
                DBSeerPredicate predicate = new DBSeerPredicate(predicateName, bounds[0], bounds[1]);
                explanation.getPredicates().add(predicate);
            }

            this.explanations.add(explanation);

            if (maxConfidence < confidence[0]) {
                maxConfidence = confidence[0];
            }
        }
    } catch (Exception e) {
        DBSeerExceptionHandler.handleException(e);
    }

    //      double[] mockupConf = {82.74, 21.49, 14.23, 7.86};

    int rank = 1;
    for (DBSeerCausalModel explanation : explanations) {
        if (explanation.getConfidence() > confidenceThreshold) {
            //            String output = String.format("%d. %s\n", rank++, explanation.toString());
            // temp
            //            if (rank <= 4)
            //            {
            //               String output = String.format("%d. %s (%.2f%%)\n", rank, explanation.getCause(), mockupConf[rank - 1]);
            //               explanationListModel.addElement(output);
            //               rank++;
            //            }
            //            else
            //            {
            //               String output = String.format("%d. %s\n", rank++, explanation.toString());
            //               explanationListModel.addElement(output);
            //            }
            String output = String.format("%d. %s\n", rank++, explanation.toString());
            explanationListModel.addElement(output);
        }
    }

    if (maxConfidence < confidenceThreshold) {
        String output = String.format(
                "There are no possible causes with the confidence higher than threshold (%.2f%%).\n",
                confidenceThreshold);
        console.append(output);
        console.append("Showing the current predicates.\n");
    }

    printPredicates();
}

From source file:dbseer.gui.actions.ExplainChartAction.java

@Override
public void actionPerformed(ActionEvent actionEvent) {
    if (type == DBSeerConstants.EXPLAIN_SELECT_NORMAL_REGION) {
        Set<XYItemEntity> selectedItems = panel.getSelectedItems();
        ArrayList<Double> region = panel.getNormalRegion();
        region.clear();// w  ww.  ja v a  2  s .  c  o  m

        for (XYItemEntity item : selectedItems) {
            region.add(item.getDataset().getX(item.getSeriesIndex(), item.getItem()).doubleValue());
        }
        ArrayList<Double> otherRegion = panel.getAnomalyRegion();
        otherRegion.removeAll(region);
        DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) panel.getChart().getXYPlot()
                .getRenderer();
        renderer.setSelectedNormal(selectedItems);
        panel.clearRectangle();
        panel.setRefreshBuffer(true);
        panel.repaint();
    } else if (type == DBSeerConstants.EXPLAIN_APPEND_NORMAL_REGION) {
        DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) panel.getChart().getXYPlot()
                .getRenderer();
        Set<XYItemEntity> previousItems = renderer.getSelectedNormal();
        Set<XYItemEntity> selectedItems = panel.getSelectedItems();
        ArrayList<Double> region = panel.getNormalRegion();

        for (XYItemEntity item : selectedItems) {
            region.add(item.getDataset().getX(item.getSeriesIndex(), item.getItem()).doubleValue());
        }
        ArrayList<Double> otherRegion = panel.getAnomalyRegion();
        otherRegion.removeAll(region);
        if (previousItems != null) {
            previousItems.addAll(selectedItems);
            renderer.setSelectedNormal(previousItems);
        } else {
            renderer.setSelectedNormal(selectedItems);
        }
        panel.clearRectangle();
        panel.setRefreshBuffer(true);
        panel.repaint();
    } else if (type == DBSeerConstants.EXPLAIN_SELECT_ANOMALY_REGION) {
        Set<XYItemEntity> selectedItems = panel.getSelectedItems();
        ArrayList<Double> region = panel.getAnomalyRegion();
        region.clear();

        for (XYItemEntity item : selectedItems) {
            region.add(item.getDataset().getX(item.getSeriesIndex(), item.getItem()).doubleValue());
        }
        ArrayList<Double> otherRegion = panel.getNormalRegion();
        otherRegion.removeAll(region);
        DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) panel.getChart().getXYPlot()
                .getRenderer();
        renderer.setSelectedAnomaly(selectedItems);
        panel.clearRectangle();
        panel.setRefreshBuffer(true);
        panel.repaint();
    } else if (type == DBSeerConstants.EXPLAIN_APPEND_ANOMALY_REGION) {
        DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) panel.getChart().getXYPlot()
                .getRenderer();
        Set<XYItemEntity> previousItems = renderer.getSelectedAnomaly();
        Set<XYItemEntity> selectedItems = panel.getSelectedItems();
        ArrayList<Double> region = panel.getAnomalyRegion();

        for (XYItemEntity item : selectedItems) {
            region.add(item.getDataset().getX(item.getSeriesIndex(), item.getItem()).doubleValue());
        }
        ArrayList<Double> otherRegion = panel.getNormalRegion();
        otherRegion.removeAll(region);
        if (previousItems != null) {
            previousItems.addAll(selectedItems);
            renderer.setSelectedAnomaly(previousItems);
        } else {
            renderer.setSelectedAnomaly(selectedItems);
        }
        panel.clearRectangle();
        panel.setRefreshBuffer(true);
        panel.repaint();
    } else if (type == DBSeerConstants.EXPLAIN_CLEAR_REGION) {
        ArrayList<Double> region = panel.getNormalRegion();
        region.clear();
        region = panel.getAnomalyRegion();
        region.clear();

        DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) panel.getChart().getXYPlot()
                .getRenderer();
        renderer.clearAnomaly();
        renderer.clearNormal();

        DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel();
        explanationListModel.clear();
        DefaultListModel predicateListModel = panel.getControlPanel().getPredicateListModel();
        predicateListModel.clear();

        panel.clearRectangle();
        panel.setRefreshBuffer(true);
        panel.repaint();

    } else if (type == DBSeerConstants.EXPLAIN_EXPLAIN) {
        explain();
    } else if (type == DBSeerConstants.EXPLAIN_TOGGLE_PREDICATES) {
        togglePredicates();
    } else if (type == DBSeerConstants.EXPLAIN_SAVE_PREDICATES) {
        savePredicates();
    } else if (type == DBSeerConstants.EXPLAIN_UPDATE_EXPLANATIONS) {
        updateExplanations();
    }
}

From source file:ANNFileDetect.EditNet.java

public void populateList() {
    String[] nnames = new String[] { "" };
    nnames = sqlite.GetNetworkNames();/*from w  w w .j  av a 2s.  co m*/
    DefaultListModel mdl = new DefaultListModel();
    for (int i = 0; i < nnames.length; i++) {
        mdl.add(i, nnames[i]);
    }
    NetList.setModel(mdl);
    NetList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting()) {
                return;
            } else {
                String[] images = {};
                try {
                    images = sqlite.GetImagesForNetwork(NetList.getSelectedValue().toString());
                } catch (Exception e) {
                    System.out.println("exception: " + e.toString());
                }
                DefaultListModel mdl2 = new DefaultListModel();
                if (images.length > 0) {
                    for (int i = 0; i < images.length; i++) {
                        mdl2.add(i, images[i]);
                    }
                } else {
                    mdl2.clear();
                    thresholdList.setModel(mdl2);
                }
                fileList.setModel(mdl2);
            }
        }
    });
    fileList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (evt.getValueIsAdjusting()) {
                return;
            } else {
                String[] thresh = sqlite.GetThresholds(NetList.getSelectedValue().toString(),
                        fileList.getSelectedValue().toString());
                DefaultListModel mdl3 = new DefaultListModel();
                if (thresh.length > 0) {
                    for (int i = 0; i < thresh.length; i++) {
                        String[] vals = thresh[i].split(",");
                        mdl3.add(i, "Range: " + vals[0] + "-" + vals[1] + " Score: " + vals[3] + " Weight: "
                                + vals[2]);
                    }
                } else {
                    mdl3.clear();
                }
                thresholdList.setModel(mdl3);
            }

        }
    });

}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListRemoveAllAction(final JList availableList, final JList selectedList) {
    final DefaultListModel availableListModel = (DefaultListModel) availableList.getModel();
    final DefaultListModel selectedListModel = (DefaultListModel) selectedList.getModel();
    int size = selectedList.getModel().getSize();
    for (int i = 0; i < size; i++) {
        availableListModel.addElement(selectedListModel.getElementAt(i));
    }//w w w .ja va 2  s. c  o m
    selectedListModel.clear();
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void pickListAddAllAction(final JList sourceList, final JList destinationList) {
    final DefaultListModel availableListModel = (DefaultListModel) sourceList.getModel();
    final DefaultListModel selectedListModel = (DefaultListModel) destinationList.getModel();
    int size = sourceList.getModel().getSize();
    for (int i = 0; i < size; i++) {
        selectedListModel.addElement(availableListModel.getElementAt(i));
    }//from  w  ww  .ja  va 2 s  .c  o  m
    availableListModel.clear();
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

protected void refreshInfoList() {
    DefaultListModel model = (DefaultListModel) projects.getModel();
    model.removeAllElements();//from   w w w . j a  v  a2 s. c om

    SPServerInfo serviceInfo = getSelectedServerInfo();
    if (serviceInfo != null) {
        try {
            List<ProjectLocation> projectLocations = getProjectLocations();

            // Sorts the project locations alphabetically
            Collections.sort(projectLocations, new Comparator<ProjectLocation>() {
                public int compare(ProjectLocation proj1, ProjectLocation proj2) {
                    return proj1.getName().compareToIgnoreCase(proj2.getName());
                }
            });

            model.clear();
            for (ProjectLocation pl : projectLocations) {
                model.addElement(pl);
            }

            connected = true;
        } catch (Exception ex) {
            model.removeAllElements();
            model.addElement("Unable to get projects from server");
            connected = false;
            upf.createUserPrompter("Server Unavailable", UserPromptType.MESSAGE, UserPromptOptions.OK,
                    UserPromptResponse.OK, "OK", "OK").promptUser("");
        }

        refreshPanel();
    } else {
        model.addElement("No Server Selected");
        connected = false;
        refreshPanel();
    }
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

/**
 * /*from  ww w . j  a v  a 2s  . c  o m*/
 */
protected void formSelected() {
    selectedForm = forms.get(formsTable.getSelectedRow());

    // Missing Fields List
    DefaultListModel model = (DefaultListModel) missingFieldsList.getModel();
    model.clear();
    for (FormFieldInfo fi : selectedForm.getFields()) {
        if (fi.getSp6FieldName() == null) {
            model.addElement(fi.getSp5FieldName());
        }
    }

    DefaultComboBoxModel cbxModel = (DefaultComboBoxModel) ((JComboBox) sp6FieldEditor.getComponent())
            .getModel();
    cbxModel.removeAllElements();
    cbxModel.addElement("");

    // Setup Sp6 Fields
    DBTableInfo tblInfo = selectedForm.getTblInfo();
    if (tblInfo != null) {
        for (DBFieldInfo fldInfo : tblInfo.getFields()) {
            if (StringUtils.isNotEmpty(fldInfo.getColumn())) {
                cbxModel.addElement(fldInfo.getColumn());
            }
        }
        for (DBRelationshipInfo relInfo : tblInfo.getRelationships()) {
            if (StringUtils.isNotEmpty(relInfo.getColName())) {
                cbxModel.addElement(relInfo.getColName());
            }
        }
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            fieldsTableModel.setSelectedForm(selectedForm);
            fieldsTableModel.fireTableDataChanged();
        }
    });

}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * //from   www.ja va2 s.  c o  m
 */
protected void viewSelected() {
    selectedView = null;
    selectedViewDef = null;
    selectedAltView = null;

    viewDefsList.clearSelection();

    DefaultListModel model = (DefaultListModel) altViewsList.getModel();
    model.clear();

    ((DefaultTreeModel) tree.getModel()).setRoot(null);

    if (viewsList.getSelectedIndex() > -1) {
        if (selectedViewSet != null) {
            String viewName = (String) viewsList.getSelectedValue();
            if (viewName != null) {
                selectedView = selectedViewSet.getViews().get(viewName);

                for (AltViewIFace altView : selectedView.getAltViews()) {
                    model.addElement(altView.getName());
                }
            }
            altViewControlPanel.getAddBtn().setEnabled(true);
            viewControlPanel.getDelBtn().setEnabled(true);
        }

    } else {
        altViewControlPanel.getAddBtn().setEnabled(false);
        viewControlPanel.getDelBtn().setEnabled(false);
    }
}