public void testCarLengths() { CarLengths cl1 = CarLengths.instance(); cl1.getNames(); // load predefined lengths Assert.assertTrue("Car Length Predefined 40", cl1.containsName("40")); Assert.assertTrue("Car Length Predefined 32", cl1.containsName("32")); Assert.assertTrue("Car Length Predefined 60", cl1.containsName("60")); cl1.addName("1"); Assert.assertTrue("Car Length Add 1", cl1.containsName("1")); Assert.assertFalse("Car Length Never Added 13", cl1.containsName("13")); cl1.addName("2"); Assert.assertTrue("Car Length Still Has 1", cl1.containsName("1")); Assert.assertTrue("Car Length Add s2", cl1.containsName("2")); String[] lengths = cl1.getNames(); Assert.assertEquals("First length name", "2", lengths[0]); Assert.assertEquals("2nd length name", "1", lengths[1]); JComboBox<?> box = cl1.getComboBox(); Assert.assertEquals("First comboBox length name", "2", box.getItemAt(0)); Assert.assertEquals("2nd comboBox length name", "1", box.getItemAt(1)); cl1.deleteName("2"); Assert.assertFalse("Car Length Delete 2", cl1.containsName("2")); cl1.deleteName("1"); Assert.assertFalse("Car Length Delete 1", cl1.containsName("1")); }
public void testCarTypes() { CarTypes ct1 = CarTypes.instance(); ct1.getNames(); // Load predefined car types Assert.assertTrue("Car Types Predefined Boxcar", ct1.containsName("Boxcar")); Assert.assertTrue("Car Types Predefined Caboose", ct1.containsName("Caboose")); ct1.addName("Type New1"); Assert.assertTrue("Car Types Add New1", ct1.containsName("Type New1")); Assert.assertFalse("Car Types Never Added New2", ct1.containsName("Type New2")); ct1.addName("Type New3"); Assert.assertTrue("Car Types Still Has New1", ct1.containsName("Type New1")); Assert.assertTrue("Car Types Add New3", ct1.containsName("Type New3")); ct1.replaceName("Type New3", "Type New4"); Assert.assertFalse("Car Types replace New3", ct1.containsName("Type New3")); Assert.assertTrue("Car Types replace New3 with New4", ct1.containsName("Type New4")); String[] types = ct1.getNames(); Assert.assertEquals("First type name", "Type New4", types[0]); Assert.assertEquals("2nd type name", "Type New1", types[1]); JComboBox<?> box = ct1.getComboBox(); Assert.assertEquals("First comboBox type name", "Type New4", box.getItemAt(0)); Assert.assertEquals("2nd comboBox type name", "Type New1", box.getItemAt(1)); ct1.deleteName("Type New4"); Assert.assertFalse("Car Types Delete New4", ct1.containsName("Type New4")); ct1.deleteName("Type New1"); Assert.assertFalse("Car Types Delete New1", ct1.containsName("Type New1")); }
public void selectDropDownStrategy(int index) { logger.debug("selectDropDownStrategy() index: " + index); if (getStrategiesList().size() != strategiesDropDown.getItemCount()) { return; } strategiesDropDown.setSelectedIndex(index); StrategyT tempStrategy = getStrategiesList().get(index); if (!strategiesDropDown .getItemAt(index) .equals(Atdl4jHelper.getStrategyUiRepOrName(tempStrategy))) { throw new IllegalStateException( "UNEXPECTED ERROR: strategiesDropDown.getItem(" + index + "): " + strategiesDropDown.getItemAt(index) + " DID NOT MATCH tempStrategy: " + Atdl4jHelper.getStrategyUiRepOrName(tempStrategy)); } fireStrategySelectedEvent(tempStrategy); }
/* ACTION PERFORMED */ private void consultActionPerformed(ActionEvent e) { /* Clean the previous solution (if any) */ cleanSolution(); setDefaultColor(); /* we can get Teams or Strings from the checkboxes */ Teams local = (Teams) localTeam.getItemAt(localTeam.getSelectedIndex()); Teams away = (Teams) awayTeam.getItemAt(awayTeam.getSelectedIndex()); int week = (Integer) this.week.getValue(); /* fill the array */ QueryCollector[] q = new QueryCollector[1]; q[0] = new QueryCollector(local, away, week); HoldOutEvaluator eval = new HoldOutEvaluator(); eval.init(recommender); /* call to the main method */ recommender.run(false, getSeason(), q); /* request the solution */ this.solution = recommender.getSimpleSolution(); paintSolution(); /* Enable <<details>> option */ itemDetails.setEnabled(true); details.setEnabled(true); }
private void selectOption(Object value) { for (int i = combo.getItemCount() - 1; i >= 0; i--) { PrefOption opt = (PrefOption) combo.getItemAt(i); if (opt.getValue().equals(value)) { combo.setSelectedItem(opt); return; } } combo.setSelectedItem(combo.getItemAt(0)); }
private Car getCarFromStorage(JComboBox<String> cars, JComboBox<EngineKind> engine) { String carName = cars.getItemAt(cars.getSelectedIndex()); Car car = null; for (Car carr : shop.getCars()) { if ((carr.getManufacturer() + " " + carr.getModel()).equals(carName) && carr.getEngineKind().equals(engine.getItemAt(engine.getSelectedIndex()))) { car = carr; } } return car; }
private LocationTrackPair getLocationTrackPair(int row) { Schedule s = sysList.get(row); JComboBox<LocationTrackPair> box = scheduleManager.getSpursByScheduleComboBox(s); String index = comboSelect.get(sysList.get(row)); LocationTrackPair ltp; if (index != null) { ltp = box.getItemAt(Integer.parseInt(index)); } else { ltp = box.getItemAt(0); } return ltp; }
protected Step createSelection(JComboBox combo, int index) { Step step = null; if (combo != null && index != -1) { ComponentReference cr = getResolver().addComponent(combo); String value = tester.getValueAsString(combo, list, combo.getItemAt(index), index); if (value == null) { step = new Action( getResolver(), null, "actionSelectIndex", new String[] {cr.getID(), String.valueOf(index)}, javax.swing.JComboBox.class); } else { step = new Action( getResolver(), null, "actionSelectItem", new String[] {cr.getID(), value}, javax.swing.JComboBox.class); } } return step; }
public String[] getItems() { String[] res = new String[choice.getItemCount()]; for (int i = 0; i < res.length; i++) { res[i] = (String) choice.getItemAt(i); } return res; }
public void afficherFilmChoisis(String titre) { Video film = this.obtenirVideo(titre); String catos = this.obtenirCategoriesEnString( comboCollection.getItemAt(comboCollection.getSelectedIndex()).toString()); if (mode[0].isSelected()) { String filmOuSerie = "SERIE TV"; String eval = ""; if (film.getEval() == 1) { eval = String.valueOf(film.getEval()) + " etoile"; } else if (film.getEval() > 1) { eval = String.valueOf(film.getEval()) + " etoiles"; } if (film.isFilm()) { filmOuSerie = "FILM"; } infos_film[0].setText(titre); infos_film[1].setText(String.valueOf(film.getAnnee())); infos_film[2].setText(filmOuSerie); infos_film[3].setText(eval); } else { textTitre.setText(film.getTitre()); textAnnee.setText(String.valueOf(film.getAnnee())); comboEval.setSelectedIndex(film.getEval()); boolean isFilm = film.isFilm(); if (isFilm) { comboType.setSelectedIndex(1); } else { comboType.setSelectedIndex(2); } } textCommentaires.setText(film.getCommentaires()); textCategories.setText(catos); }
private void handleEntryAction(ActionEvent actionEvent) throws IOException, ParserConfigurationException, XPathExpressionException, SAXException, NoItemException { if (this.getGazetteer() == null) { Util.getLogger().severe("No gazeteer is registered"); return; } String lookupString; JComboBox cmb = ((JComboBox) actionEvent.getSource()); lookupString = cmb.getSelectedItem().toString(); if (lookupString == null || lookupString.length() < 1) return; java.util.List<PointOfInterest> results = this.gazetteer.findPlaces(lookupString); if (results == null || results.size() == 0) return; this.controller.moveToLocation(results.get(0)); // Add it to the list if not already there for (int i = 0; i < cmb.getItemCount(); i++) { Object oi = cmb.getItemAt(i); if (oi != null && oi.toString().trim().equals(lookupString)) return; // item exists } cmb.insertItemAt(lookupString, 0); }
public SwingThreadFrame() { setTitle("SwingThreadTest"); final JComboBox combo = new JComboBox(); combo.insertItemAt(new Integer(Integer.MAX_VALUE), 0); combo.setPrototypeDisplayValue(combo.getItemAt(0)); combo.setSelectedIndex(0); JPanel panel = new JPanel(); JButton goodButton = new JButton("Good"); goodButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { new Thread(new GoodWorkerRunnable(combo)).start(); } }); panel.add(goodButton); JButton badButton = new JButton("Bad"); badButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { new Thread(new BadWorkerRunnable(combo)).start(); } }); panel.add(badButton); panel.add(combo); add(panel); pack(); }
/* * Metodo mostrarLibro() * sin parametros, sin retorno, muestra los datos del elemento del vector seleccionado */ private void mostrarLibro() { int seleccion = librosCombo.getSelectedIndex(); Libro l = (Libro) librosCombo.getItemAt(seleccion); tituloLibro.setText(l.getTituloLibro()); autorNombres.setText(l.getAutorNombres()); apellidosAutor.setText(l.getApellidosAutor()); nombreEditorial.setText(l.getNombreEditorial()); añoPublicacion.setText(String.valueOf(l.getAñoPublicacion())); codigoISBN.setText(l.getCodigoISBN()); lugarPublicacion.setText(l.getLugarPublicacion()); numeroPaginas.setText(String.valueOf(l.getNumeroPaginas())); descripcionArea.setText(l.getDescripcionLibro()); subgeneroCombo.setSelectedItem(l.getSubgeneroLibro()); // generoLiricoRadio.setSelected(true); // semestreSpinner.setValue(1);} if (l.getGenero() == 'N') { generoNarrativoRadio.setSelected(true); } else if (l.getGenero() == 'D') { generoDramaRadio.setSelected(true); } else { generoLiricoRadio.setSelected(true); } españolCheck.setSelected(l.isEspañolCheck()); inglesCheck.setSelected(l.isInglesCheck()); mandarinCheck.setSelected(l.isMandarinCheck()); }
public void setSelectedFile(String name) { for (int i = 0; i < cycleName.getItemCount(); i++) { if (cycleName.getItemAt(i).toString().equalsIgnoreCase(name)) { cycleName.setSelectedIndex(i); } } }
public DataSourceQueryChooserDialog( Collection dataSourceQueryChoosers, Frame frame, String title, boolean modal) { super(frame, title, modal); init(dataSourceQueryChoosers); try { jbInit(); pack(); } catch (Exception ex) { ex.printStackTrace(); } addComponentListener( new ComponentAdapter() { public void componentShown(ComponentEvent e) { okCancelPanel.setOKPressed(false); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { // User may have hit OK, got a validation-error dialog, then hit the // X button. [Jon Aquino] okCancelPanel.setOKPressed(false); } }); // Set the selected item to trigger the event that sets the panel. [Jon Aquino] formatComboBox.setSelectedItem(formatComboBox.getItemAt(0)); }
private int getIndexByCustomer(String customerCode) { for (int i = 0; i < txtCustomer.getItemCount(); i++) { if (txtCustomer.getItemAt(i).getKey().equals(customerCode)) { return i; } } return 0; }
public void setMidiOutDevice(MidiDevice.Info midiOutDeviceInfo) { int n = _midiOutComboBox.getItemCount(); for (int i = 0; i < n; i++) { if (((MidiDevice.Info) _midiOutComboBox.getItemAt(i)) == midiOutDeviceInfo) { _midiOutComboBox.setSelectedIndex(i); } } }
/** sets the class of the chosen result matrix. */ protected void setFormat() { for (int i = 0; i < m_OutputFormatClasses.size(); i++) { if (m_OutputFormatNames.get(i).equals(m_OutputFormatComboBox.getItemAt(i).toString())) { m_OutputFormatComboBox.setSelectedIndex(i); break; } } }
public static List getItems(JComboBox comboBox) { List result = new ArrayList(); for (int i = 0; i < comboBox.getItemCount(); i++) { Object element = comboBox.getItemAt(i); result.add(element); } return result; }
/** * Get selected number of dead fields. When 'random' selected it returns 0. * * @return Number of selected dead fields, 0 when 'random' chosen. */ public int getDeadFieldNumber() { if (comboOptions.getSelectedIndex() == 0) { Random generator = new Random(); return Integer.parseInt(comboOptions.getItemAt(generator.nextInt(5) + 1).toString()); } else { return Integer.parseInt(comboOptions.getSelectedItem().toString()); } }
public void valueChanged(TreeSelectionEvent arg0) { DefaultMutableTreeNode curTreeNode = (DefaultMutableTreeNode) ((MyTree) arg0.getSource()).getLastSelectedPathComponent(); if (curTreeNode == null) return; if (!(curTreeNode.getUserObject() instanceof Caliber)) { return; } Caliber cal = (Caliber) curTreeNode.getUserObject(); // 数据源组合框 dataSourceCbx.setValue(cal.getACal().getSourceID()); // 根据字段列名得到字段类型 // cbxFieldName.setSelectedIndex(-1); JComboBox cbxFieldNameTmp = (JComboBox) cbxFieldName.getEditor(); int count = cbxFieldNameTmp.getItemCount(); String value; for (int i = 0; i < count; i++) { value = ((FComboBoxItem) cbxFieldNameTmp.getItemAt(i)).getValue().toString(); if (value.substring(0, value.indexOf(":")).equals(cal.getACal().getSourceColID())) { cbxFieldName.setSelectedIndex(i); break; } } // 字段名称组合框 // cbxFieldName.setValue(cal.getACal().getSourceColID()); // 比较类型 cbxCompare.setValue(cal.getACal().getCompareType()); // 根据sFieldEname返回字段类型 String sFieldTyp = getFieldType(); // 根据字段类型判断参数加不加引号(') // 条件值 if (DefinePub.checkCharVal(sFieldTyp)) { String paraValue = cal.getACal().getValue(); // 判断是不是in或not in比较符 if (CompareType.IN_TYPE.equalsIgnoreCase(cal.getACal().getCompareType()) || CompareType.NOTIN_TYPE.equalsIgnoreCase(cal.getACal().getCompareType())) { // 去掉左右括号 paraValue = paraValue.substring(1, paraValue.length() - 1); // 去掉逗号旁的引号 paraValue = paraValue.replaceAll("','", ","); } // 去掉最外层引号 cbxWhereValue.setValue(paraValue.substring(1, paraValue.length() - 1)); } else { cbxWhereValue.setValue(cal.getACal().getValue()); } // 定义条件类型 if (!Common.isNullStr(cal.getACal().getJoinBefore())) frdoType.setValue(cal.getACal().getJoinBefore()); }
/** Returns information about component. */ @Override public Hashtable<String, Object> getDump() { Hashtable<String, Object> result = super.getDump(); JComboBox<?> jComboBox = (JComboBox<?>) getSource(); Object selectedItem = jComboBox.getSelectedItem(); if (selectedItem != null) { result.put(TEXT_DPROP, selectedItem.toString()); } int itemCount = jComboBox.getItemCount(); String[] items = new String[itemCount]; for (int i = 0; i < itemCount; i++) { if (jComboBox.getItemAt(i) != null) { items[i] = jComboBox.getItemAt(i).toString(); } } addToDump(result, ITEM_PREFIX_DPROP, items); return result; }
private void updateTypeComboBoxes() { CarTypes.instance().updateComboBox(comboBoxTypes); // remove car types not serviced by this location and track for (int i = comboBoxTypes.getItemCount() - 1; i >= 0; i--) { String type = comboBoxTypes.getItemAt(i); if (_track != null && !_track.acceptsTypeName(type)) { comboBoxTypes.removeItem(type); } } CarTypes.instance().updateComboBox(comboBoxShipTypes); // remove car types not serviced by this location and track for (int i = comboBoxShipTypes.getItemCount() - 1; i >= 0; i--) { String type = comboBoxShipTypes.getItemAt(i); if (_track != null && !_track.acceptsTypeName(type)) { comboBoxShipTypes.removeItem(type); } } }
@Override public Parameter duplicate(String newLabel, String newId) { String[] values = new String[choice.getItemCount()]; for (int i = 0; i < values.length; i++) { values[i] = (String) choice.getItemAt(i); } Object def = choice.getSelectedItem(); return new ChoiceParameter(newLabel, newId, values, def != null ? (String) def : null); }
/** * Sets the selected item of an combobox, since using setSelectedItem(...) doesn't work, if one * checks object references! * * @param cb the combobox to set the item for * @param item the item to set active */ protected void setSelectedItem(JComboBox cb, String item) { int i; for (i = 0; i < cb.getItemCount(); i++) { if (cb.getItemAt(i).toString().equals(item)) { cb.setSelectedIndex(i); break; } } }
public void setSelectedFormat(String format) { for (int i = 0; i < formatComboBox.getItemCount(); i++) { DataSourceQueryChooser chooser = (DataSourceQueryChooser) formatComboBox.getItemAt(i); if (chooser.toString().equals(format)) { formatComboBox.setSelectedIndex(i); return; } } }
@Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == annuler) { this.setVisible(false); } if (source == validate) { // ***************here we test if the field is filled or not************ if (tot_pop.getText().equals("")) { JOptionPane.showMessageDialog(errorMsg, "Fill the initial population"); } else { total_popInt = Integer.parseInt(tot_pop.getText()); // Animal a=new Animal(0,typef.getText(),total); int index = typef.getSelectedIndex(); String typeAnim = (typef.getItemAt(index)).toString(); // ****************here we test if what we insert exist with the function above******** if (testingInit("cow")) { write = new fileWriting("init_pop", typeAnim + " " + total_popInt); anima = new AnimalType(total_popInt, typeAnim); this.setVisible(false); // JOptionPane.showMessageDialog(null, "The animal type is created successfully"); } else { JOptionPane.showMessageDialog(errorMsg, "Information on this date already given"); } switch (typeAnim) { case "Cow": AppFrame.totalPopulationCOW = AppFrame.totalPopulationCOW + total_popInt; initialPopCOW = total_popInt; break; case "Deer": AppFrame.totalPopulationDEER = AppFrame.totalPopulationDEER + total_popInt; initialPopDEER = total_popInt; break; case "Horse": AppFrame.totalPopulationHORSE = AppFrame.totalPopulationHORSE + total_popInt; initialPopHORSE = total_popInt; break; default: System.out.println("Switch in Initialize is not working"); break; } Main.totalPopulation = Main.totalPopulation + total_popInt; new AnimalDetails( "2009", "01", CreateAnimal.animalTypeToEnum(typeAnim), total_popInt, 0, "Winter"); new CreateAnimal(CreateAnimal.animalTypeToEnum(typeAnim), total_popInt); } } }
private void prepareTextComboBox(final Object propertyValue) { // _textComboBox wird in der letzten Zeile editierbar gemacht, und es wird // der übergebene Wert in diese Zeile eingetragen und selektiert, wenn er nicht // einem der anderen Einträge entspricht. if (propertyValue != null) { String propertyValueAsString = (String) propertyValue; final int size = _textComboBox.getModel().getSize(); boolean propertyValueFound = false; for (int i = 0; i < size - 1; i++) { if (propertyValueAsString.equals((String) _textComboBox.getItemAt(i))) { propertyValueFound = true; _textComboBox.setSelectedIndex(i); break; } } if (!propertyValueFound) { _textComboBox.removeItemAt(size - 1); _textComboBox.addItem(propertyValueAsString); _textComboBox.setSelectedIndex(size - 1); } } ItemListener textComboBoxItemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (_textComboBox.getSelectedIndex() == DOTPointPainter.DYNAMIC_TEXT_ITEMS.length - 1) { _textComboBox.setEditable(true); } else { _textComboBox.setEditable(false); } } } }; _textComboBox.addItemListener(textComboBoxItemListener); ActionListener editorActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { final int length = DOTPointPainter.DYNAMIC_TEXT_ITEMS.length; final int index = length - 1; final ComboBoxEditor editor = _textComboBox.getEditor(); String editedItem = (String) editor.getItem(); _textComboBox.insertItemAt(editedItem, index); final DefaultComboBoxModel model = (DefaultComboBoxModel) _textComboBox.getModel(); if (model.getSize() > length) { // Sieht komisch aus, aber der direkte Weg ging nicht. model.removeElementAt(length); } } }; _textComboBox.getEditor().addActionListener(editorActionListener); }
// Вид формы при изменении сотрудника public void sotrDiaUpdate(Sotrudnik s) { label_id_hidden.setText(Integer.toString(s.getId_sotrudnika())); textField_familiya.setText(s.getFamiliya()); textField_imya.setText(s.getImya()); textField_otchestvo.setText(s.getOtchestvo()); textField_phone.setText(s.getPhone()); textField_date.setText(s.getData_priema().toString()); comboBox_doljnost.removeAllItems(); comboBox_kvalification.removeAllItems(); try { DBClass db = new DBClass(); ArrayList<Doljnost> d = db.doljnostFromDB(); DBClass db2 = new DBClass(); Doljnost dd = db2.doljnostFromDB(s); for (int i = 0; i < d.size(); i++) { comboBox_doljnost.addItem(d.get(i)); Doljnost ddd = (Doljnost) comboBox_doljnost.getItemAt(i); if (dd.getNazvanie_doljnosti().equals(ddd.getNazvanie_doljnosti())) dd = ddd; } comboBox_doljnost.setSelectedItem(dd); DBClass db3 = new DBClass(); ArrayList<Kvalification> k = db3.kvalificationFromDB(); DBClass db4 = new DBClass(); Kvalification kk = db4.kvalificationFromDB(s); for (int i = 0; i < k.size(); i++) { comboBox_kvalification.addItem(k.get(i)); Kvalification kkk = (Kvalification) comboBox_kvalification.getItemAt(i); if (kk.getNazvanie_kvalification().equals(kkk.getNazvanie_kvalification())) kk = kkk; } comboBox_kvalification.setSelectedItem(kk); } catch (ClassNotFoundException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panelException, e.getMessage()); } catch (SQLException ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(panelException, ee.getMessage()); } }
public void testCarOwners() { CarOwners co1 = CarOwners.instance(); co1.addName("Rich Guy 1"); Assert.assertTrue("Car Owner Add", co1.containsName("Rich Guy 1")); Assert.assertFalse("Car Owner Never Added", co1.containsName("Richer Guy 2")); co1.addName("Really Rich 3"); Assert.assertTrue("Car Owner Still Has", co1.containsName("Rich Guy 1")); Assert.assertTrue("Car Owner Add second", co1.containsName("Really Rich 3")); String[] owners = co1.getNames(); Assert.assertEquals("First owner name", "Really Rich 3", owners[0]); Assert.assertEquals("2nd owner name", "Rich Guy 1", owners[1]); JComboBox<?> box = co1.getComboBox(); Assert.assertEquals("First comboBox owner name", "Really Rich 3", box.getItemAt(0)); Assert.assertEquals("2nd comboBox owner name", "Rich Guy 1", box.getItemAt(1)); co1.deleteName("Really Rich 3"); Assert.assertFalse("Car Owner Delete", co1.containsName("Really Rich 3")); co1.deleteName("Rich Guy 1"); Assert.assertFalse("Car Owner Delete second", co1.containsName("Rich Guy 1")); }