Search in sources :

Example 1 with SortOrder

use of javax.swing.SortOrder in project zaproxy by zaproxy.

the class SpiderMessagesTable method setModel.

@Override
public void setModel(TableModel dataModel) {
    // Keep the same column sorted when model is changed
    int sortedcolumnIndex = getSortedColumnIndex();
    SortOrder sortOrder = getSortOrder(sortedcolumnIndex);
    super.setModel(dataModel);
    if (sortedcolumnIndex != -1) {
        setSortOrder(sortedcolumnIndex, sortOrder);
    }
}
Also used : SortOrder(javax.swing.SortOrder)

Example 2 with SortOrder

use of javax.swing.SortOrder in project jmeter by apache.

the class ObjectTableSorter method toggleSortOrder.

@Override
public void toggleSortOrder(int column) {
    SortKey newSortKey;
    if (isSortable(column)) {
        SortOrder newOrder = sortkey == null || sortkey.getColumn() != column || sortkey.getSortOrder() != SortOrder.ASCENDING ? SortOrder.ASCENDING : SortOrder.DESCENDING;
        newSortKey = new SortKey(column, newOrder);
    } else {
        newSortKey = null;
    }
    setSortKey(newSortKey);
}
Also used : SortOrder(javax.swing.SortOrder)

Example 3 with SortOrder

use of javax.swing.SortOrder in project jdk8u_jdk by JetBrains.

the class DefaultRowSorter method compare.

@SuppressWarnings("unchecked")
private int compare(int model1, int model2) {
    int column;
    SortOrder sortOrder;
    Object v1, v2;
    int result;
    for (int counter = 0; counter < cachedSortKeys.length; counter++) {
        column = cachedSortKeys[counter].getColumn();
        sortOrder = cachedSortKeys[counter].getSortOrder();
        if (sortOrder == SortOrder.UNSORTED) {
            result = model1 - model2;
        } else {
            // v1 != null && v2 != null
            if (useToString[column]) {
                v1 = getModelWrapper().getStringValueAt(model1, column);
                v2 = getModelWrapper().getStringValueAt(model2, column);
            } else {
                v1 = getModelWrapper().getValueAt(model1, column);
                v2 = getModelWrapper().getValueAt(model2, column);
            }
            // Treat nulls as < then non-null
            if (v1 == null) {
                if (v2 == null) {
                    result = 0;
                } else {
                    result = -1;
                }
            } else if (v2 == null) {
                result = 1;
            } else {
                result = sortComparators[counter].compare(v1, v2);
            }
            if (sortOrder == SortOrder.DESCENDING) {
                result *= -1;
            }
        }
        if (result != 0) {
            return result;
        }
    }
    // If we get here, they're equal. Fallback to model order.
    return model1 - model2;
}
Also used : SortOrder(javax.swing.SortOrder)

Example 4 with SortOrder

use of javax.swing.SortOrder in project JMRI by JMRI.

the class DefaultUserMessagePreferencesXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // ensure the master object exists
    jmri.UserPreferencesManager p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    p.setLoading();
    List<Element> settingList = shared.getChildren("setting");
    for (int i = 0; i < settingList.size(); i++) {
        String name = settingList.get(i).getText();
        p.setSimplePreferenceState(name, true);
    }
    List<Element> comboList = shared.getChildren("comboBoxLastValue");
    for (int i = 0; i < comboList.size(); i++) {
        List<Element> comboItem = comboList.get(i).getChildren("comboBox");
        for (int x = 0; x < comboItem.size(); x++) {
            String combo = comboItem.get(x).getAttribute("name").getValue();
            String setting = comboItem.get(x).getAttribute("lastSelected").getValue();
            p.addComboBoxLastSelection(combo, setting);
        }
    }
    List<Element> classList = shared.getChildren("classPreferences");
    for (int k = 0; k < classList.size(); k++) {
        List<Element> multipleList = classList.get(k).getChildren("multipleChoice");
        String strClass = classList.get(k).getAttribute("class").getValue();
        for (int i = 0; i < multipleList.size(); i++) {
            List<Element> multiItem = multipleList.get(i).getChildren("option");
            for (int x = 0; x < multiItem.size(); x++) {
                String item = multiItem.get(x).getAttribute("item").getValue();
                int value = 0x00;
                try {
                    value = multiItem.get(x).getAttribute("value").getIntValue();
                } catch (org.jdom2.DataConversionException e) {
                    log.error("failed to convert positional attribute");
                }
                p.setMultipleChoiceOption(strClass, item, value);
            }
        }
        List<Element> preferenceList = classList.get(k).getChildren("reminderPrompts");
        for (int i = 0; i < preferenceList.size(); i++) {
            List<Element> reminderBoxes = preferenceList.get(i).getChildren("reminder");
            for (int j = 0; j < reminderBoxes.size(); j++) {
                String name = reminderBoxes.get(j).getText();
                p.setPreferenceState(strClass, name, true);
            }
        }
    }
    List<Element> windowList = shared.getChildren("windowDetails");
    for (int k = 0; k < windowList.size(); k++) {
        String strClass = windowList.get(k).getAttribute("class").getValue();
        List<Element> locListX = windowList.get(k).getChildren("locX");
        double x = 0.0;
        for (int i = 0; i < locListX.size(); i++) {
            try {
                x = Double.parseDouble(locListX.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        List<Element> locListY = windowList.get(k).getChildren("locY");
        double y = 0.0;
        for (int i = 0; i < locListY.size(); i++) {
            try {
                y = Double.parseDouble(locListY.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        p.setWindowLocation(strClass, new java.awt.Point((int) x, (int) y));
        List<Element> sizeWidth = windowList.get(k).getChildren("width");
        double width = 0.0;
        for (int i = 0; i < sizeWidth.size(); i++) {
            try {
                width = Double.parseDouble(sizeWidth.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        List<Element> heightList = windowList.get(k).getChildren("height");
        double height = 0.0;
        for (int i = 0; i < heightList.size(); i++) {
            try {
                height = Double.parseDouble(heightList.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        p.setWindowSize(strClass, new java.awt.Dimension((int) width, (int) height));
        Element prop = windowList.get(k).getChild("properties");
        if (prop != null) {
            for (Object next : prop.getChildren("property")) {
                Element e = (Element) next;
                try {
                    Class<?> cl;
                    Constructor<?> ctor;
                    // create key object
                    String key = e.getChild("key").getText();
                    // create value object
                    Object value = null;
                    if (e.getChild("value") != null) {
                        cl = Class.forName(e.getChild("value").getAttributeValue("class"));
                        ctor = cl.getConstructor(new Class<?>[] { String.class });
                        value = ctor.newInstance(new Object[] { e.getChild("value").getText() });
                    }
                    // store
                    p.setProperty(strClass, key, value);
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                    log.error("Error loading properties", ex);
                }
            }
        }
    }
    List<Element> tablesList = shared.getChildren("tableDetails");
    for (Element tables : tablesList) {
        List<Element> tableList = tables.getChildren("table");
        for (Element table : tableList) {
            List<Element> columnList = table.getChildren("column");
            String strTableName = table.getAttribute("name").getValue();
            for (Element column : columnList) {
                String strColumnName = column.getAttribute("name").getValue();
                int order = -1;
                int width = -1;
                SortOrder sort = SortOrder.UNSORTED;
                boolean hidden = false;
                if (column.getChild("order") != null) {
                    order = Integer.parseInt(column.getChild("order").getText());
                }
                if (column.getChild("width") != null) {
                    width = Integer.parseInt(column.getChild("width").getText());
                }
                if (column.getChild("sortOrder") != null) {
                    sort = SortOrder.valueOf(column.getChild("sortOrder").getText());
                // before 4.3.5 we used "sort" save column sort state
                } else if (column.getChild("sort") != null) {
                    switch(Integer.parseInt(column.getChild("sort").getText())) {
                        case TableSorter.ASCENDING:
                            sort = SortOrder.ASCENDING;
                            break;
                        case TableSorter.DESCENDING:
                            sort = SortOrder.DESCENDING;
                            break;
                        default:
                            break;
                    }
                }
                if (column.getChild("hidden") != null && column.getChild("hidden").getText().equals("yes")) {
                    hidden = true;
                }
                p.setTableColumnPreferences(strTableName, strColumnName, order, width, sort, hidden);
            }
        }
    }
    p.finishLoading();
    return true;
}
Also used : Element(org.jdom2.Element) SortOrder(javax.swing.SortOrder) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with SortOrder

use of javax.swing.SortOrder in project JMRI by JMRI.

the class TrainsTableFrame method getSortBy.

protected String getSortBy() {
    // set the defaults
    String sortBy = TrainsTableModel.TIMECOLUMNNAME;
    _status = SortOrder.ASCENDING;
    // now look to see if a sort is active
    for (RowSorter.SortKey key : trainsTable.getRowSorter().getSortKeys()) {
        String name = trainsModel.getColumnName(key.getColumn());
        SortOrder status = key.getSortOrder();
        // log.debug("Column {} status {}", name, status);
        if (!status.equals(SortOrder.UNSORTED) && !name.isEmpty()) {
            sortBy = name;
            _status = status;
            break;
        }
    }
    return sortBy;
}
Also used : RowSorter(javax.swing.RowSorter) SortOrder(javax.swing.SortOrder)

Aggregations

SortOrder (javax.swing.SortOrder)8 RowSorter (javax.swing.RowSorter)2 Element (org.jdom2.Element)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 SortKey (javax.swing.RowSorter.SortKey)1 TableColumn (javax.swing.table.TableColumn)1 TableColumnModel (javax.swing.table.TableColumnModel)1 XTableColumnModel (jmri.util.swing.XTableColumnModel)1 DataConversionException (org.jdom2.DataConversionException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1