Java Code Examples for javax.swing.ListSelectionModel#addListSelectionListener()

The following examples show how to use javax.swing.ListSelectionModel#addListSelectionListener() . 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: GTableColumnModel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void setSelectionModel(ListSelectionModel newModel) {
	if (newModel == null) {
		throw new IllegalArgumentException("Cannot set a null SelectionModel");
	}

	ListSelectionModel oldModel = selectionModel;
	if (newModel != oldModel) {
		if (oldModel != null) {
			oldModel.removeListSelectionListener(this);
		}

		selectionModel = newModel;
		newModel.addListSelectionListener(this);
	}
}
 
Example 2
Source File: AbilityChooserTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public AvailableAbilityTreeViewModel(CharacterFacade character, ListSelectionModel selectionModel,
	String tableTitle)
{
	this.character = character;
	this.title = tableTitle;
	this.treeviews = new DefaultListFacade<>(AbilityTreeViews.createTreeViewList(character));
	this.selectionModel = selectionModel;
	this.infoFactory = character.getInfoFactory();
	this.delegate = new DelegatingListFacade<>();
	delegate.setDelegate(new DefaultListFacade<>());
	selectionModel.addListSelectionListener(this);

	dataColumns = Arrays.asList(new DefaultDataViewColumn("in_type", String.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsMultiples", Boolean.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsStacks", Boolean.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsDescription", String.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsCost", Float.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsSource", String.class)); //$NON-NLS-1$

}
 
Example 3
Source File: AbilityChooserTab.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
public AvailableAbilityTreeViewModel(CharacterFacade character, ListSelectionModel selectionModel,
	String tableTitle)
{
	this.character = character;
	this.title = tableTitle;
	this.treeviews = new DefaultListFacade<>(AbilityTreeViews.createTreeViewList(character));
	this.selectionModel = selectionModel;
	this.infoFactory = character.getInfoFactory();
	this.delegate = new DelegatingListFacade<>();
	delegate.setDelegate(new DefaultListFacade<>());
	selectionModel.addListSelectionListener(this);

	dataColumns = Arrays.asList(new DefaultDataViewColumn("in_type", String.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsMultiples", Boolean.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsStacks", Boolean.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsDescription", String.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsCost", Float.class), //$NON-NLS-1$
		new DefaultDataViewColumn("in_abColumnsSource", String.class)); //$NON-NLS-1$

}
 
Example 4
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/**
 * Create and install the listeners for the JList, its model, and its
 * selectionModel.  This method is called at installUI() time.
 *
 * @see #installUI
 * @see #uninstallListeners
 */
protected void installListeners()
{
  focusListener = createFocusListener();
  mouseInputListener = createMouseInputListener();
  propertyChangeListener = createPropertyChangeListener();
  listSelectionListener = createListSelectionListener();
  listDataListener = createListDataListener();

  list.addFocusListener(focusListener);
  list.addMouseListener(mouseInputListener);
  list.addMouseMotionListener(mouseInputListener);
  list.addPropertyChangeListener(propertyChangeListener);

  ListModel model = list.getModel();
  if (model != null) {
    model.addListDataListener(listDataListener);
  }

  ListSelectionModel selectionModel = list.getSelectionModel();
  if (selectionModel != null) {
    selectionModel.addListSelectionListener(listSelectionListener);
  }
}
 
Example 5
Source File: ProfilerTable.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setSelectionModel(ListSelectionModel newModel) {
    ListSelectionModel oldModel = getSelectionModel();
    if (oldModel != null && selectionListener != null)
        oldModel.removeListSelectionListener(selectionListener);
    
    super.setSelectionModel(newModel);
    
    if (newModel != null) {
        if (selectionListener == null) selectionListener = new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) { if (!internal) saveSelection(); }
        };
        newModel.addListSelectionListener(selectionListener);
    }
}
 
Example 6
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initComponents()
{
	setTitle(LanguageBundle.getString("in_companionSelectRace")); //$NON-NLS-1$
	setLayout(new BorderLayout());
	Container container = getContentPane();
	{
		final ListSelectionModel selectionModel = raceTable.getSelectionModel();
		selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		selectionModel.addListSelectionListener(e -> {
                  if (!e.getValueIsAdjusting())
                  {
                      selectButton.setEnabled(!selectionModel.isSelectionEmpty());
                  }
              });
	}
	SearchFilterPanel searchBar = new SearchFilterPanel();
	container.add(searchBar, BorderLayout.NORTH);
	raceTable.setDisplayableFilter(searchBar);
	raceTable.addActionListener(this);
	raceTable.setTreeViewModel(this);
	container.add(new JScrollPane(raceTable), BorderLayout.CENTER);
	JPanel buttonPane = new JPanel(new FlowLayout());
	selectButton.addActionListener(this);
	selectButton.setEnabled(false);
	selectButton.setActionCommand("SELECT");
	buttonPane.add(selectButton);

	JButton cancelButton = new JButton(LanguageBundle.getString("in_cancel"));
	cancelButton.addActionListener(this);
	cancelButton.setActionCommand("CANCEL");
	buttonPane.add(cancelButton);
	container.add(buttonPane, BorderLayout.SOUTH);

	Utility.installEscapeCloseOperation(this);
}
 
Example 7
Source File: GroupEditorPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
private void jDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteButtonActionPerformed
   //jAllGroupsList.r
   ListSelectionModel lsm = jAllGroupsList.getSelectionModel();
   if (lsm.isSelectionEmpty())
      return;
   int minIndex=lsm.getMinSelectionIndex();
   int maxIndex=lsm.getMaxSelectionIndex();
   //remove listeners temporarily
   lsm.removeListSelectionListener(this);
   for(int i=minIndex; i<=maxIndex; i++){
      if (lsm.isSelectedIndex(i)){
         Object obj=jAllGroupsList.getModel().getElementAt(i);
         if (obj instanceof ObjectGroup){
            ObjectGroup groupToDelete = (ObjectGroup) obj;
            // Find an alternate group and make it current
            if (jAllGroupsList.getModel().getSize()==1){
               throw new UnsupportedOperationException("Not yet implemented");
            }
            else {
               currentGroup=(ObjectGroup) jAllGroupsList.getModel().getElementAt(0);
               dSet.removeGroup(groupToDelete.getName());
            }
            
         }
      }
   }
   updateGroupsList();
   // Restore listeners
   lsm.addListSelectionListener(this);

}
 
Example 8
Source File: DetailPanel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new <code>DetailPanel</code> instance.
 *
 * @param aTable the table to listen for selections on
 * @param aModel the model backing the table
 */
DetailPanel(JTable aTable, final MyTableModel aModel) {
    mModel = aModel;
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder("Details: "));

    mDetails = new JEditorPane();
    mDetails.setEditable(false);
    mDetails.setContentType("text/html");
    add(new JScrollPane(mDetails), BorderLayout.CENTER);

    final ListSelectionModel rowSM = aTable.getSelectionModel();
    rowSM.addListSelectionListener(this);
}
 
Example 9
Source File: ListComboBoxModel.java    From blog with Apache License 2.0 5 votes vote down vote up
public void setListSelectionModel(ListSelectionModel listSelectionModel) {
	if (this.listSelectionModel != null) {
		this.listSelectionModel
				.removeListSelectionListener(listSelectionUpdater);
	}
	this.listSelectionModel = listSelectionModel;
	if (listSelectionModel != null) {
		listSelectionModel.addListSelectionListener(listSelectionUpdater);
	}
}
 
Example 10
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 11
Source File: ListModelSelection.java    From blog with Apache License 2.0 5 votes vote down vote up
public void setListModels(ListAdapterListModel<E> listAdapterListModel,
		ListSelectionModel listSelectionModel) {
	this.listAdapterListModel = listAdapterListModel;
	if (this.listSelectionModel != null) {
		this.listSelectionModel
				.removeListSelectionListener(listSelectionAdapter);
	}
	this.listSelectionModel = listSelectionModel;
	if (listSelectionModel != null) {
		listSelectionModel.addListSelectionListener(listSelectionAdapter);
	}
}
 
Example 12
Source File: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public TubeTable(boolean client) {
    super();
    this.client = client;

    JTableHeader header = getTableHeader();
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);

    ListSelectionModel model = getSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    model.addListSelectionListener(new TubeListSelectionListener(client));
}
 
Example 13
Source File: MessageHandlerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HandlerTable() {
    JTableHeader header = getTableHeader();
    header.setResizingAllowed(false);
    header.setReorderingAllowed(false);
    ListSelectionModel model = getSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    model.addListSelectionListener(new HandlerListSelectionListener());
}
 
Example 14
Source File: ClassMethodSelector.java    From netbeans with Apache License 2.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 15
Source File: StyleMapTable.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new style map table.
 *
 * @param model the model
 * @param av the av
 * @param edit the edit
 * @param tmed the tmed
 */
public StyleMapTable(TableModel model, AnnotationFeaturesViewer av, StyleMapEditor edit,
        TableGUIMediator tmed) {
  super(model);
  med = tmed;
  setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  setDropTarget(new DropTarget(this, new TableDropAdapter(av, edit)));

  getTableHeader().setReorderingAllowed(false);
  ListSelectionModel lsm = this.getSelectionModel();
  lsm.addListSelectionListener(new TableSelectionListener(med));
}
 
Example 16
Source File: RowHeaderRenderer1.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param refTable Reference table
 * @param tableShow Show table
 */
public RowHeaderRenderer1(JTable refTable, JTable tableShow) {
    this._refTable = refTable;
    this._tableShow = tableShow;
    ListSelectionModel listModel = _refTable.getSelectionModel();
    listModel.addListSelectionListener(this);
}
 
Example 17
Source File: JLogTable.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public JLogTable(LogTableModel   model, 
	   JLogEntryDetail logEntryDetail,
	   boolean         bSort) {
   super();
   
   this.logEntryDetail = logEntryDetail;
   this.model          = model;

   setModel(model);

   setDefaultRenderer(Date.class, 
	       new DateCellRenderer("HH:mm:ss, MMM dd"));
   
   setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

   ListSelectionModel rowSM = getSelectionModel();

   rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {

  if (e.getValueIsAdjusting()) {
    return;
  }

  ListSelectionModel lsm = (ListSelectionModel)e.getSource();

  if (lsm.isSelectionEmpty()) {
    //
  } else {	    
           int ix = lsm.getMinSelectionIndex();

    ExtLogEntry entry = JLogTable.this.model.getEntry(ix);

    if(entry != null) {
      JLogTable.this.logEntryDetail.setParentAndEntry(JLogTable.this, entry);
    }
    
  }
}
     });

   getColumnModel().getColumn(LogTableModel.COL_ID).setPreferredWidth(30);
   getColumnModel().getColumn(LogTableModel.COL_BID).setPreferredWidth(30);
   getColumnModel().getColumn(LogTableModel.COL_LEVEL).setPreferredWidth(40);
   getColumnModel().getColumn(LogTableModel.COL_MESSAGE).setPreferredWidth(150);    
 }
 
Example 18
Source File: JEventTable.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public JEventTable(
                    EventTableModel   model, 
                    JEventEntryDetail logEntryDetail,
                    boolean         bSort) {
   super();
   
   this.logEntryDetail = logEntryDetail;
   this.model          = model;

	TableSorter sorter = new TableSorter(model);

	setModel(sorter);
	sorter.addMouseListenerToHeaderInTable(this);
   
   setDefaultRenderer(Date.class,   new DateCellRenderer("HH:mm:ss, MMM dd"));
   setDefaultRenderer(String.class, new StringCellRenderer());
   // setDefaultRenderer(Object.class, new StringCellRenderer());
   
   setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

   ListSelectionModel rowSM = getSelectionModel();

   rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {

  if (e.getValueIsAdjusting()) {
    return;
  }

  ListSelectionModel lsm = (ListSelectionModel)e.getSource();

  if (lsm.isSelectionEmpty()) {
    //
  } else {	    
           int ix = lsm.getMinSelectionIndex();

    Event entry = JEventTable.this.model.getEntry(ix);

    if(entry != null) {
      JEventTable.this.logEntryDetail.setParentAndEntry(JEventTable.this, entry);
    }
    
  }
}
     });

   /*
   getColumnModel().getColumn(EventTableModel.COL_TIME).setPreferredWidth(100);
   getColumnModel().getColumn(EventTableModel.COL_TOPIC).setPreferredWidth(170);
   getColumnModel().getColumn(EventTableModel.COL_BUNDLE).setPreferredWidth(80);    
   */
 }
 
Example 19
Source File: HexView.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public HexView() {
    super(new HexViewTableModel(bytesInRow));
    highlightColors = new Color[highlightColorsStr.length];
    for (int i = 0; i < highlightColors.length; i++) {
        highlightColors[i] = Color.decode("#" + highlightColorsStr[i]);
    }

    setBackground(Color.white);
    setFont(new Font("Monospaced", Font.PLAIN, 12));
    setTableHeader(new JTableHeader());
    setMaximumSize(new Dimension(200, 200));

    setShowHorizontalLines(false);
    setShowVerticalLines(false);
    setRowSelectionAllowed(false);
    setColumnSelectionAllowed(false);

    HighlightCellRenderer cellRenderer = new HighlightCellRenderer();
    TableColumn column = columnModel.getColumn(0);
    column.setMaxWidth(80);
    for (int i = 0; i < bytesInRow; i++) {
        column = columnModel.getColumn(i + 1);
        column.setMaxWidth(25);
        column.setCellRenderer(cellRenderer);
    }

    column = columnModel.getColumn(bytesInRow + 1);
    column.setMaxWidth(10);

    for (int i = 0; i < bytesInRow; i++) {
        column = columnModel.getColumn(i + bytesInRow + 1 + 1);
        column.setMaxWidth(10);
        column.setCellRenderer(cellRenderer);
    }

    addMouseListener(new HexViewMouseAdapter());
    addMouseMotionListener(new HexViewMouseMotionAdapter());
    ListSelectionModel rowSelModel = getSelectionModel();
    ListSelectionModel colSelModel = getColumnModel().getSelectionModel();
    ListSelectionListener selectionListener = new HexViewSelectionListener(this);
    rowSelModel.addListSelectionListener(selectionListener);
    colSelModel.addListSelectionListener(selectionListener);
}
 
Example 20
Source File: SkillInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public FilterHandler(CharacterFacade character, ListSelectionModel model)
{
	this.character = character;
	this.model = model;
	model.addListSelectionListener(this);
}