Example usage for javax.swing SortOrder DESCENDING

List of usage examples for javax.swing SortOrder DESCENDING

Introduction

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

Prototype

SortOrder DESCENDING

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

Click Source Link

Document

Enumeration value indicating the items are sorted in decreasing order.

Usage

From source file:org.jdal.swing.table.ListTableModelSorter.java

/**
 * {@inheritDoc}//  w w  w. j  av a  2  s .com
 */
@Override
public void toggleSortOrder(int column) {
    if (key.getColumn() != column) {
        key = new SortKey(column, javax.swing.SortOrder.ASCENDING);
    } else {
        key = new SortKey(column,
                key.getSortOrder() == SortOrder.ASCENDING ? SortOrder.DESCENDING : SortOrder.ASCENDING);
    }
    sort();
}

From source file:de.tor.tribes.util.PropertyHelper.java

public static void restoreTableProperties(JXTable pTable, Configuration pConfig, String pPrefix) {
    //set col width
    List<TableColumn> cols = ((TableColumnModelExt) pTable.getColumnModel()).getColumns(true);

    for (TableColumn c : cols) {
        TableColumnExt col = (TableColumnExt) c;
        String title = col.getTitle();
        try {/*from  w  w  w  .  j  a  va2 s  .c om*/
            col.setPreferredWidth(
                    pConfig.getInteger(pPrefix + ".table.col." + title + ".width", col.getWidth()));
        } catch (ConversionException ignored) {
        }
        try {
            col.setVisible(pConfig.getBoolean(pPrefix + ".table.col." + title + ".visible", true));
        } catch (ConversionException ce) {
            col.setVisible(true);
        }
    }

    SortOrder sortOrder = SortOrder.UNSORTED;
    int iSortOrder = 0;
    try {
        iSortOrder = pConfig.getInteger(pPrefix + ".table.sort.order", 0);
    } catch (ConversionException ignored) {
    }

    switch (iSortOrder) {
    case 1:
        sortOrder = SortOrder.ASCENDING;
        break;
    case -1:
        sortOrder = SortOrder.DESCENDING;
        break;
    default:
        sortOrder = SortOrder.UNSORTED;
    }

    Boolean scroll = false;
    try {
        scroll = pConfig.getBoolean(pPrefix + ".table.horizontal.scroll", false);
    } catch (ConversionException ignored) {
    }

    pTable.setHorizontalScrollEnabled(scroll);

    Integer orderCol = 0;
    try {
        orderCol = pConfig.getInteger(pPrefix + ".table.sort.col", 0);
    } catch (ConversionException ignored) {
    }

    try {
        pTable.setSortOrder(orderCol.intValue(), sortOrder);
    } catch (IndexOutOfBoundsException ignored) {
    }
}

From source file:com.hp.alm.ali.idea.services.EntityServiceTest.java

@Test
@TestTarget(ServerVersion.AGM)/*from w  w w.  ja  v a  2 s  .c  o  m*/
public void testQuery() {
    RestInvocations.loadMetadata(handler, "defect");
    RestInvocations.loadMetadata(handler, "release-backlog-item");

    handler.addRequest(false, "GET",
            "/qcbin/rest/domains/domain/projects/project/defects?fields=priority,release-backlog-item.id,release-backlog-item.blocked,product-group-id&query={status[\"Fixed\"]; product-group-id[1000]}&order-by={priority[DESC]}",
            200).content("entityServiceTest_entity.xml");

    EntityQuery query = new EntityQuery("defect");
    query.setValue("status", "Fixed");
    query.addColumn("priority", 1);
    query.addOrder("priority", SortOrder.DESCENDING);
    EntityList list = entityService.query(query);
    Assert.assertEquals(1, list.size());
    Assert.assertEquals(86, list.get(0).getId());
}

From source file:ca.phon.app.session.RecordFilterPanel.java

private void init() {
    FormLayout layout = new FormLayout("0px, fill:pref:grow",
            "pref, 1dlu, pref, pref, 1dlu, pref, pref, 1dlu, pref, pref");
    CellConstraints cc = new CellConstraints();
    setLayout(layout);//from ww w .  j  a va2  s. c  o  m

    radioGrp = new ButtonGroup();

    ButtonAction bAct = new ButtonAction();

    allBtn = new JRadioButton("All records");
    allBtn.setSelected(true);
    allBtn.addActionListener(bAct);
    radioGrp.add(allBtn);

    rangeBtn = new JRadioButton("Specific records");
    rangeBtn.addActionListener(bAct);
    radioGrp.add(rangeBtn);

    speakerBtn = new JRadioButton("Records for participant(s)");
    speakerBtn.addActionListener(bAct);
    radioGrp.add(speakerBtn);

    searchBtn = new JRadioButton("Records from search results");
    searchBtn.addActionListener(bAct);
    radioGrp.add(searchBtn);

    rangeField = new JTextField();
    rangeField.setText("1.." + t.getRecordCount());
    rangeField.setInputVerifier(new RangeVerifier());
    rangeField.setEnabled(false);

    speakerTbl = new JXTable(new ParticipantsTableModel());
    speakerTbl.setVisibleRowCount(2);
    speakerTbl.setEnabled(false);

    searchTbl = new JXTable(new SearchTableModel());
    searchTbl.setVisibleRowCount(4);
    searchTbl.setEnabled(false);
    searchTbl.getColumn(0).setCellRenderer(new QueryNameCellRenderer());
    searchTbl.getColumn(1).setCellRenderer(new DateCellRenderer());
    searchTbl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    searchTbl.getSelectionModel().addListSelectionListener(new SearchListener());
    if (searchTbl.getModel().getRowCount() > 0) {
        searchTbl.getSelectionModel().setSelectionInterval(0, 0);
    }
    searchTbl.setSortOrder(1, SortOrder.DESCENDING);

    // add components
    add(allBtn, cc.xyw(1, 1, 2));
    add(rangeBtn, cc.xyw(1, 3, 2));
    add(rangeField, cc.xy(2, 4));
    add(speakerBtn, cc.xyw(1, 6, 2));
    add(new JScrollPane(speakerTbl), cc.xy(2, 7));
    add(searchBtn, cc.xyw(1, 9, 2));
    add(new JScrollPane(searchTbl), cc.xy(2, 10));
}

From source file:org.jdal.swing.PageableTable.java

/**
 * Convert the Order from SortKey to Page.Order
 * @param key the SortKey/*ww w. ja va2 s .co  m*/
 * @return  the Page order
 */
private Page.Order converSortOrder(RowSorter.SortKey key) {
    Page.Order order = Order.ASC;
    if (key.getSortOrder() == SortOrder.DESCENDING) {
        order = Order.DESC;
    }
    return order;
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * /*from   w w  w .  j a  va2s  .  c o m*/
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

@Override
public void sortBy(Object propertyId, boolean ascending) {
    if (isSortable()) {
        for (int i = 0; i < columnsOrder.size(); i++) {
            Column column = columnsOrder.get(i);
            if (column.getId().equals(propertyId)) {
                SortOrder sortOrder = ascending ? SortOrder.ASCENDING : SortOrder.DESCENDING;
                tableModel.sort(singletonList(new RowSorter.SortKey(i, sortOrder)));
                onDataChange();/*  w w  w  . j av a 2  s  .  c om*/
                packRows();
                break;
            }
        }
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

@Override
public void sort(String columnId, SortDirection direction) {
    Column column = getColumn(columnId);
    if (column == null) {
        throw new IllegalArgumentException("Unable to find column " + columnId);
    }//from w  w  w  .  j  av a  2s .com

    if (isSortable()) {
        SortOrder sortOrder = direction == SortDirection.ASCENDING ? SortOrder.ASCENDING : SortOrder.DESCENDING;
        int columnIndex = columnsOrder.indexOf(column);
        tableModel.sort(singletonList(new RowSorter.SortKey(columnIndex, sortOrder)));
        onDataChange();
        packRows();
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * /*from w w  w .  ja va2s .  com*/
 */
public void sgrSort() {
    int sgrColIndex = model.getSgrHeading().getViewOrder();
    spreadSheet.setSortOrder(sgrColIndex, SortOrder.DESCENDING);
}

From source file:org.nuclos.client.ui.collect.model.SortableCollectableTableModelImpl.java

@Override
public void toggleSortOrder(final int column, boolean sortImmediately) {
    if (!isSortable(column)) {
        return;//ww w  . j a  v  a  2s . c o m
    }

    List<SortKey> newSortKeys = new LinkedList<SortKey>(sortKeys);
    int currentSortIndex = CollectionUtils.indexOfFirst(sortKeys, new Predicate<SortKey>() {
        @Override
        public boolean evaluate(SortKey t) {
            return t.getColumn() == column;
        }
    });

    SortOrder newSortOrder = SortOrder.ASCENDING;
    int lastSortIndex = newSortKeys.size();
    if (currentSortIndex != -1) {
        SortKey oldSortKey = newSortKeys.remove(currentSortIndex);
        if (oldSortKey.getSortOrder() != SortOrder.UNSORTED) {
            switch (oldSortKey.getSortOrder()) {
            case ASCENDING:
                newSortOrder = SortOrder.DESCENDING;
                newSortKeys.add(currentSortIndex, new SortKey(column, newSortOrder));
                break;
            case DESCENDING:
                newSortOrder = SortOrder.UNSORTED;
                // if descending, nothing will be added. 3-click behavior. asc,desc,unsorted.
                newSortKeys.add(currentSortIndex, new SortKey(column, newSortOrder));
                break;
            case UNSORTED:
                newSortOrder = SortOrder.ASCENDING;
                newSortKeys.add(currentSortIndex, new SortKey(column, newSortOrder));
                break;
            }
        } else {
            newSortOrder = SortOrder.ASCENDING;
            newSortKeys.add(
                    lastSortIndex == 0 ? 0
                            : (lastSortIndex > newSortKeys.size() ? lastSortIndex - 1 : lastSortIndex),
                    new SortKey(column, newSortOrder));
        }
    } else {
        newSortOrder = SortOrder.ASCENDING;
        newSortKeys.add(
                lastSortIndex == 0 ? 0
                        : (lastSortIndex > newSortKeys.size() ? lastSortIndex - 1 : lastSortIndex),
                new SortKey(column, newSortOrder));
    }

    List<SortKey> newSortKeys1 = new LinkedList<SortKey>();
    List<SortKey> newSortKeys2 = new LinkedList<SortKey>();
    for (SortKey sortKey : newSortKeys) {
        if (sortKey.getSortOrder() == SortOrder.UNSORTED) {
            newSortKeys1.add(sortKey);
        } else {
            newSortKeys2.add(sortKey);
        }
    }

    newSortKeys.clear();
    newSortKeys.addAll(
            newSortKeys2.subList(newSortKeys2.size() < 3 ? 0 : newSortKeys2.size() - 3, newSortKeys2.size()));
    newSortKeys.addAll(newSortKeys1);

    if (LOG.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("Sort subform by:");
        for (SortKey sk : newSortKeys) {
            sb.append("\n\t" + getCollectableEntityField(sk.getColumn()).getName() + " " + sk.getSortOrder());
        }
        LOG.debug(sb.toString());
    }
    setSortKeys(newSortKeys, sortImmediately);
}