javax.swing.event.ListSelectionEvent Java Examples

The following examples show how to use javax.swing.event.ListSelectionEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaxonSetPanel.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void initTaxonSetsTable(AbstractTableModel tableModel, final String[] columnToolTips) {
    taxonSetsTable = new JTable(tableModel) {
        //Implement table header tool tips.
        protected JTableHeader createDefaultTableHeader() {
            return new JTableHeader(columnModel) {
                public String getToolTipText(MouseEvent e) {
                    Point p = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(p.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();
                    return columnToolTips[realIndex];
                }
            };
        }
    };
    taxonSetsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    taxonSetsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            taxonSetsTableSelectionChanged();
        }
    });
    taxonSetsTable.doLayout();
}
 
Example #2
Source File: ThemeEditor.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void initTableModel(final JTable table, String stylePrefix) {
    final ThemeModel model = new ThemeModel(themeHash, stylePrefix);
    table.setModel(model);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int row = getModelSelection(getCurrentStyleTable());
            editEntry.setEnabled(row > -1);
            removeThemeEntry.setEnabled(row > -1);
            /*
             * if(liveHighlighting.isSelected() && row > -1 && table !=
             * constantsTable && row < model.getRowCount()) {
             * flashSelectedProperty(model, (String)model.getValueAt(row,
             * 0)); }
             */
        }
    });
}
 
Example #3
Source File: FileTemplateTabAsList.java    From consulo with Apache License 2.0 6 votes vote down vote up
FileTemplateTabAsList(String title) {
  super(title);
  myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myList.setCellRenderer(new MyListCellRenderer());
  myList.addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
      onTemplateSelected();
    }
  });
  new ListSpeedSearch(myList, new Function<Object, String>() {
    @Override
    public String fun(final Object o) {
      if (o instanceof FileTemplate) {
        return ((FileTemplate)o).getName();
      }
      return null;
    }
  });
}
 
Example #4
Source File: FontDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private void styleListValueChanged(ListSelectionEvent e) {

		int style = -1;
		String selectedStyle = styleList.getSelectedValue();
		if (selectedStyle == PLAIN) {
			style = Font.PLAIN;
		}
		if (selectedStyle == BOLD) {
			style = Font.BOLD;
		}
		if (selectedStyle == ITALIC) {
			style = Font.ITALIC;
		}
		if (selectedStyle == BOLD_ITALIC) {
			style = Font.BOLD + Font.ITALIC;
		}

		font = FontTools.getFont(font.getFamily(), style, font.getSize());
		previewLabel.setFont(font);
	}
 
Example #5
Source File: VcsConfigurationsDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void initList(VcsDescriptor[] names) {
  DefaultListModel model = new DefaultListModel();

  for (VcsDescriptor name : names) {
    model.addElement(name);
  }

  myVcses.setModel(model);
  myVcses.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
      updateConfiguration();
    }
  });

  myVcses.setCellRenderer(VCS_LIST_RENDERER);

  myVcsesScrollPane.setMinimumSize(myVcsesScrollPane.getPreferredSize());
}
 
Example #6
Source File: RepositoryPublishDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Called whenever the value of the selection changes.
 *
 * @param e
 *          the event that characterizes the change.
 */
public void valueChanged( final ListSelectionEvent e ) {
  final int selectedRow = getTable().getSelectedRow();
  if ( selectedRow == -1 ) {
    return;
  }

  final FileObject selectedFileObject = getTable().getSelectedFileObject( selectedRow );
  if ( selectedFileObject == null ) {
    return;
  }

  try {
    if ( selectedFileObject.getType() == FileType.FILE ) {
      getFileNameTextField().setText( selectedFileObject.getName().getBaseName() );
    }
  } catch ( FileSystemException e1 ) {
    // ignore ..
  }
}
 
Example #7
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
   if (e.getValueIsAdjusting())  
      return;
   ListSelectionModel lsm = (ListSelectionModel)e.getSource();
   if (lsm.isSelectionEmpty())
      return;
   if (lsm.equals(jAllGroupsList.getSelectionModel())){
      // Due to SINGLE_SELECTION mode we'll break on first match
      int minIndex=lsm.getMinSelectionIndex();
      int maxIndex=lsm.getMaxSelectionIndex();
      for(int i=minIndex; i<=maxIndex; i++){
         if (lsm.isSelectedIndex(i)){
            Object obj=jAllGroupsList.getModel().getElementAt(i);
            if (obj instanceof ObjectGroup){
               currentGroup = (ObjectGroup) obj;
               updateCurrentGroup();
            }
         }
      }
   }
}
 
Example #8
Source File: ListSelectionDocument.java    From blog with Apache License 2.0 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	JList<?> list = (JList<?>) e.getSource();
	ListModel<?> model = list.getModel();

	ListSelectionModel listSelectionModel = list.getSelectionModel();

	int minSelectionIndex = listSelectionModel.getMinSelectionIndex();
	int maxSelectionIndex = listSelectionModel.getMaxSelectionIndex();

	StringBuilder textBuilder = new StringBuilder();

	for (int i = minSelectionIndex; i <= maxSelectionIndex; i++) {
		if (listSelectionModel.isSelectedIndex(i)) {
			Object elementAt = model.getElementAt(i);
			formatElement(elementAt, textBuilder, i);
		}
	}

	setText(textBuilder.toString());
}
 
Example #9
Source File: AbilityChooserTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	if (!e.getValueIsAdjusting())
	{
		int index = categoryTable.getSelectionModel().getMinSelectionIndex();
		if (index != -1)
		{
			abilityCat = (AbilityCategory) categoryTable.getValueAt(index, 0);
			this.setEnabled(abilityCat.isEditable());
			this.putValue(SHORT_DESCRIPTION,
				abilityCat.isEditable() ? null : LanguageBundle.getString("in_abCatNotEditable"));
		}

	}
}
 
Example #10
Source File: MechGroupView.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
public void valueChanged(ListSelectionEvent event) {
    if (event.getValueIsAdjusting()) {
        return;
    }
    if (event.getSource().equals(entities)) {
        int selected = entities.getSelectedIndex();
        if (selected == -1) {
            ta.setText("");
            return;
        } else if (!client.getGame().getEntity(entityArray[selected]).getOwner().equals(client.getLocalPlayer())) {
            ta.setText("(enemy unit)");
        } else {
            Entity entity = client.getGame().getEntity(entityArray[selected]);
            MechView mechView = new MechView(entity,
                    client.getGame().getOptions().booleanOption(OptionsConstants.BASE_SHOW_BAY_DETAIL));
            ta.setText(mechView.getMechReadout());
        }
    }
}
 
Example #11
Source File: ClassInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	if (!e.getValueIsAdjusting())
	{
		PCClass data = getSelectedClass(e.getSource());
		if (data != null)
		{
			text = character.getInfoFactory().getHTMLInfo(data, null);
			infoPane.setText(text);
		}
		else
		{
			text = ""; //$NON-NLS-1$
			infoPane.setText(""); //$NON-NLS-1$
		}
	}
}
 
Example #12
Source File: ChooserDialog.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	if (availTable != null && !e.getValueIsAdjusting())
	{
		if (e.getSource() == availTable.getSelectionModel() && availTable.getSelectedObject() instanceof InfoFacade)
		{
			InfoFacade target = (InfoFacade) availTable.getSelectedObject();
			InfoFactory factory = chooser.getInfoFactory();
			if (factory != null && target != null)
			{
				infoPane.setText(factory.getHTMLInfo(target));
			}
		}
	}
}
 
Example #13
Source File: StateModifier.java    From algorithms-nutshell-2ed with MIT License 6 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	// must find the one that is selected
	int idx = list.getSelectedIndex();
	DefaultListModel<IMove> dlm = (DefaultListModel<IMove>) list.getModel();
	FreeCellNode node = (FreeCellNode) initial.copy();
	for (int i = 0; i < idx; i++) {
		IMove move = (IMove) dlm.get(i);
		if (move.isValid(node)) {
			move.execute(node);
		} else {
			System.out.println("INVALID MOVE!");
		}
	}
	
	drawer.setNode(node);
	drawer.repaint();
}
 
Example #14
Source File: ScriptableDataSourceEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void valueChanged( final ListSelectionEvent e ) {
  if ( !inQueryNameUpdate ) {
    final DataSetQuery query = (DataSetQuery) queryNameList.getSelectedValue();
    if ( query != null ) {
      queryNameTextField.setText( query.getQueryName() );
      queryTextArea.setText( query.getQuery() );
      updateComponents();
    } else {
      queryNameTextField.setText( "" );
      queryTextArea.setText( "" );
      updateComponents();
    }
  }
}
 
Example #15
Source File: PostfixTemplatesChildConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nullable
@Override
public JComponent createComponent() {
  PostfixTemplateProvider postfixTemplateProvider = myExtensionPoint.getInstance();
  if (postfixTemplateProvider == null) {
    return null;
  }

  OnePixelSplitter splitter = new OnePixelSplitter();
  splitter.setSplitterProportionKey("PostfixTemplatesChildConfigurable.splitter");

  myCheckBoxList = new CheckBoxList<>();

  splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myCheckBoxList, true));

  myPostfixDescriptionPanel = new PostfixDescriptionPanel();
  JPanel component = myPostfixDescriptionPanel.getComponent();
  component.setBorder(JBUI.Borders.empty(0, 8, 0, 0));
  splitter.setSecondComponent(component);

  myCheckBoxList.setItems(new ArrayList<>(postfixTemplateProvider.getTemplates()), PostfixTemplate::getPresentableName, postfixTemplate -> Boolean.TRUE);

  myCheckBoxList.addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
      PostfixTemplate itemAt = myCheckBoxList.getItemAt(myCheckBoxList.getSelectedIndex());

      myPostfixDescriptionPanel.reset(PostfixTemplateMetaData.createMetaData(itemAt));
    }
  });
  return splitter;
}
 
Example #16
Source File: ClassMethodSelector.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setSelectionModel(final ListSelectionModel selection) {
    this.selection = selection;
    selection.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int index = selection.getMinSelectionIndex();
                selected = index == -1 ? null : getElementAt(index);
            }
        }
    });
}
 
Example #17
Source File: window.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form window
 */
public window() {
    initComponents();
    jList1.addListSelectionListener((ListSelectionEvent e) -> {
        if(!e.getValueIsAdjusting()){
            JList source = (JList)e.getSource();
            jLabel7.setText("JList - "+source.getSelectedValue().toString());
        }
    });
}
 
Example #18
Source File: InnerTablePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new InnerTablePanel.
 *
 * @param model DefaultTableModel for included table
 */
public TablePanel(final AbstractTableModel model) {
    super(model);
    final JTable table = getTable();
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeButton.setEnabled(selectedRowCount > 0);
            editButton.setEnabled(selectedRowCount == 1);
        }
    });
}
 
Example #19
Source File: NotesTableSelectionHandler.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        if (noteTable.getSelectedRow() == -1) {
            return;
        }
        int selectedRow = noteTable.convertRowIndexToModel(noteTable.getSelectedRow());
        int messageId =
                ((NotesTableModel) noteTable.getModel()).getRow(selectedRow).getMessageId();
        HistoryReference hr = extHist.getHistoryReference(messageId);
        extHist.showInHistory(hr);
    }
}
 
Example #20
Source File: DatabaseTablesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DatabaseTablesPanel() {
    initComponents();
    initInitial();
    ListSelectionListener selectionListener = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateButtons();
        }
    };
    availableTablesList.getSelectionModel().addListSelectionListener(selectionListener);
    selectedTablesList.getSelectionModel().addListSelectionListener(selectionListener);
}
 
Example #21
Source File: FiringDisplay.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent event) {
    if (event.getValueIsAdjusting()) {
        return;
    }
    if (event.getSource().equals(clientgui.mechD.wPan.weaponList)
            && (clientgui.getClient().getGame().getPhase() == Phase.PHASE_FIRING)) {
        // If we aren't in the firing phase, there's no guarantee that cen
        // is set properly, hence we can't update

        // update target data in weapon display
        updateTarget();
    }
}
 
Example #22
Source File: XMLMerger.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void valueChanged(ListSelectionEvent listSelectionEvent) {
    if (listSelectionEvent.getSource() == linkingList) {
        linkButton.setEnabled(false);
        unlinkButton.setEnabled(true);
    } else if (listSelectionEvent.getSource() == XMLViewer1.getIdElementList() || listSelectionEvent.getSource() == XMLViewer2.getIdElementList()) {
        if (XMLViewer1.getIdElementList().getSelectedIndex() != -1 && XMLViewer2.getIdElementList().getSelectedIndex() != -1) {
            linkButton.setEnabled(true);
        }

    }
}
 
Example #23
Source File: ComboBoxTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**********************************************************************
 *  Returns the renderer component of the cell.
 *
 *  @interfaceMethod javax.swing.table.TableCellEditor
 *********************************************************************/

public final Component getTableCellEditorComponent (JTable  table,
                                                    Object  value,
                                                    boolean selected,
                                                    int     row,
                                                    int     col)
{

    //add a listener to the table
    if  ( ! this.tableListenerAdded)
    {
        this.tableListenerAdded = true;
        this.table = table;
        this.table.getSelectionModel ().addListSelectionListener (new ListSelectionListener ()
        {
            public final void valueChanged (ListSelectionEvent evt)
            {
                eventTableSelectionChanged ();
            }
        });
    }
    this.currentRow = row;
    this.initialValue = value;

    return getEditorComponent (table, value, selected, row, col);

}
 
Example #24
Source File: TDA.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * process table selection events (thread display)
 * @param e the event to process.
 */
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(int i = 0; i < rows.length; i++) {
        appendThreadInfo(sb, ((ThreadsTableModel) ts.getTableModel()).
                getInfoObjectAtRow(ts.modelIndex(rows[i])));
    }
    displayContent(sb.toString());
    setThreadDisplay(true);
}
 
Example #25
Source File: EndmemberFormModel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        if (endmemberListSelectionModel.isSelectionEmpty()) {
            setSelectedEndmemberIndex(-1);
        } else {
            setSelectedEndmemberIndex(endmemberListSelectionModel.getLeadSelectionIndex());
        }
    }
}
 
Example #26
Source File: PlanBox.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
private void onPlanSelectionChanged(ListSelectionEvent e) {
  VisualizationPlan plan = (VisualizationPlan) planList.getSelectedValue();
  if (plan == null) {
    return;
  }
  // update the display of the panel according to the new plan
  planDetailPanel.setPlan(plan);
}
 
Example #27
Source File: LicenseWindow.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
private JList<License> createLicenseList(License[] licenses, final JTextArea textArea) {
	final JList<License> result = new JList<>(licenses);
	result.setBorder(new LineBorder(Color.darkGray, 1));
	result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	result.addListSelectionListener(new ListSelectionListener() {
		@Override
		public void valueChanged(ListSelectionEvent e) {
			textArea.setText(result.getSelectedValue().getLicenseText());
			textArea.setCaretPosition(0);
		}
	});
	result.setSelectedIndex(0);
	return result;
}
 
Example #28
Source File: ThumbsExplorerPanel.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
protected void fireSelectionChanged(int index) {
  ListSelectionEvent listEvent = new ListSelectionEvent(current, index, index, false);
  Object[] listeners = listenersList.getListeners(ListSelectionListener.class);
  for (Object lst : listeners) {
    ((ListSelectionListener) lst).valueChanged(listEvent);
  }
}
 
Example #29
Source File: ManageTags.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged (ListSelectionEvent e) {
    if (e.getSource() == panel.lstTags && !e.getValueIsAdjusting()) {
        GitTag selectedTag = null;
        Object selectedObject = panel.lstTags.getSelectedValue();
        if (selectedObject instanceof GitTag) {
            selectedTag = (GitTag) panel.lstTags.getSelectedValue();
        }
        updateTagInfo(selectedTag);
    }
}
 
Example #30
Source File: CfgPropsDialog.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new dialog CfgPropsDialog.
 *
 * @param parent the parent dialog.
 */
public CfgPropsDialog(java.awt.Dialog parent) {
    super(parent, true);
    initComponents();
    // retrieve some flads from prefs
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true);
    bDeprErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, true);
    // setup props sorting
    this.sortedProps = new TreeSet<>(new ConfigurationMetadataComparator(bDeprLast));
    // setup property list
    lCfgProps.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final ConfigurationMetadataProperty selectedValue = lCfgProps.getSelectedValue();
                if (selectedValue != null) {
                    tpDetails.setText(Utils.cfgPropDetailsHtml(selectedValue));
                    tpDetails.setCaretPosition(0);
                }
            }
        }
    });
    // set default button
    rootPane.setDefaultButton(bOk);
    // close dialog with ESC key
    final ActionListener escAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            CfgPropsDialog.this.setVisible(false);
        }
    };
    rootPane.registerKeyboardAction(escAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
}