Search in sources :

Example 31 with ListSelectionModel

use of javax.swing.ListSelectionModel in project knime-core by knime.

the class TableContentModelTest method testResetHilite.

// testUnHilite()
/**
 * Method being tested: resetHiLite().
 */
public final void testResetHilite() {
    final HiLiteHandler hiliter = new HiLiteHandler();
    final TableContentModel m = new TableContentModel(DATA, hiliter);
    final JTable table = new JTable(m);
    final ListSelectionModel listModel = table.getSelectionModel();
    // make sure, the content model knows about ALL ROWS
    m.getRow(OBJECT_DATA.length - 1);
    assertEquals(table.getRowCount(), OBJECT_DATA.length);
    // first: hilite all;
    listModel.setSelectionInterval(0, OBJECT_DATA.length - 1);
    m.requestHiLite(listModel);
    flushEDTQueue();
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertTrue(m.isHiLit(i));
    }
    // reset hilite
    m.requestResetHiLite();
    // hilite happens in EDT thread, this is executed in main - need to wait
    ViewUtils.invokeAndWaitInEDT(new Runnable() {

        @Override
        public void run() {
        // nothing, just run
        }
    });
    for (int i = 0; i < OBJECT_DATA.length; i++) {
        assertFalse(m.isHiLit(i));
    }
    int lucky = (int) (Math.random() * OBJECT_DATA.length);
    listModel.setSelectionInterval(lucky, lucky);
    m.requestHiLite(listModel);
    flushEDTQueue();
    m.setTableContentFilter(TableContentFilter.HiliteOnly);
    // 0 should be ok, it returns the lucky row
    m.getRow(0);
    m.unHiLiteAll(new KeyEvent(this));
    assertEquals(m.getRowCount(), 0);
}
Also used : KeyEvent(org.knime.core.node.property.hilite.KeyEvent) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)31 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)11 JTable (javax.swing.JTable)9 Dimension (java.awt.Dimension)7 JScrollPane (javax.swing.JScrollPane)7 BorderLayout (java.awt.BorderLayout)5 JButton (javax.swing.JButton)5 Point (java.awt.Point)4 Rectangle (java.awt.Rectangle)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 Color (java.awt.Color)3 Insets (java.awt.Insets)3 Component (java.awt.Component)2 FlowLayout (java.awt.FlowLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 ImageIcon (javax.swing.ImageIcon)2