Java Code Examples for javax.swing.JList#setSelectedIndices()

The following examples show how to use javax.swing.JList#setSelectedIndices() . 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: SuitePropertiesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRemoveAllSubModules() throws Exception {
    SuiteProject suite1 = generateSuite("suite1");
    TestBase.generateSuiteComponent(suite1, "module1a");
    TestBase.generateSuiteComponent(suite1, "module1b");
    SuiteProperties suite1Props = getSuiteProperties(suite1);
    
    SuiteSubModulesListModel model = suite1Props.getModulesListModel();
    assertNotNull(model);
    
    // simulate removing all items from the list
    JList moduleList = new JList(model);
    moduleList.setSelectedIndices(new int[] {0, model.getSize() - 1});
    model.removeModules(Arrays.asList(moduleList.getSelectedValues()));
    assertEquals("no subModule should be left", 0, model.getSize());
    
    saveProperties(suite1Props);
    
    SubprojectProvider spp = getSubProjectProvider(suite1);
    assertEquals("no module should be left", 0, spp.getSubprojects().size());
}
 
Example 2
Source File: Utility.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of all the objects in the given JList.
 */
public static String[] getList(Object[] size, JList objects) {
	String[] list;
	if (size.length == 0) {
		list = new String[0];
	}
	else {
		int[] select = new int[size.length];
		for (int i = 0; i < size.length; i++) {
			select[i] = i;
		}
		objects.setSelectedIndices(select);
		size = objects.getSelectedValues();
		list = new String[size.length];
		for (int i = 0; i < size.length; i++) {
			list[i] = (String) size[i];
		}
	}
	return list;
}
 
Example 3
Source File: WebSocketUiHelper.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public void setSelectedOpcodes(List<String> opcodes) {
    JList<String> opcodesList = getOpcodeList();
    if (opcodes == null || opcodes.contains(SELECT_ALL_OPCODES)) {
        opcodesList.setSelectedIndex(0);
    } else {
        int j = 0;
        int[] selectedIndices = new int[opcodes.size()];
        ListModel<String> model = opcodesList.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            String item = model.getElementAt(i);
            if (opcodes.contains(item)) {
                selectedIndices[j++] = i;
            }
        }
        opcodesList.setSelectedIndices(selectedIndices);
    }
}
 
Example 4
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 5
Source File: OperatorUIUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static void setSelectedListIndices(final JList list, final List<Integer> indices) {
    final int[] selIndex = new int[indices.size()];
    for (int i = 0; i < indices.size(); ++i) {
        selIndex[i] = indices.get(i);
    }
    list.setSelectedIndices(selIndex);
}
 
Example 6
Source File: UniqueKeyUI.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Generates the options/controls to prompt the user for unique key details
 *
 * @return
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Option> getOptions() {
	LinkedList<Option> opts = new LinkedList<>();

	opts.add(new Option("Unique key name:", _keyNameField = JUtils.textField("")));

	if (_uniqueKey != null) {
		_keyNameField.setText(_uniqueKey.getKeyName());
	}

	// Add the attributes box (only if there are attributes)
	EntityAttribute[] atts = _entity.getEntityAttributes().toArray(new EntityAttribute[0]);

	_attListField = new JList(atts);

	if (atts.length > 0) {
		opts.add(new Option("Unique key attributes:", JUtils.fixHeight(new JScrollPane(_attListField))));
	}

	// Add the outgoing edges box (only if there are outgoing edges)
	UniqueIndexable[] edges = _entity.getIndexableEdges().toArray(new UniqueIndexable[0]);

	_edgeListField = new JList(edges);

	if (edges.length > 0) {
		opts.add(new Option("Unique key edges:", JUtils.fixHeight(new JScrollPane(_edgeListField))));
	}

	if (_uniqueKey != null) {
		Set<UniqueIndexable> elems = _uniqueKey.getElements();
		ArrayList<Integer> setAtt = new ArrayList<>();
		ArrayList<Integer> setEdges = new ArrayList<>();

		for (int i = 0; i < atts.length; i++) {
			if (elems.contains(atts[i])) {
				setAtt.add(i);
			}
		}

		for (int i = 0; i < edges.length; i++) {
			if (elems.contains(edges[i])) {
				setEdges.add(i);
			}
		}

		int[] setA = new int[setAtt.size()];
		int[] setE = new int[setEdges.size()];

		for (int i = 0; i < setAtt.size(); i++) {
			setA[i] = setAtt.get(i);
		}

		for (int i = 0; i < setEdges.size(); i++) {
			setE[i] = setEdges.get(i);
		}

		_attListField.setSelectedIndices(setA);
		_edgeListField.setSelectedIndices(setE);
	}

	return opts;
}
 
Example 7
Source File: ShowcaseIconDemo.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	JList<?> list = (JList<?>) e.getSource();
	list.setSelectedIndices(new int[] {});
}
 
Example 8
Source File: PerformanceVectorViewer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public PerformanceVectorViewer(final PerformanceVector performanceVector, final IOContainer container) {
	setLayout(new BorderLayout());

	// all criteria
	final CardLayout cardLayout = new CardLayout();
	final JPanel mainPanel = new JPanel(cardLayout);
	add(mainPanel, BorderLayout.CENTER);
	List<String> criteriaNameList = new LinkedList<>();
	for (int i = 0; i < performanceVector.getSize(); i++) {
		PerformanceCriterion criterion = performanceVector.getCriterion(i);
		criteriaNameList.add(criterion.getName());
		JPanel component = ResultDisplayTools.createVisualizationComponent(criterion, container,
				"Performance Criterion", false);
		JScrollPane criterionPane = new ExtendedJScrollPane(component);
		criterionPane.setBorder(null);
		criterionPane.setBackground(Colors.WHITE);
		mainPanel.add(criterionPane, criterion.getName());
	}
	if (criteriaNameList.isEmpty()) {
		remove(mainPanel);
		add(new ResourceLabel("result_view.no_criterions"));
		return;
	}
	String[] criteriaNames = new String[criteriaNameList.size()];
	criteriaNameList.toArray(criteriaNames);

	// selection list
	final JList<String> criteriaList = new MenuShortcutJList<String>(criteriaNames, false) {

		private static final long serialVersionUID = 3031125186920370793L;

		@Override
		public Dimension getPreferredSize() {
			Dimension dim = super.getPreferredSize();
			dim.width = Math.max(150, dim.width);
			return dim;
		}
	};
	criteriaList.setCellRenderer(new CriterionListCellRenderer());
	criteriaList.setOpaque(false);

	criteriaList.setBorder(BorderFactory.createTitledBorder("Criterion"));
	criteriaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	criteriaList.addListSelectionListener(new ListSelectionListener() {

		@Override
		public void valueChanged(ListSelectionEvent e) {
			String selected = criteriaList.getSelectedValue();
			cardLayout.show(mainPanel, selected);
		}
	});

	JScrollPane listScrollPane = new ExtendedJScrollPane(criteriaList);
	listScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 2));
	add(listScrollPane, BorderLayout.WEST);

	// select first criterion
	criteriaList.setSelectedIndices(new int[] { 0 });
}
 
Example 9
Source File: DataTable.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
void setColumns(String[] names, String[] selected) {
  displayedNames = new String[names.length];
  realNames.clear();
	for (int i=0; i<names.length; i++) {
    String s = TeXParser.removeSubscripting(names[i]);
		// add white space for better look
		displayedNames[i] = "   "+s+" "; //$NON-NLS-1$ //$NON-NLS-2$
		realNames.put(displayedNames[i], names[i]);
  	if (selected!=null) {
   	for (int j=0; j<selected.length; j++) {
   		if (selected[j]!=null && selected[j].equals(names[i])) {
   			selected[j] = displayedNames[i];
   		}
   	}
  	}
	}
  prevPatterns.clear();
  for(String name : names) {
    prevPatterns.put(name, getFormatPattern(name));
  }
  // create column list and add to scroller
  columnList = new JList(displayedNames);
  columnList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  columnList.setVisibleRowCount(-1);
  columnList.addListSelectionListener(new ListSelectionListener() {
  	public void valueChanged(ListSelectionEvent e) {
  		showNumberFormatAndSample(columnList.getSelectedIndices());
  	}
  });
  columnScroller.setViewportView(columnList);
  pack();
  int[] indices = null;
  if (selected!=null) {
    // select requested names
    indices = new int[selected.length];
    for (int j=0; j<indices.length; j++) {
    	inner:
     for (int i = 0; i< displayedNames.length; i++) {
     	if (displayedNames[i].equals(selected[j])) {
     		indices[j] = i;
     		break inner;
     	}
     }
    }
  	columnList.setSelectedIndices(indices);
  }
  else
    showNumberFormatAndSample(indices);
}