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.

ThemePanel.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.components.addonpanel;
  18. import com.dmdirc.addons.ui_swing.UIUtilities;
  19. import com.dmdirc.addons.ui_swing.components.IconManager;
  20. import com.dmdirc.addons.ui_swing.components.addonbrowser.DataLoaderWorkerFactory;
  21. import com.dmdirc.addons.ui_swing.injection.MainWindow;
  22. import com.dmdirc.config.UserConfig;
  23. import com.dmdirc.events.eventbus.EventBus;
  24. import com.dmdirc.interfaces.config.ConfigProvider;
  25. import com.dmdirc.ui.themes.Theme;
  26. import com.dmdirc.ui.themes.ThemeManager;
  27. import com.dmdirc.updater.manager.CachingUpdateManager;
  28. import java.awt.Window;
  29. import java.util.ArrayList;
  30. import java.util.Collections;
  31. import java.util.List;
  32. import javax.inject.Inject;
  33. import javax.swing.JTable;
  34. import javax.swing.table.DefaultTableModel;
  35. /**
  36. * Lists known themes, enabling the end user to enable/disable these as well as download new ones.
  37. */
  38. public class ThemePanel extends AddonPanel {
  39. /** A version number for this class. */
  40. private static final long serialVersionUID = 1;
  41. /** Manager to retrieve themes from. */
  42. private final ThemeManager themeManager;
  43. /** Manager to use to retrieve addon-related icons. */
  44. private final IconManager iconManager;
  45. /** Manager to use to retrieve update information. */
  46. private final CachingUpdateManager updateManager;
  47. /** Configuration to write update-related settings to. */
  48. private final ConfigProvider userConfig;
  49. /**
  50. * Creates a new instance of ThemePanel.
  51. *
  52. * @param parentWindow Parent window
  53. * @param themeManager Manager to retrieve themes from.
  54. * @param workerFactory Factory to use to create data workers.
  55. * @param iconManager Manager to use to retrieve addon-related icons.
  56. * @param updateManager Manager to use to retrieve update information.
  57. * @param userConfig Configuration to write update-related settings to.
  58. * @param eventBus The event bus to post errors to.
  59. */
  60. @Inject
  61. public ThemePanel(
  62. @MainWindow final Window parentWindow,
  63. final ThemeManager themeManager,
  64. final DataLoaderWorkerFactory workerFactory,
  65. final IconManager iconManager,
  66. final CachingUpdateManager updateManager,
  67. @UserConfig final ConfigProvider userConfig,
  68. final EventBus eventBus) {
  69. super(parentWindow, workerFactory, eventBus);
  70. this.themeManager = themeManager;
  71. this.iconManager = iconManager;
  72. this.updateManager = updateManager;
  73. this.userConfig = userConfig;
  74. load();
  75. }
  76. @Override
  77. protected JTable populateList(final JTable table) {
  78. final List<Theme> list = new ArrayList<>(themeManager.getAllThemes().values());
  79. Collections.sort(list);
  80. UIUtilities.invokeLater(() -> {
  81. ((DefaultTableModel) addonList.getModel()).setRowCount(0);
  82. for (final Theme theme : list) {
  83. ((DefaultTableModel) addonList.getModel()).addRow(
  84. new AddonCell[]{
  85. new AddonCell(
  86. new AddonToggle(
  87. updateManager,
  88. userConfig,
  89. themeManager,
  90. theme),
  91. iconManager),});
  92. }
  93. addonList.repaint();
  94. });
  95. return addonList;
  96. }
  97. @Override
  98. protected String getTypeName() {
  99. return "themes";
  100. }
  101. }