List of usage examples for javax.swing.event ListSelectionEvent getSource
public Object getSource()
From source file:net.sf.firemox.DeckBuilder.java
public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (e.getSource() == leftList.getSelectionModel()) { if (leftList.getSelectedIndex() == -1 || allListModel.isEmpty()) { // No selection, disable fire button. addButton.setEnabled(false); } else { // Selection, enable the fire button. addButton.setEnabled(true); // Update the views final MCardCompare selectedCard = (MCardCompare) leftList.getSelectedValue(); cardNameTxt.setText(selectedCard.getName()); setCard(selectedCard);/*from ww w .ja v a 2 s .c o m*/ } } else if (e.getSource() == rightList.getSelectionModel()) { if (rightList.getSelectedRow() == -1) { // No selection, disable fire button. removeButton.setEnabled(false); } else { // Selection, enable the fire button. removeButton.setEnabled(true); // Update the views setCard(rightListModel.getCards().getElementAt(rightList.getSelectedRow())); } } } }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
/** * Class Constructor.//from ww w . ja v a 2 s . c o m * * @param model * * @see */ public RegistryObjectsTable(TableModel model) { // Gives a TableColumnModel so that AutoCreateColumnsFromModel will be false. super(model, new DefaultTableColumnModel()); this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); if (model instanceof RegistryObjectsTableModel) { tableModel = (RegistryObjectsTableModel) model; } else if (model instanceof TableSorter) { tableModel = (RegistryObjectsTableModel) (((TableSorter) model).getModel()); } else { Object[] unexpectedTableModelArgs = { model }; MessageFormat form = new MessageFormat(resourceBundle.getString("error.unexpectedTableModel")); throw new IllegalArgumentException(form.format(unexpectedTableModelArgs)); } setToolTipText(resourceBundle.getString("tip.registryObjectsTable")); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); ListSelectionModel rowSM = getSelectionModel(); stdRowHeight = getRowHeight(); setRowHeight(stdRowHeight * 3); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (!lsm.isSelectionEmpty()) { setSelectedRow(lsm.getMinSelectionIndex()); } else { setSelectedRow(-1); } } }); createPopup(); addRenderers(); // Add listener to self so that I can bring up popup menus on right mouse click popupListener = new PopupListener(); addMouseListener(popupListener); //add listener for 'authenticated' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this); //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); }
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
/** * Register a selection listener to the JTable related to this class * * @param rowSelectionListener that will be called when the selection of the JTable changes *//*from w w w . jav a2s . c o m*/ public void registerRowSelectionListener(final RowSelectionListener rowSelectionListener) { ListSelectionModel rowSM = jTable.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { logger.debug("No rows are selected."); rowSelectionListener.onClearSelectedRow(); } else { int selectedRowIndex = lsm.getMinSelectionIndex(); logger.debug("Row " + selectedRowIndex + " is now selected."); Object selectedRow = getSelectedRow(); rowSelectionListener.onSelectedRow(selectedRowIndex, selectedRow); } } }); }
From source file:homenetapp.HomeNetAppGui.java
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged int index = evt.getFirstIndex(); JList j = (JList) evt.getSource(); homenet.Packet p = (homenet.Packet) j.getSelectedValue(); //homenet.Packet p = (homenet.Packet)packetListModel.getElementAt(index); displayPacket(p);/* w w w .ja v a 2s .c o m*/ }
From source file:cnu.eslab.fileTest.NewJFrame.java
@Override public void valueChanged(ListSelectionEvent e) { // TODO Auto-generated method stub if (e.getSource() == mUidList) { // package name ? UID index . int indexEnd = -1; if (e.getValueIsAdjusting() == false) { if (mUidList.getSelectedIndex() == -1) { // ?? ? ? ? . ComponetStateChanger(POWER_BUTTON_OFF); } else { // ?? ? ? . ComponetStateChanger(POWER_BUTTON_ON); mSearchUid = mUidList.getSelectedValue().toString(); indexEnd = mSearchUid.indexOf(" "); mSearchUid = mSearchUid.substring(0, indexEnd); mFilePathTextField.setText(mSearchUid); }// w w w. ja v a2 s .c o m } } else if (e.getSource() == mDeleteList) { } }
From source file:edu.ku.brc.af.ui.forms.validation.ValComboBoxFromQuery.java
public void valueChanged(final ListSelectionEvent e) { //log.debug("valueChanged: "+(e != null ? ((JMenuItem)e.getSource()).getText() : "null")); //log.debug("valueChanged: "+(e != null ? e.getClass().getSimpleName() : "null")+" "+e.getSource().getClass().getSimpleName()); if (e != null) { if (e.getSource() instanceof TextFieldWithQuery.AddItemEvent) { doNewAction(((TextFieldWithQuery.AddItemEvent) e.getSource()).value); return; } else if (e.getSource() instanceof TextFieldWithQuery) { if (((TextFieldWithQuery) e.getSource()).getTextField().getText().length() == 0) { dataObj = null;/* w ww . j a v a 2 s . com*/ } } else { String itemLabel = null; if (e.getSource() instanceof JMenuItem) { itemLabel = ((JMenuItem) e.getSource()).getText().toString(); this.dataObj = null; getValue(); refreshUIFromData(true); } else if (e.getSource() instanceof JList) { JList listBox = (JList) e.getSource(); if (listBox.getSelectedIndex() > -1) { itemLabel = listBox.getSelectedValue().toString(); this.dataObj = null; getValue(); } else { return; } } } } isChanged = true; valueHasChanged(); validateState(); boolean doEnable = dataObj != null || (textWithQuery != null && textWithQuery.getSelectedId() != null); if (editBtn != null) { editBtn.setEnabled(doEnable); } if (cloneBtn != null) { cloneBtn.setEnabled(doEnable); } notifyListeners(e); repaint(); }
From source file:com.pironet.tda.TDA.java
/** * process table selection events (thread display) * * @param e the event to process.//www.j av a2 s .co m */ public void valueChanged(ListSelectionEvent e) { //displayCategory(e.getFirstIndex()); ThreadsTableSelectionModel ttsm = (ThreadsTableSelectionModel) e.getSource(); TableSorter ts = (TableSorter) ttsm.getTable().getModel(); int[] rows = ttsm.getTable().getSelectedRows(); StringBuffer sb = new StringBuffer(); for (final int row : rows) { appendThreadInfo(sb, ((ThreadsTableModel) ts.getTableModel()).getInfoObjectAtRow(ts.modelIndex(row))); } displayContent(sb.toString()); setThreadDisplay(true); }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Build the table now that we have all the information we need for the columns. *//*ww w . j ava2s .c o m*/ protected void buildTable() { // Now Build the JTable model = new ColTableModel(); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setFocusable(false); //table.setPreferredScrollableViewportSize(new Dimension(200,table.getRowHeight()*6)); configColumns(); //table.setCellSelectionEnabled(false); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); updateUI(!lsm.isSelectionEmpty()); } } }); table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() == 2) { int index = table.getSelectedRow(); editRow(index, false); } } }); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); /* // This is BROKEN! table.setCellSelectionEnabled(true); for (int i=0;i<model.getColumnCount();i++) { TableColumn column = table.getColumn(model.getColumnName(i)); //log.info(model.getColumnName(i)); //column.setCellRenderer(renderer); ColumnInfo columnInfo = columnList.get(i); Component comp = columnInfo.getComp(); //column.setCellEditor(new DefaultCellEditor(new JTextField())); if (comp instanceof GetSetValueIFace) { column.setCellEditor(new MyTableCellEditor(columnInfo)); } else if (comp instanceof JTextField) { column.setCellEditor(new DefaultCellEditor((JTextField)comp)); } else { log.error("Couldn't figure out DefaultCellEditor for comp ["+comp.getClass().getSimpleName()+"]"); } } */ tableScroller = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); orderablePanel = new JPanel(new BorderLayout()); orderablePanel.add(tableScroller, BorderLayout.CENTER); mainComp.add(orderablePanel, BorderLayout.CENTER); initColumnSizes(table); }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Handles list selection events for this application. *//*from w w w .j a va 2 s . c om*/ public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } if (e.getSource().equals(bucketsTable.getSelectionModel())) { bucketSelectedAction(); } else if (e.getSource().equals(objectsTable.getSelectionModel())) { objectSelectedAction(); } }
From source file:de.main.sessioncreator.DesktopApplication1View.java
public void getAreasBacgroundW(File f) { fileHelper.getAreas(f);//from w w w . j av a 2s . c om Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator(); while (it.hasNext()) { DefaultListModel dlm = new DefaultListModel(); JList list = new JList(dlm); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.getViewport().setView(list); Map.Entry en = it.next(); wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane); for (Object o : fileHelper.areaMap.get(en.getKey().toString())) { dlm.addElement(o); } MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList tabList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = tabList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = tabList.getModel().getElementAt(index); wizardtaChoosenAreas.append(o.toString() + "\n"); } } } }; list.addMouseListener(mouseListener); ListSelectionListener listListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable add button. wizardbtnAddAreas.setEnabled(false); } else { //Selection, enable the add button. wizardbtnAddAreas.setEnabled(true); } } } }; list.addListSelectionListener(listListener); } }