Example usage for javax.swing.event ListSelectionEvent getSource

List of usage examples for javax.swing.event ListSelectionEvent getSource

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initAuthorsTable() {
    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/*w  ww.j a va 2  s  .  c o  m*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel selectionModel = authorsTable.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
            if (source.getMinSelectionIndex() >= 0) {
                authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex());
            }

            if (!e.getValueIsAdjusting()) {
                booksTableModel.setAuthorIndex(source.getMinSelectionIndex());
            }

        }
    });

    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    JPopupMenu authorsPopupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");

    authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = authorsTable.rowAtPoint(
                            SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable));
                    if (rowAtPoint > -1) {
                        authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                        authorsTableModel.setCurrentSlectedIndex(rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteItem.addActionListener(new ActionListener() {
        private Author author;

        @Override
        public void actionPerformed(ActionEvent e) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow());
                    log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname()
                            + " from database.");
                    authorManager.deleteAuthor(author);

                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (InterruptedException | ExecutionException e) {
                        if (e.getCause() instanceof DataIntegrityViolationException) {
                            JOptionPane.showMessageDialog(MainWindow.this,
                                    "Couldn't delete author; there are still some books assigned to him.",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                        log.error("There was an exception thrown during deletion author: "
                                + author.getFirstname() + " " + author.getSurname(), e);

                        return;
                    }

                    updateModel();
                }
            }.execute();
        }
    });
    authorsPopupMenu.add(deleteItem);
    authorsTable.setComponentPopupMenu(authorsPopupMenu);
}

From source file:com.starbucks.apps.StarbucksBarista.java

private void ordersListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ordersListValueChanged
    JList list = (JList) evt.getSource();
    Order order = (Order) list.getSelectedValue();
    if (order != null) {
        viewButton.setEnabled(true);/*ww  w. j a  v a2  s  .  com*/
        prepareButton.setEnabled(true);
    }
}

From source file:gui.TwopointPWDPanel.java

private void processMarkerTableClick(ListSelectionEvent e) {
    // Reset the display areas
    while (phaseModel.getRowCount() > 0) {
        phaseModel.removeRow(0);/*from w w  w .j a va  2  s  . co  m*/
    }
    rfqChart.clearDataset();
    lodChart.clearDataset();

    // The selected marker...
    ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    CMarker selM = null;
    if (lsm.isSelectionEmpty() == false) {
        int selectedRow = lsm.getMinSelectionIndex();
        selM = (CMarker) markerTable.getValueAt(selectedRow, 1);
    }

    if (selM != null) {
        // ...against all the other markers (in the correct order)
        if (AppFrame.tpmmode != AppFrame.TPMMODE_NONSNP) {
            order.freezeSafeNames();
        }
        for (CMarker lnkM : order.getLinkageGroup().getMarkers()) {
            // Self against self -> add an empty row
            if (selM.marker == lnkM.marker) {
                phaseModel.addRow(new Object[] { "", selM, "", "" });
            } else {
                int i = order.getLinkageGroup().getMarkerIndexBySafeName(selM.safeName);
                int j = order.getLinkageGroup().getMarkerIndexBySafeName(lnkM.safeName);
                int i2 = i, j2 = j;
                if (order.translateIndexes != null) {
                    i2 = order.translatePPIndexes[i];
                    j2 = order.translatePPIndexes[j];
                }
                if (order.getPhasePairArray()[i2][j2] != null) {
                    appendMarker(lnkM, order.getPhasePairArray()[i2][j2]);
                }
            }
        }
    }

    m1Label.setText("");
    m2Label.setText("");
}

From source file:gui.TwopointPWDPanelnonsnp.java

private void processMarkerTableClick(ListSelectionEvent e) {
    // Reset the display areas
    while (phaseModel.getRowCount() > 0) {
        phaseModel.removeRow(0);/*from  www .  j  a va 2s  .  com*/
    }
    rfqChart.clearDataset();
    lodChart.clearDataset();

    // The selected marker...
    ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    CMarker selM = null;
    if (lsm.isSelectionEmpty() == false) {
        int selectedRow = lsm.getMinSelectionIndex();
        selM = (CMarker) markerTable.getValueAt(selectedRow, 1);
    }

    if (selM != null) {
        // ...against all the other markers (in the correct order)
        for (CMarker lnkM : order.getLinkageGroup().getMarkers()) {
            // Self against self -> add an empty row
            if (selM.marker == lnkM.marker) {
                phaseModel.addRow(new Object[] { "", selM, "", "" });
            } else {
                int i = selM.getSafeNameSuffix() - 1;
                int j = lnkM.getSafeNameSuffix() - 1;
                /* changed getIndex() to getSafeNameSuffix()-1 */
                appendMarker(lnkM, order.getPhasePairArray()[i][j]);
            }
        }
    }

    m1Label.setText("");
    m2Label.setText("");
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void valueChanged(ListSelectionEvent e) {
    if (e.getSource() == table.getSelectionModel()) {
        // The parent directory can't be selected
        final File parentDir = getParentDirectory();

        if (parentDir != null) {
            if (getSelection().contains(parentDir)) {
                // Unselect the parent directory entry (always the 1st one)
                table.getSelectionModel().removeSelectionInterval(0, 0);
            }/*ww w  . j  a v  a  2s .co m*/
        }

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("[%s] Selection changed", getComponentLabel()));
        }

        // Propagate the event
        fireChangeEvent();
    }
}

From source file:com.wesley.urban_cuts.client.urbancuts.myFrame.java

/**
 * Creates new form HomeFrame/*from   w w  w .  ja v a 2s . c  o m*/
 */
public myFrame() {
    initComponents();
    ctx = new ClassPathXmlApplicationContext(
            "classpath:com/wesley/urban_cuts/app/conf/applicationContext-*.xml");
    staffCrudService = (StaffCrudService) ctx.getBean("StaffCrudService");
    styleCrudService = (StyleCrudService) ctx.getBean("StyleCrudService");
    paymentCrudService = (PaymentCrudService) ctx.getBean("PaymentCrudService");

    populate_barbers();
    populate_styles();
    populate_table();

    jList2.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                JList source = (JList) event.getSource();
                String selected = source.getSelectedValue().toString();
                jTextField1.setText(selected);
            }
        }
    });

    jList3.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                JList source = (JList) event.getSource();
                String selected2 = source.getSelectedValue().toString();
                jTextField3.setText(selected2);
                Style s = styleCrudService.getByPropertyName("style_name", jTextField3.getText());
                jTextField2.setText(Double.toString(s.getPrice()));
            }
        }
    });
}

From source file:userinterface.graph.GraphOptionsPanel.java

public void valueChanged(ListSelectionEvent e) {
    stopEditors();/*from   w  ww.j a  va2  s .c o  m*/
    doEnables();

    if (e.getSource() == axesList) {
        int[] sel = axesList.getSelectedIndices();

        ArrayList own = new ArrayList();

        for (int i = 0; i < sel.length; i++) {
            if (sel[i] == 0)
                own.add(xAxisSettings);
            else if (sel[i] == 1)
                own.add(yAxisSettings);
        }
        axisPropertiesTable.setOwners(own);
    } else if (e.getSource() == seriesList) {
        Object lock = null;

        if (theModel instanceof Graph) {
            lock = ((Graph) theModel).getSeriesLock();
        } else if (theModel instanceof Histogram) {
            lock = ((Histogram) theModel).getSeriesLock();
        }

        if (lock == null) {
            return;
        }

        synchronized (lock) {
            int[] sel = seriesList.getSelectedIndices();

            ArrayList own = new ArrayList();
            //seriesPropertiesTable.setOwners(own);

            for (int i = 0; i < sel.length; i++) {
                if (theModel instanceof Graph)
                    own.add(((Graph) theModel).getGraphSeriesList().getElementAt(sel[i]));
            }

            //seriesPropertiesTable = new SettingTable(parent);
            //seriesPropertiesTable.setOwners(own);
        }
    }
}

From source file:jboost.visualization.HistogramFrame.java

private JScrollPane getJScrollPane1() {
    if (jScrollPane1 == null) {
        jScrollPane1 = new JScrollPane();
        jList1 = new JList(infoParser.iterNoList);
        jList1.setLayout(new FlowLayout());
        jList1.setFocusable(false);/*from   w ww. j  av  a 2 s  .  c  o  m*/
        jList1.setIgnoreRepaint(false);
        jList1.addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent evt) {
                if (!evt.getValueIsAdjusting()) {
                    JList list = (JList) evt.getSource();
                    iter = list.getSelectedIndex();
                    loadIteration(iter);
                }
            }
        });
        jScrollPane1.getViewport().add(jList1);
    }
    return jScrollPane1;
}

From source file:gda.gui.BatonPanel.java

/**
 * change the appearance of the give button depending if there is a selection or not {@inheritDoc}
 * /* w w w  . ja va2  s  .  com*/
 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
 */
@Override
public void valueChanged(ListSelectionEvent e) {
    boolean enable = false;
    ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    if (!lsm.isSelectionEmpty() && btnRelease.isEnabled() && userClients.getModel().getRowCount() > 1) {
        int selectedRow = lsm.getMinSelectionIndex();
        Integer selectedUser = (Integer) userClients.getValueAt(selectedRow, 0);
        enable = selectedUser != JythonServerFacade.getInstance().getClientID();
    }
    final boolean fenable = enable;
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            btnGive.setEnabled(fenable);
        }
    });

}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getSource() == inputDocList && inputDocList.getSelectedValues().length == 1) {
        Document doc = (Document) inputDocList.getSelectedValue();
        inputDocArea.setText(doc.getText());
        inputDocArea.setCaretPosition(0);
        inputDocLangBox.setSelectedItem(doc.getLang());
    } else if (e.getSource() == docList && docList.getSelectedValues().length == 1) {
        Document doc = (Document) docList.getSelectedValue();
        inputDocArea.setText(doc.getText());
        inputDocArea.setCaretPosition(0);
        docLangBox.setSelectedItem(doc.getLang());
    }/* ww  w .  j a v a  2  s . com*/
}