Example usage for javax.swing.event ListSelectionListener ListSelectionListener

List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener

Introduction

In this page you can find the example usage for javax.swing.event ListSelectionListener ListSelectionListener.

Prototype

ListSelectionListener

Source Link

Usage

From source file:logdruid.ui.mainpanel.StatRecordingSelectorPanel.java

/**
 * Create the panel./*  w w w  . j av  a2 s  .  co  m*/
 */
public StatRecordingSelectorPanel(final Repository rep, Source src) {
    repository = rep;
    source = src;
    records = rep.getRecordings(StatRecording.class);
    // Collections.sort(records);
    Iterator it = records.iterator();
    while (it.hasNext()) {
        Recording record = (Recording) it.next();
        data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(),
                src.isActiveRecordingOnSource(record) });
    }

    model = new logdruid.ui.mainpanel.StatRecordingSelectorPanel.MyTableModel(data, header);

    StatRecordingSelectorPanel thiis = this;
    logger.info("source is " + ((source == null) ? "null" : src.getSourceName()));
    setLayout(new BorderLayout(0, 0));

    JPanel panel_1 = new JPanel();
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);

    table.setPreferredScrollableViewportSize(new Dimension(0, 150));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);
    // Set up column sizes.
    initColumnSizes(table);

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    add(splitPane);

    jPanelDetail = new JPanel();
    splitPane.setBottomComponent(jPanelDetail);
    splitPane.setTopComponent(panel_1);
    jPanelDetail.setLayout(new BorderLayout(0, 0));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);
            logger.info("ListSelectionListener - selectedRow: " + selectedRow);
            if (selectedRow >= 0) {
                if (jPanelDetail != null) {
                    logger.debug("ListSelectionListener - valueChanged");
                    jPanelDetail.removeAll();
                    recEditor = getEditor(repository.getRecording(StatRecording.class, selectedRow));
                    if (recEditor != null) {
                        jPanelDetail.add(recEditor, BorderLayout.CENTER);
                    }
                    jPanelDetail.revalidate();
                }
            }
        }
    });
    if (repository.getRecordings(StatRecording.class).size() > 0) {
        recEditor = getEditor(repository.getRecording(StatRecording.class, 0));
        jPanelDetail.add(recEditor, BorderLayout.CENTER);
        table.setRowSelectionInterval(0, 0);
    }
    if (model.getRowCount() > 0) {
        table.getRowSorter().toggleSortOrder(0);
        table.setRowSelectionInterval(0, 0);

    }
}

From source file:com.dbschools.quickquiz.client.giver.MainWindow.java

private void addListeners() {
    takerTableDisplay.addTableKeyListener(new KeyAdapter() {
        @Override//w  w  w . j  av  a 2s.  c om
        public void keyPressed(KeyEvent e) {
            char keyChar = e.getKeyChar();
            if (Character.isDigit(keyChar) && e.isControlDown()) {
                awardPoints(Integer.parseInt(Character.toString(keyChar)));
            }
        }
    });
    final ListSelectionModel takerTableSelectionModel = takerTableDisplay.getSelectionModel();
    takerTableSelectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            btnAwardPoints.setEnabled(!takerTableSelectionModel.isSelectionEmpty());
        }
    });
    countdownMeter.addCountdownFinishListener(new CountdownFinishListener() {
        public void countdownFinished() {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    btnSendQuestion.setEnabled(true);
                }
            });
        }
    });
}

From source file:logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.java

/**
 * Create the panel.//from  w  w  w.  j  av  a  2s . c  om
 */
public MetadataRecordingSelectorPanel(Repository rep, Source src) {
    repository = rep;
    source = src;
    records = rep.getRecordings(MetadataRecording.class);
    // Collections.sort(records);
    Iterator it = records.iterator();
    while (it.hasNext()) {
        Recording record = (Recording) it.next();
        data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(),
                src.isActiveRecordingOnSource(record) });
    }

    model = new logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.MyTableModel(data, header);

    logger.info("source is " + ((source == null) ? "null" : src.getSourceName()));
    setLayout(new BorderLayout(0, 0));

    JPanel panel_1 = new JPanel();
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);

    table.setPreferredScrollableViewportSize(new Dimension(0, 150));
    table.setFillsViewportHeight(true);
    table.setAutoCreateRowSorter(true);

    // Set up column sizes.
    initColumnSizes(table);
    reloadTable();

    JSplitPane splitPane = new JSplitPane();
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    add(splitPane);

    jPanelDetail = new JPanel();
    splitPane.setBottomComponent(jPanelDetail);
    splitPane.setTopComponent(panel_1);

    jPanelDetail.setLayout(new BorderLayout(0, 0));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1)
            // persist repository
            // display selected row
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);

            logger.info("ListSelectionListener - selectedRow: " + selectedRow);
            if (selectedRow >= 0) {

                if (jPanelDetail != null) {
                    logger.debug("ListSelectionListener - valueChanged");
                    jPanelDetail.removeAll();
                    recEditor = getEditor(repository.getRecording(MetadataRecording.class, selectedRow));
                    if (recEditor != null) {
                        jPanelDetail.add(recEditor, BorderLayout.CENTER);
                    }
                    reloadTable();
                    jPanelDetail.revalidate();
                }
            }
        }
    });
    if (repository.getRecordings(MetadataRecording.class).size() > 0) {
        recEditor = getEditor(repository.getRecording(MetadataRecording.class, 0));
        jPanelDetail.add(recEditor, BorderLayout.CENTER);
        table.setRowSelectionInterval(0, 0);
    }
    if (model.getRowCount() > 0) {
        table.getRowSorter().toggleSortOrder(0);
        table.setRowSelectionInterval(0, 0);
    }
    //reloadTable();
    // jPanelDetail.revalidate();

}

From source file:de.tor.tribes.ui.views.DSWorkbenchConquersFrame.java

DSWorkbenchConquersFrame() {
    initComponents();//from w  w w .  ja v a 2 s  . co m
    centerPanel = new GenericTestPanel();
    jConquerPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jConquersPanel);
    buildMenu();

    jConquersFrameAlwaysOnTop
            .setSelected(GlobalOptions.getProperties().getBoolean("conquers.frame.alwaysOnTop"));
    setAlwaysOnTop(jConquersFrameAlwaysOnTop.isSelected());

    jConquersTable.setModel(new ConquerTableModel());
    jConquersTable.getSelectionModel().addListSelectionListener(DSWorkbenchConquersFrame.this);
    capabilityInfoPanel1.addActionListener(this);
    jConquersTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchConquersFrame.getSingleton().actionPerformed(new ActionEvent(jConquersTable, 0, "Find"));
        }
    });

    jXColumnList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateFilter();
        }
    });
    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.conquers_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
    setGlassPane(jxFilterPane);
    pack();
}

From source file:com.floreantpos.ui.views.order.modifier.TicketItemModifierTableView.java

private void initComponents() {
    titledBorder.setTitle(modifierSelectionModel.getTicketItem().getName());
    titledBorder.setTitleJustification(TitledBorder.CENTER);
    setBorder(border);//from w  ww .  ja  v  a2 s  .co  m
    setLayout(new java.awt.BorderLayout(5, 5));

    ticketItemActionPanel = new com.floreantpos.swing.TransparentPanel();
    //btnDecreaseAmount = new com.floreantpos.swing.PosButton();
    btnScrollDown = new com.floreantpos.swing.PosButton();
    modifierViewerTable = new com.floreantpos.ui.views.order.modifier.ModifierViewerTable(
            modifierSelectionModel.getTicketItem());
    ticketScrollPane = new PosScrollPane(modifierViewerTable);
    ticketScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    ticketScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    ticketScrollPane.setPreferredSize(new java.awt.Dimension(180, 200));

    createTicketActionPanel();
    createTicketItemControlPanel();

    JPanel centerPanel = new JPanel(new BorderLayout(5, 5));
    centerPanel.add(ticketScrollPane);

    centerPanel.add(createItemDescriptionPanel(), BorderLayout.NORTH);
    add(centerPanel);
    add(ticketActionPanel, BorderLayout.SOUTH);
    centerPanel.add(ticketItemActionPanel, BorderLayout.EAST);

    modifierViewerTable.getRenderer().setInTicketScreen(true);
    modifierViewerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateSelectionView();
            }
        }
    });

    modifierViewerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {

            Object selected = modifierViewerTable.getSelected();
            if (!(selected instanceof ITicketItem)) {
                return;
            }

            ITicketItem item = (ITicketItem) selected;

            Boolean printedToKitchen = item.isPrintedToKitchen();
            btnDelete.setEnabled(!printedToKitchen);
        }

    });

    setPreferredSize(new java.awt.Dimension(360, 463));

}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java

private void addTable() {

    defaultTableModel.addColumn("");
    defaultTableModel.addColumn("Property");
    defaultTableModel.addColumn("Value");

    final LegendColourRenderer cellRenderer = new LegendColourRenderer();
    final JTable table = new JTable(defaultTableModel) {

        @Override/* w  w  w.  j a  v  a  2 s.c  o m*/
        public TableCellRenderer getCellRenderer(int row, int column) {
            if (column == 0) {
                return cellRenderer;
            }
            return super.getCellRenderer(row, column);
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        };
    };

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            if (e.getFirstIndex() >= 0) {

                String value = (String) defaultTableModel.getValueAt(table.getSelectedRow(), 1);
                eventTablePanel.setFilterString(value);
            }
        }
    });

    TableColumn column;
    for (int i = 0; i < 3; i++) {
        column = table.getColumnModel().getColumn(i);

        switch (i) {
        case 0:
            column.setMinWidth(15);
            column.setMaxWidth(15);
            column.setPreferredWidth(15);
            break;

        case 2:
            column.setMinWidth(70);
            column.setMaxWidth(70);
            column.setPreferredWidth(70);
            break;
        }
    }

    JScrollPane tablecrollPane = new JScrollPane(table);
    tablecrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    this.add(tablecrollPane, BorderLayout.CENTER);
}

From source file:com.mirth.connect.connectors.jdbc.DatabaseMetadataDialog.java

/**
 * Makes the alert table with a parameter that is true if a new alert should be added as well.
 *//*  w w w. j  av a 2s .c  o m*/
public void makeIncludedMetaDataTable(Set<Table> metaData) {
    updateIncludedMetaDataTable(metaData);

    includedMetaDataTable.setDragEnabled(false);
    includedMetaDataTable.setRowSelectionAllowed(false);
    includedMetaDataTable.setRowHeight(UIConstants.ROW_HEIGHT);
    includedMetaDataTable.setFocusable(false);
    includedMetaDataTable.setOpaque(true);
    includedMetaDataTable.getTableHeader().setReorderingAllowed(false);
    includedMetaDataTable.setSortable(false);

    includedMetaDataTable.getColumnExt(INCLUDED_STATUS_COLUMN_NAME).setMaxWidth(50);
    includedMetaDataTable.getColumnExt(INCLUDED_STATUS_COLUMN_NAME).setMinWidth(50);
    includedMetaDataTable.getColumnExt(INCLUDED_TYPE_COLUMN_NAME).setVisible(false);
    includedMetaDataTable.getColumnExt(INCLUDED_TYPE_COLUMN_NAME).setMinWidth(5);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        includedMetaDataTable.setHighlighters(highlighter);
    }

    includedMetaDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
        }
    });

    includedMetaDataPane.setViewportView(includedMetaDataTable);

    // Mouse listener for trigger-button popup on the table.
    includedMetaDataTable.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkTableNameSelected(evt);
        }
    });

}

From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java

DSWorkbenchStatsFrame() {
    initComponents();//  w w  w .j  av a 2s  . co m
    centerPanel = new GenericTestPanel();
    jStatsPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jMainStatPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    jTabbedPane1.registerKeyboardAction(DSWorkbenchStatsFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    jTribeList.registerKeyboardAction(DSWorkbenchStatsFrame.this, "Delete", delete,
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    jAlwaysOnTopBox.setSelected(GlobalOptions.getProperties().getBoolean("stats.frame.alwaysOnTop"));
    setAlwaysOnTop(jAlwaysOnTopBox.isSelected());

    jAllyList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            List allySelection = jAllyList.getSelectedValuesList();
            jTribeList.clearSelection();
            List<Tribe> tribes = new LinkedList<>();
            for (Object o : allySelection) {
                Tribe[] tribesForAlly = StatManager.getSingleton().getMonitoredTribes((Ally) o);
                for (Tribe t : tribesForAlly) {
                    if (!tribes.contains(t)) {
                        tribes.add(t);
                    }
                }
                Collections.sort(tribes);
                DefaultListModel<Tribe> model = new DefaultListModel<>();
                for (Tribe t : tribes) {
                    model.addElement(t);
                }
                jTribeList.setModel(model);
            }
        }
    });

    jTribeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            fireUpdateChartEvent(null);
        }
    });

    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    jStartDate.setDate(c.getTime());
    jEndDate.setDate(c.getTime());
    jStatCreatePanel.setVisible(false);
    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.stats_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>

    pack();
}

From source file:org.nekorp.workflow.desktop.view.DatosAutoView.java

@Override
public void iniciaVista() {
    initComponents();/*from  w  w w  .j a  v  a  2s . co m*/
    bindComponents();
    searchModel = new AutoSearchJListModel();
    search.setModel(searchModel);
    //esto resuelve el problema de regresar el foco a la caja de texto.
    search.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (search.hasFocus()) {
                numeroSerie.requestFocus();
            }
        }
    });
    this.numeroSerie.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            actualizarNumeroSerie();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            actualizarNumeroSerie();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            actualizarNumeroSerie();
        }
    });
    this.cancelIcon.add(iconProvider.getIcon(cancelSearchIconRaw));
    this.searchIcon.add(iconProvider.getIcon(searchIconRaw));
}

From source file:org.gumtree.vis.awt.AbstractPlotEditor.java

private JPanel createHelpPanel() {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = plot.getHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);// www  .j a  v  a2  s. c  o  m
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;
}