Java Code Examples for javax.swing.event.ListSelectionEvent

The following examples show how to use javax.swing.event.ListSelectionEvent. These examples are extracted from open source projects. 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 Project: pcgen   Source File: ChooserDialog.java    License: 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 2
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 3
Source Project: consulo   Source File: FileTemplateTabAsList.java    License: 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 Project: CodenameOne   Source File: ThemeEditor.java    License: 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 5
Source Project: opensim-gui   Source File: GroupEditorPanel.java    License: 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 6
Source Project: pcgen   Source File: ClassInfoTab.java    License: 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 7
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 8
Source Project: algorithms-nutshell-2ed   Source File: StateModifier.java    License: 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 9
/**
 * 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 10
Source Project: consulo   Source File: VcsConfigurationsDialog.java    License: 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 11
Source Project: blog   Source File: ListSelectionDocument.java    License: 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 12
Source Project: megamek   Source File: MechGroupView.java    License: 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 13
@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 14
/** Creates the UI. */
private void createUI() {
    setLayout(new BorderLayout());

    JScrollPane scrollPane = new JScrollPane();
    add(scrollPane, BorderLayout.CENTER);

    vendorOptionTable = new JTable();
    scrollPane.setViewportView(vendorOptionTable);
    vendorOptionTable.setModel(model);
    vendorOptionTable
            .getColumnModel()
            .getColumn(0)
            .setCellRenderer(new VendorOptionInfoCellRenderer(model));
    vendorOptionTable
            .getColumnModel()
            .getColumn(1)
            .setCellRenderer(new VendorOptionInfoCellRenderer(model));
    vendorOptionTable
            .getSelectionModel()
            .addListSelectionListener(
                    new ListSelectionListener() {

                        @Override
                        public void valueChanged(ListSelectionEvent e) {
                            displayDescription(vendorOptionTable.getSelectedRow());
                        }
                    });

    descriptionArea = new JTextArea();
    descriptionArea.setEditable(false);
    descriptionArea.setRows(5);
    descriptionArea.setLineWrap(true);
    descriptionArea.setWrapStyleWord(true);
    descriptionArea.setFont(vendorOptionTable.getFont());
    JScrollPane descriptionAreaScrollPane = new JScrollPane(descriptionArea);
    add(descriptionAreaScrollPane, BorderLayout.EAST);
    descriptionAreaScrollPane.setPreferredSize(new Dimension(200, 100));
}
 
Example 15
Source Project: jeveassets   Source File: MenuManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void valueChanged(final ListSelectionEvent e) {
	if (!e.getValueIsAdjusting()) {
		if (selectedColumns == null || selectedRows == null || !Arrays.equals(selectedColumns, jTable.getSelectedColumns()) || !Arrays.equals(selectedRows, jTable.getSelectedRows())) {
			selectedColumns = jTable.getSelectedColumns();
			selectedRows = jTable.getSelectedRows();
			updateMainTableMenu();
		}
	}
}
 
Example 16
Source Project: netbeans   Source File: KeymapPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
    super.valueChanged(e);
    if (!e.getValueIsAdjusting()) {
        int index = getSelectedRow();
        selectedActionId = getActionId(index);
    }
}
 
Example 17
Source Project: attic-polygene-java   Source File: DependencyPane.java    License: Apache License 2.0 5 votes vote down vote up
private void fieldListValueChanged( ListSelectionEvent evt )
{
    if( evt.getValueIsAdjusting() )
    {
        return;
    }

    reloadDetail( (InjectedFieldDetailDescriptor) fieldList.getSelectedValue() );
}
 
Example 18
/**
 * @see ListSelectionListener *
 */
public final void valueChanged(final ListSelectionEvent aEvent) {
   //Ignore extra messages.
   if (aEvent.getValueIsAdjusting()) {
      return;
   }

   final ListSelectionModel lsm = (ListSelectionModel) aEvent.getSource();
   if (lsm.isSelectionEmpty()) {
      mDetails.setText("Nothing selected");
   } else {
      final int selectedRow = lsm.getMinSelectionIndex();
      final EventDetails e = mModel.getEventDetails(selectedRow);
      final Object[] args =
              {
                      new Date(e.getTimeStamp()),
                      e.getPriority(),
                      escape(e.getThreadName()),
                      escape(e.getNDC()),
                      escape(e.getCategoryName()),
                      escape(e.getLocationDetails()),
                      escape(e.getMessage()),
                      escape(getThrowableStrRep(e))
              };
      final MessageFormat messageFormat = new MessageFormat(
              "<b>Time:</b> <code>{0,time,medium}</code>" +
                      "&nbsp;&nbsp;<b>Priority:</b> <code>{1}</code>" +
                      "&nbsp;&nbsp;<b>Thread:</b> <code>{2}</code>" +
                      "&nbsp;&nbsp;<b>NDC:</b> <code>{3}</code>" +
                      "<br><b>Logger:</b> <code>{4}</code>" +
                      "<br><b>Location:</b> <code>{5}</code>" +
                      "<br><b>Message:</b>" +
                      "<pre>{6}</pre>" +
                      "<b>Throwable:</b>" +
                      "<pre>{7}</pre>");
      mDetails.setText(messageFormat.format(args));
      mDetails.setCaretPosition(0);
   }
}
 
Example 19
/**
 * Maps {@code JTableHeader.columnSelectionChanged(ListSelectionEvent)}
 * through queue
 */
public void columnSelectionChanged(final ListSelectionEvent listSelectionEvent) {
    runMapping(new MapVoidAction("columnSelectionChanged") {
        @Override
        public void map() {
            ((JTableHeader) getSource()).columnSelectionChanged(listSelectionEvent);
        }
    });
}
 
Example 20
Source Project: netbeans   Source File: NetworkMonitorTopComponent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the request table.
 */
private void initRequestTable() {
    requestTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    requestTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            selectedItemChanged();
        }
    });
}
 
Example 21
public DomainEditor(Model aModel, Component aParent) {
    super(aParent, ERDesignerBundle.DOMAINEDITOR);
    initialize();

    DefaultComboBoxModel theDataTypes = editingView.getDataTypesModel();
    for (DataType theType : aModel.getDomainDataTypes()) {
        theDataTypes.addElement(theType);
    }

    DomainTableModel theModel = editingView.getDomainTableModel();
    for (Domain theDomain : aModel.getDomains()) {
        theModel.add(theDomain.clone());
    }

    model = aModel;
    domainEditor = new ModelItemNameCellEditor<>(model.getDialect());
    editingView.getDomainTable().getColumnModel().getColumn(0).setCellRenderer(ModelItemDefaultCellRenderer.getInstance());
    editingView.getDomainTable().getColumnModel().getColumn(0).setCellEditor(domainEditor);
    editingView.getDomainTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateDomainEditFields();
        }
    });

    updateDomainEditFields();

    UIInitializer.getInstance().initialize(this);
}
 
Example 22
/** @see ListSelectionListener **/
public void valueChanged(ListSelectionEvent aEvent) {
    //Ignore extra messages.
    if (aEvent.getValueIsAdjusting()) {
        return;
    }

    final ListSelectionModel lsm = (ListSelectionModel) aEvent.getSource();
    if (lsm.isSelectionEmpty()) {
        mDetails.setText("Nothing selected");
    } else {
        final int selectedRow = lsm.getMinSelectionIndex();
        final EventDetails e = mModel.getEventDetails(selectedRow);
        final Object[] args =
        {
            new Date(e.getTimeStamp()),
            e.getPriority(),
            escape(e.getThreadName()),
            escape(e.getNDC()),
            escape(e.getCategoryName()),
            escape(e.getLocationDetails()),
            escape(e.getMessage()),
            escape(getThrowableStrRep(e))
        };
        mDetails.setText(FORMATTER.format(args));
        mDetails.setCaretPosition(0);
    }
}
 
Example 23
Source Project: netbeans   Source File: OptionsPanel.java    License: Apache License 2.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
    optionsTable.editCellAt(optionsTable.getSelectedRow(), optionsTable.getSelectedColumn());
    Component editor = optionsTable.getEditorComponent();

    if (editor != null) {
        editor.requestFocus();
    }
    if (editor instanceof JTextComponent) {
        JTextComponent textComp = (JTextComponent) editor;
        textComp.selectAll();
    }
    updateButtons();
}
 
Example 24
Source Project: btdex   Source File: AccountsPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	if (e.getValueIsAdjusting())
		return;
	int row = table.getSelectedRow();
	removeButton.setEnabled(row >= 0);
	
	if(row >= 0) {
		rightButtonPane.setVisible(false);
		right.setVisible(true);
		marketComboBox.setEnabled(false);
		nameField.setEditable(false);
		
		// show this account properties
		MarketAccount ac = Globals.getInstance().getMarketAccounts().get(row);
		
		for (int i = 0; i < marketComboBox.getItemCount(); i++) {
			if(ac.getMarket().equals(marketComboBox.getItemAt(i).toString())) {
				marketComboBox.setSelectedIndex(i);
				break;
			}
		}
		nameField.setText(ac.getName());
		
		createFields(ac.getFields(), false);
	}
}
 
Example 25
Source Project: openjdk-jdk9   Source File: JTableOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTable.columnSelectionChanged(ListSelectionEvent)}
 * through queue
 */
public void columnSelectionChanged(final ListSelectionEvent listSelectionEvent) {
    runMapping(new MapVoidAction("columnSelectionChanged") {
        @Override
        public void map() {
            ((JTable) getSource()).columnSelectionChanged(listSelectionEvent);
        }
    });
}
 
Example 26
Source Project: NBANDROID-V2   Source File: AndroidPlatformCustomizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        AndroidPlatformInfo.PathRecord selectedValue1 = (AndroidPlatformInfo.PathRecord) sourcesList.getSelectedValue();
        removeSources.setEnabled(selectedValue1 == null ? false : selectedValue1.isUserRecord());
    }
}
 
Example 27
Source Project: pcgen   Source File: ClassInfoTab.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e)
{
	if (!e.getValueIsAdjusting())
	{
		selectedClass = getSelectedClass(e.getSource());
		if (selectedClass == null)
		{
			setEnabled(false);
		}
		setEnabled(selectedClass != null);
	}
}
 
Example 28
public MyTreeTableSelectionModel() {
    super();

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

        }
    });
}
 
Example 29
Source Project: pgptool   Source File: MainFrameView.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	if (e.getValueIsAdjusting() || !isAttached()) {
		return;
	}

	DecryptedFile selectedRow = getSelectedRow();
	if (selectedRow == null) {
		table.clearSelection();
	}
	pm.getSelectedRow().setValue(selectedRow);
}
 
Example 30
Source Project: ghidra   Source File: GhidraTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void valueChanged(ListSelectionEvent e) {
	if (e.getValueIsAdjusting()) {
		return;
	}

	if (getSelectedRowCount() != 1) {
		return;
	}

	int column = Math.max(0, getSelectedColumn());
	navigateOnCurrentSelection(getSelectedRow(), column);
}