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

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