javax.swing.ListModel Java Examples

The following examples show how to use javax.swing.ListModel. 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: UnitType.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getMaximumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
    ListModel<BuildableType> buildQueue = buildQueueList.getModel();
    final int buildQueueLastPos = buildQueue.getSize();

    boolean canBuild = false;
    if (colony.canBuild(this)) {
        canBuild = true;
    }

    // does not depend on anything, nothing depends on it
    // can be built at any time
    if (canBuild) return buildQueueLastPos;
    // check for building in queue that allows builting this unit
    for (int index = 0; index < buildQueue.getSize(); index++) {
        BuildableType toBuild = buildQueue.getElementAt(index);
        if (toBuild == this) continue;
        if (toBuild.hasAbility(Ability.BUILD, this)) {
            return buildQueueLastPos;
        }
    }
    return UNABLE_TO_BUILD;
}
 
Example #2
Source File: DisassembledViewPluginTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the plugins response to {@link ProgramSelectionPluginEvent}s.
 * 
 * @throws Exception If there is a problem opening the program.
 */
@Test
public void testProcessingOnSelectionChanged() throws Exception {
	openProgram("notepad");

	tool.showComponentProvider(componentProvider, true);
	waitForPostedSwingRunnables();

	// the Java component that is our display for the plugin
	JList list = (JList) getInstanceField("contentList", componentProvider);
	ListModel listContents = list.getModel();

	// make sure that nothing happens on a single-selection     
	plugin.processEvent(createProgramSelectionEvent(false));

	assertTrue("The list is not the same after processing a " + "single-selection event.",
		compareListData(listContents, list.getModel()));

	// make sure that the component display is cleared when there is a 
	// multiple-selection
	plugin.processEvent(createProgramSelectionEvent(true));

	assertTrue(
		"The list content did not change after processing a " + "multiple-selection event.",
		!compareListData(listContents, list.getModel()));
}
 
Example #3
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 #4
Source File: CProjectNodeComponent.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Because the checked list box can not yet deal with growing or shrinking models, the checked
 * list box is recreated by this function if necessary.
 */
private void updateCheckedListPanel() {
  m_checkedList.removeListSelectionListener(m_updateListener);
  m_checkedListPanel.removeAll();
  m_checkedList = new JCheckedListbox<>(getDebuggerVector(), false);
  m_checkedList.addListSelectionListener(m_updateListener);
  final JScrollPane debuggerScrollPane = new JScrollPane(m_checkedList);
  m_checkedListPanel.add(debuggerScrollPane);
  final Collection<DebuggerTemplate> debuggers = m_project.getConfiguration().getDebuggers();
  final ListModel<DebuggerTemplate> model = m_checkedList.getModel();
  for (int i = 0; i < model.getSize(); ++i) {
    final DebuggerTemplate debuggerId = model.getElementAt(i);
    m_checkedList.setChecked(i, debuggers.contains(debuggerId));
  }
  m_checkedList.updateUI();
  updateUI();
}
 
Example #5
Source File: JdbcDataSourceDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void setScriptingLanguage( final String lang, final JComboBox languageField ) {
  if ( lang == null ) {
    languageField.setSelectedItem( null );
    return;
  }

  final ListModel model = languageField.getModel();
  for ( int i = 0; i < model.getSize(); i++ ) {
    final ScriptEngineFactory elementAt = (ScriptEngineFactory) model.getElementAt( i );
    if ( elementAt == null ) {
      continue;
    }
    if ( elementAt.getNames().contains( lang ) ) {
      languageField.setSelectedItem( elementAt );
      return;
    }
  }
}
 
Example #6
Source File: WebSocketUiHelper.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public void setSelectedChannelIds(List<Integer> channelIds) {
    JList<WebSocketChannelDTO> channelsList = getChannelsList();
    if (channelIds == null || channelIds.contains(-1)) {
        channelsList.setSelectedIndex(0);
    } else {
        int[] selectedIndices = new int[channelIds.size()];
        ListModel<WebSocketChannelDTO> model = channelsList.getModel();
        for (int i = 0, j = 0; i < model.getSize(); i++) {
            WebSocketChannelDTO channel = model.getElementAt(i);
            if (channelIds.contains(channel.id)) {
                selectedIndices[j++] = i;
            }
        }
        channelsList.setSelectedIndices(selectedIndices);
    }
}
 
Example #7
Source File: CategoryPanelFormatters.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isChanged() {
    ListModel formattersModel = formattersList.getModel();
    VariablesFormatter[] formatters = new VariablesFormatter[formattersModel.getSize()];
    for (int i = 0; i < formatters.length; i++) {
        formatters[i] = (VariablesFormatter) formattersModel.getElementAt(i);
    }
    VariablesFormatter[] saved = VariablesFormatter.loadFormatters();
    if(saved == null) {
        return false;
    }
    if(saved.length != formatters.length) {
        return true;
    }
    for (int i = 0; i < saved.length; i++) {
        VariablesFormatter savedFormatter = saved[i];
        VariablesFormatter currentFormatter = (VariablesFormatter) formattersModel.getElementAt(i);
        if(!areVariablesFormattersEqual(savedFormatter, currentFormatter)) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: AnalysisView.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
public boolean reb2sacAbstraction()
{
  ListModel<String> preAbsList = preAbs.getModel();
  for (int i = 0; i < preAbsList.getSize(); i++)
  {
    String abstractionOption = (String) preAbsList.getElementAt(i);
    if (!abstractionOption.equals("complex-formation-and-sequestering-abstraction") && !abstractionOption.equals("operator-site-reduction-abstraction"))
    {
      return true;
    }
  }
  ListModel<String> loopAbsList = loopAbs.getModel();
  if (loopAbsList.getSize() > 0)
  {
    return true;
  }
  ListModel<String> postAbsList = postAbs.getModel();
  if (postAbsList.getSize() > 0)
  {
    return true;
  }
  return false;
}
 
Example #9
Source File: TableRowHeader.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
private void updatePrefferedWidth(int firstRow, int lastRow) {
    final ListModel model = getModel();
    final int l = model.getSize() - 1;
    if (lastRow > l)
        lastRow = l;
    if (firstRow < 0)
        firstRow = 0;
    int m = this.m;
    for (int i = firstRow; i <= lastRow; i++) {
        final Object obj = model.getElementAt(i);
        if (obj == null)
            continue;
        final Component c = renderer.getListCellRendererComponent(this,
                obj, i, true, true);
        final int t = c.getPreferredSize().width + 2;
        if (t > m)
            m = t;
    }
    if (m != getFixedCellWidth()) {
        setFixedCellWidth(m);
        revalidate();
    }
}
 
Example #10
Source File: GoToPanelImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Sets the model.
 * Threading: Requires EDT.
 * @param the model to set
 * @param finished true for final update
 * @return true if model has changed
 */
@Override
public boolean setModel(
        @NonNull final ListModel model,
        final boolean finished) {
    assert SwingUtilities.isEventDispatchThread();
    matchesList.setModel(model);
    if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) {
        matchesList.setSelectedIndex(0);
        setListPanelContent(null,false);
        if ( time != -1 ) {
            GoToSymbolAction.LOGGER.log(
                    Level.FINE,
                    "Real search time {0} ms.",    //NOI18N
                    (System.currentTimeMillis() - time));
            time = -1;
        }
        return true;
    } else if (finished) {
        setListPanelContent(NbBundle.getMessage(GoToPanelImpl.class, "TXT_NoSymbolsFound") ,false );
        return false;
    } else {
        return false;
    }
}
 
Example #11
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
/**
 * Paint one List cell: compute the relevant state, get the "rubber stamp"
 * cell renderer component, and then use the CellRendererPane to paint it.
 * Subclasses may want to override this method rather than paint().
 *
 * @see #paint
 */
protected void paintCell(
	   Graphics g,
	   int row,
	   Rectangle rowBounds,
	   ListCellRenderer cellRenderer,
	   ListModel dataModel,
	   ListSelectionModel selModel,
	   int leadIndex)
{
  Object value = dataModel.getElementAt(row);
  boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
  boolean isSelected = selModel.isSelectedIndex(row);

  Component rendererComponent =
    cellRenderer.getListCellRendererComponent(list, value, row, isSelected, cellHasFocus);

  int cx = rowBounds.x;
  int cy = rowBounds.y;
  int cw = rowBounds.width;
  int ch = rowBounds.height;
  rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
}
 
Example #12
Source File: QueryLibraryPanel.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
public void saveClicked(){
    String name=nameField.getText().trim();
    if(name.length()==0){
        WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Name is empty.");
        return;
    }
    else {
        ListModel listModel=queryList.getModel();
        for(int i=0;i<listModel.getSize();i++){
            Object o=listModel.getElementAt(i);
            if(name.equals(o)){
                if(openedName==null || !openedName.equals(name)){
                    // TODO: confirm overwrite
                }
                break;
            }
        }
    }
    
    openedName=name;
    
    save(name);
}
 
Example #13
Source File: PmdDataSourceEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void setScriptingLanguage( final String lang, final JComboBox languageField ) {
  if ( lang == null ) {
    languageField.setSelectedItem( null );
    return;
  }

  final ListModel model = languageField.getModel();
  for ( int i = 0; i < model.getSize(); i++ ) {
    final ScriptEngineFactory elementAt = (ScriptEngineFactory) model.getElementAt( i );
    if ( elementAt == null ) {
      continue;
    }
    if ( elementAt.getNames().contains( lang ) ) {
      languageField.setSelectedItem( elementAt );
      return;
    }
  }
}
 
Example #14
Source File: TaskPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void reloadField (JComponent component, IssueField field) {
    String newValue;
    newValue = task.getFieldValue(field);
    boolean fieldDirty = unsavedFields.contains(field.getKey());
    if (!fieldDirty) {
        if (component instanceof JComboBox) {
            throw new UnsupportedOperationException();
        } else if (component instanceof JTextComponent) {
            ((JTextComponent) component).setText(newValue);
        } else if (component instanceof JList) {
            JList list = (JList) component;
            list.clearSelection();
            ListModel model = list.getModel();
            for (String value : task.getFieldValues(field)) {
                for (int i = 0; i < model.getSize(); i++) {
                    if (value.equals(model.getElementAt(i))) {
                        list.addSelectionInterval(i, i);
                    }
                }
            }
        } else if (component instanceof JCheckBox) {
            ((JCheckBox) component).setSelected("1".equals(newValue));
        }
    }
}
 
Example #15
Source File: PsychoPanel2.java    From psychoPATH with GNU General Public License v3.0 5 votes vote down vote up
private void breakupASCIIFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_breakupASCIIFormatActionPerformed

        if(editorFormat=="ASCII") return;
            
        breakupHexFormat.setSelected(false);
        breakupASCIIFormat.setSelected(true);
        
        editorFormat="ASCII";
                
        // now, we have to go through the list and convert each element
        //
        // also, in such case we want to make sure this toggle is only activated once
        // breakupList 
        // iterate and convert from hex to ascii
        // convert all from ASCII to HEX
        
        ListModel breakupListModel = breakupList.getModel();
        String newValues[] = new String[breakupListModel.getSize()];        
        for(int i=0;i<breakupListModel.getSize();i++)
        {
            String hex=breakupListModel.getElementAt(i).toString();
            StringBuilder output = new StringBuilder();
            for (int j = 0; j < hex.length(); j+=2) 
            {
                String str = hex.substring(j, j+2);
                output.append((char)Integer.parseInt(str, 16));
            }   
            newValues[i]=output.toString();
            // now, we convert it from ASCII to HEX
            //brutDocrootSuffixes.add(suffix);
        }                
        breakupList.setListData(newValues);          
        /*
        String hex;
  
        */
        
    }
 
Example #16
Source File: GoToFilePanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private void listFoundFilesMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listFoundFilesMouseMoved
  final ListModel model = this.listFoundFiles.getModel();
  final int index = this.listFoundFiles.locationToIndex(evt.getPoint());
  if (index < 0) {
    this.listFoundFiles.setToolTipText(null);
  } else {
    final File file = ((NodeFileOrFolder) model.getElementAt(index)).makeFileForNode();
    this.listFoundFiles.setToolTipText(file == null ? null : file.getAbsolutePath());
  }
}
 
Example #17
Source File: BreakpointNestedGroupsDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
String[] getDisplayedGroups() {
    ListModel model = displayedGroupsList.getModel();
    int n = model.getSize();
    String[] groupNames = new String[n];
    for (int i = 0; i < n; i++) {
        GroupElement ge = (GroupElement) model.getElementAt(i);
        groupNames[i] = ge.getGroup().name();
    }
    return groupNames;
}
 
Example #18
Source File: ActivitySequenceEditor.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public ListModel<Object> getTagList() {
  if (tagList == null) {
    tagList = new DefaultListModel<Object>();
    Enumeration en = children();
    while (en.hasMoreElements()) {
      ActivitySequenceElementEditor asee = (ActivitySequenceElementEditor) en.nextElement();
      String tag = StrUtils.nullableString(asee.getActivitySequenceElement().getTag());
      if (tag != null)
        tagList.addElement(tag);
    }
  }
  return tagList;
}
 
Example #19
Source File: FilteredListModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Factory method to create new filtering lazy model.
 */
@NonNull
static FilteredListModel create (
        @NonNull final ListModel listModel,
        @NonNull final Filter filter,
        @NullAllowed final Object defValue) {
    return new FilteredListModel(listModel, filter, defValue);
}
 
Example #20
Source File: ListComboBoxModel.java    From blog with Apache License 2.0 5 votes vote down vote up
public void setListModel(ListModel<E> listModel) {
	if (this.listModel != null) {
		this.listModel.removeListDataListener(listModelUpdater);
	}
	this.listModel = listModel;
	if (listModel != null) {
		listModel.removeListDataListener(listModelUpdater);
	}
}
 
Example #21
Source File: SourceSelectionDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initDefaults()
{
	final ListModel sortedModel = sourceList.getModel();
	String defaultSelectedSource = CONTEXT.initProperty(PROP_SELECTED_SOURCE, DEFAULT_SOURCE);
	int index = Collections.binarySearch(new AbstractList<Object>()
	{

		@Override
		public Object get(int idx)
		{
			return sortedModel.getElementAt(idx);
		}

		@Override
		public int size()
		{
			return sortedModel.getSize();
		}

	}, defaultSelectedSource, Comparators.toStringIgnoreCaseCollator());
	if (index >= 0)
	{
		sourceList.setSelectedIndex(index);
	}
	else if (sortedModel.getSize() > 0)
	{
		sourceList.setSelectedIndex(0);
	}
	sourceList.addListSelectionListener(this);
}
 
Example #22
Source File: SelectionList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setItems( ListModel<ListItem> items ) {
    ListItem selItem = theList.getSelectedValue();
    theList.setModel( items );
    if( null != selItem ) {
        setSelectedItem( selItem );
    }
}
 
Example #23
Source File: PathController.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void updateModel(String items) {
    if (items == null) {
        return;
    }
    ListModel m = l.getModel();
    if (m != null) {
        m.removeListDataListener(this);
    }

    model = createModel(items);
    model.addListDataListener(this);
    l.setModel(model);
}
 
Example #24
Source File: SymfonyGoToViewActionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ListModel<SymfonyViewItem> createListModel() {
    DefaultListModel<SymfonyViewItem> dlm = new DefaultListModel<>();

    for (FileObject view : views) {
        dlm.addElement(new SymfonyViewItem(view));
    }

    return dlm;
}
 
Example #25
Source File: ChooserTreeView.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public boolean isVisible(TreePath path) {
   Object node = path.getLastPathComponent();
   if(tree.isLeaf(node)) {
     ListModel model = content.getModel();
     for(int i = 0; i < model.getSize(); i++)
if(model.getElementAt(i).equals(node))
  return true;
     return false;
   } else
     return pathView.getPath().equals(path);
 }
 
Example #26
Source File: FontChooserPanel.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes the contents of the dialog from the given font
 * object.
 *
 * @param font the font from which to read the properties.
 */
public void setSelectedFont( Font font) {
    if (font == null) {
        throw new NullPointerException();
    }
    this.bold.setSelected(font.isBold());
    this.italic.setSelected(font.isItalic());

    String fontName = font.getName();
    ListModel model = this.fontlist.getModel();
    this.fontlist.clearSelection();
    for (int i = 0; i < model.getSize(); i++) {
        if (fontName.equals(model.getElementAt(i))) {
            this.fontlist.setSelectedIndex(i);
            break;
        }
    }

    String fontSize = String.valueOf(font.getSize());
    model = this.sizelist.getModel();
    this.sizelist.clearSelection();
    for (int i = 0; i < model.getSize(); i++) {
        if (fontSize.equals(model.getElementAt(i))) {
            this.sizelist.setSelectedIndex(i);
            break;
        }
    }
}
 
Example #27
Source File: SelectionList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to select the given item in this list.
 * @param item Item to select.
 * @return True if this list contains the given item, false otherwise.
 */
boolean setSelectedItem( ListItem item ) {
    ListModel<ListItem> model = theList.getModel();
    for( int i=0; i<model.getSize(); i++ ) {
        if( item.equals( model.getElementAt( i )  ) ) {
            theList.setSelectedIndex( i );
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: ListeningListSelectionModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void settingChanged(String generalKey, String specificKey, String value) {
	if (generalKey.equals(this.generalKey)) {
		ListModel<String> listModel = list.getModel();
		// searching indices of selected dimensions
		String names[] = ParameterTypeEnumeration.transformString2Enumeration(value);
		boolean[] selectedDimensions = new boolean[listModel.getSize()];
		for (int i = 0; i < names.length; i++) {
			String name = names[i].trim();
			for (int j = 0; j < listModel.getSize(); j++) {
				if (listModel.getElementAt(j).equals(name)) {
					selectedDimensions[j] = true;
					break;
				}
			}
		}

		// switching all differing dimensions
		setValueIsAdjusting(true);
		for (int i = 0; i < listModel.getSize(); i++) {
			if (selectedDimensions[i]) {
				addSelectionInterval(i, i);
			} else {
				removeSelectionInterval(i, i);
			}
		}
		setValueIsAdjusting(false);
	}

}
 
Example #29
Source File: ClasspathCustomEditorOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** returns complete class path from editor
 * @return String[] class paths */    
public String[] getClasspathValue() {
    ArrayList<String> data=new ArrayList<String>();
    ListModel model=lstClasspath().getModel();
    for (int i=0; i<model.getSize(); i++) {
        data.add(model.getElementAt(i).toString());
    }
    return data.toArray(new String[data.size()]);
}
 
Example #30
Source File: KeyBindings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public List listActions() {
    ListModel model = lstActions().getModel();
    List ret=new Vector();
    for (int i=0;i < model.getSize();i++) {
        ret.add(model.getElementAt(i));
    }
    return ret;
}