You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddonFilter.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. *
  3. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.addons.ui_swing.components.addonbrowser;
  24. import javax.swing.ButtonModel;
  25. import javax.swing.JTextField;
  26. import javax.swing.RowFilter;
  27. import javax.swing.RowFilter.Entry;
  28. import javax.swing.table.DefaultTableModel;
  29. /**
  30. * Addon filter.
  31. */
  32. public class AddonFilter extends RowFilter<DefaultTableModel, Integer> {
  33. private ButtonModel verifiedBox;
  34. private ButtonModel unverifiedBox;
  35. private ButtonModel installedBox;
  36. private ButtonModel notinstalledBox;
  37. private ButtonModel pluginsBox;
  38. private ButtonModel themesBox;
  39. private ButtonModel actionsBox;
  40. private JTextField searchBox;
  41. /**
  42. * Creates a new addon filter.
  43. *
  44. * @param verifiedBox
  45. * @param unverifiedBox
  46. * @param installedBox
  47. * @param notinstalledBox
  48. * @param pluginsBox
  49. * @param themesBox
  50. * @param actionsBox
  51. * @param searchBox
  52. */
  53. public AddonFilter(final ButtonModel verifiedBox,
  54. final ButtonModel unverifiedBox, final ButtonModel installedBox,
  55. final ButtonModel notinstalledBox, final ButtonModel pluginsBox,
  56. final ButtonModel themesBox, final ButtonModel actionsBox,
  57. final JTextField searchBox) {
  58. this.verifiedBox = verifiedBox;
  59. this.unverifiedBox = unverifiedBox;
  60. this.installedBox = installedBox;
  61. this.notinstalledBox = notinstalledBox;
  62. this.pluginsBox = pluginsBox;
  63. this.themesBox = themesBox;
  64. this.actionsBox = actionsBox;
  65. this.searchBox = searchBox;
  66. }
  67. /** {@inheritDoc} */
  68. @Override
  69. public boolean include(
  70. Entry<? extends DefaultTableModel, ? extends Integer> entry) {
  71. AddonInfo info = ((AddonInfoLabel) entry.getModel().getValueAt(entry.
  72. getIdentifier(), 0)).getAddonInfo();
  73. return !((!verifiedBox.isSelected() && info.isVerified()) ||
  74. (!unverifiedBox.isSelected() && !info.isVerified()) ||
  75. (!installedBox.isSelected() && info.isInstalled()) ||
  76. (!notinstalledBox.isSelected() &&
  77. !info.isInstalled()) || (!pluginsBox.isSelected() &&
  78. info.getType() == AddonType.TYPE_PLUGIN) ||
  79. (!themesBox.isSelected() && info.getType() ==
  80. AddonType.TYPE_THEME) ||
  81. (!actionsBox.isSelected() && info.getType() ==
  82. AddonType.TYPE_ACTION_PACK) || (!searchBox.getText().
  83. isEmpty() && !info.matches(searchBox.getText())));
  84. }
  85. }