Example usage for javax.swing SortOrder ASCENDING

List of usage examples for javax.swing SortOrder ASCENDING

Introduction

In this page you can find the example usage for javax.swing SortOrder ASCENDING.

Prototype

SortOrder ASCENDING

To view the source code for javax.swing SortOrder ASCENDING.

Click Source Link

Document

Enumeration value indicating the items are sorted in increasing order.

Usage

From source file:org.zaproxy.zap.extension.customFire.PolicyAllCategoryPanel.java

/**
 * This method initializes tableTest/*from   ww w. j  a  va  2 s  .c  om*/
 *
 * @return javax.swing.JTable
 */
private JTable getTableTest() {
    if (tableTest == null) {
        tableTest = new JTable();
        tableTest.setModel(getAllCategoryTableModel());
        tableTest.setRowHeight(DisplayUtils.getScaledSize(18));
        tableTest.setIntercellSpacing(new java.awt.Dimension(1, 1));
        tableTest.setAutoCreateRowSorter(true);

        //Default sort by name (column 0)
        List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>(1);
        sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
        tableTest.getRowSorter().setSortKeys(sortKeys);

        for (int i = 0; i < tableTest.getColumnCount() - 1; i++) {
            TableColumn column = tableTest.getColumnModel().getColumn(i);
            column.setPreferredWidth(width[i]);
        }

        JComboBox<String> jcb1 = new JComboBox<>();
        jcb1.addItem(""); // Always show a blank one for where they are not all the same
        for (AlertThreshold level : AlertThreshold.values()) {
            jcb1.addItem(Constant.messages
                    .getString("customFire.custom.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(jcb1));

        JComboBox<String> jcb2 = new JComboBox<>();
        jcb2.addItem(""); // Always show a blank one for where they are not all the same
        for (AttackStrength level : AttackStrength.values()) {
            jcb2.addItem(Constant.messages
                    .getString("customFire.custom.policy.level." + level.name().toLowerCase()));
        }

        tableTest.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(jcb2));
    }

    return tableTest;
}

From source file:pl.otros.vfs.browser.table.FileNameWithTypeComparator.java

public int compareTo(FileNameWithType o1, FileNameWithType o2) {
    if (o1 == null || o1.getFileType() == null || o1.getFileName() == null) {
        return -1;
    }/*from   www  .j  a  va  2 s  .c o  m*/
    if (o2 == null || o2.getFileType() == null || o2.getFileName() == null) {
        return 1;
    }
    //folders first first
    boolean folder1 = FileType.FOLDER.equals(o1.getFileType());
    boolean folder2 = FileType.FOLDER.equals(o2.getFileType());
    int result = 0;

    int sortOrderSign = SortOrder.ASCENDING.equals(sortOrder) ? 1 : -1;
    if (o1.getFileName().getBaseName().equalsIgnoreCase(ParentFileObject.PARENT_NAME)) {
        result = -1 * sortOrderSign;
    } else if (o2.getFileName().getBaseName().equalsIgnoreCase(ParentFileObject.PARENT_NAME)) {
        result = 1 * sortOrderSign;
    } else if (folder1 & !folder2) {
        result = -1 * sortOrderSign;
    } else if (!folder1 & folder2) {
        result = 1 * sortOrderSign;
    } else {
        result = o1.getFileName().compareTo(o2.getFileName());
    }

    return result;
}