PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/models/MPComboboxModel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 68 lines | 30 code | 7 blank | 31 comment | 6 complexity | 1b574db978a538f00e200bd6fef5c9f7 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.utils.models;
  18. import javax.swing.DefaultComboBoxModel;
  19. /**
  20. * MP Implementation of a {@link DefaultComboBoxModel}
  21. */
  22. public class MPComboboxModel extends DefaultComboBoxModel {
  23. private static final long serialVersionUID = 1L;
  24. /**
  25. * Constructs a DefaultComboBoxModel object initialized with an array of {@link MPComboboxModelItem}objects.
  26. * @param items
  27. */
  28. public MPComboboxModel(MPComboBoxModelItem[] items) {
  29. super(items);
  30. }
  31. /**
  32. * Returns all elements in the model
  33. * @return
  34. */
  35. public MPComboBoxModelItem[] getElements() {
  36. MPComboBoxModelItem[] m = new MPComboBoxModelItem[getSize()];
  37. for (int i = 0; i < m.length; i++) {
  38. m[i] = (MPComboBoxModelItem) getElementAt(i);
  39. }
  40. return m;
  41. }
  42. @Override
  43. public MPComboBoxModelItem getSelectedItem() {
  44. if (super.getSelectedItem() != null) {
  45. if (super.getSelectedItem() instanceof MPComboBoxModelItem) {
  46. return (MPComboBoxModelItem) super.getSelectedItem();
  47. } else {
  48. return new MPComboBoxModelItem(0, super.getSelectedItem().toString());
  49. }
  50. } else {
  51. return null;
  52. }
  53. }
  54. /**
  55. * Set the value of the selected item. The selected item may be null.
  56. * @param item - The combo box value or null for no selection.
  57. */
  58. public void setSelectedItem(MPComboBoxModelItem item) {
  59. super.setSelectedItem(item);
  60. }
  61. }