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.

NotificationConfig.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.notifications;
  18. import com.dmdirc.addons.ui_swing.components.reorderablelist.ListReorderButtonPanel;
  19. import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
  20. import com.dmdirc.config.prefs.PreferencesInterface;
  21. import com.dmdirc.config.provider.ConfigProvider;
  22. import java.util.LinkedList;
  23. import java.util.List;
  24. import javax.swing.BorderFactory;
  25. import javax.swing.JLabel;
  26. import javax.swing.JPanel;
  27. import javax.swing.JScrollPane;
  28. import javax.swing.UIManager;
  29. import net.miginfocom.swing.MigLayout;
  30. /**
  31. * Notification method configuration panel.
  32. */
  33. public class NotificationConfig extends JPanel implements PreferencesInterface {
  34. /** A version number for this class. */
  35. private static final long serialVersionUID = 1;
  36. /** Notification method order list. */
  37. private ReorderableJList<String> list;
  38. /** Notification methods. */
  39. private final List<String> methods;
  40. /** User settings config to save to. */
  41. private final ConfigProvider userSettings;
  42. /** This plugin's settings domain. */
  43. private final String domain;
  44. /**
  45. * Creates a new instance of NotificationConfig panel.
  46. *
  47. * @param userSettings Config to save settings to
  48. * @param domain This plugin's settings domain
  49. * @param methods A list of methods to be used in the panel
  50. */
  51. public NotificationConfig(
  52. final ConfigProvider userSettings,
  53. final String domain,
  54. final List<String> methods) {
  55. if (methods == null) {
  56. this.methods = new LinkedList<>();
  57. } else {
  58. this.methods = new LinkedList<>(methods);
  59. }
  60. this.userSettings = userSettings;
  61. this.domain = domain;
  62. initComponents();
  63. }
  64. /**
  65. * Initialises the components.
  66. */
  67. private void initComponents() {
  68. list = new ReorderableJList<>();
  69. for (String method : methods) {
  70. list.getModel().add(method);
  71. }
  72. setLayout(new MigLayout("fillx, ins 0"));
  73. JPanel panel = new JPanel();
  74. panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
  75. "TitledBorder.border"), "Source order"));
  76. panel.setLayout(new MigLayout("fillx, ins 5"));
  77. panel.add(new JLabel("Drag and drop items to reorder"), "wrap");
  78. panel.add(new JScrollPane(list), "growx, pushx");
  79. panel.add(new ListReorderButtonPanel<>(list), "");
  80. add(panel, "growx, wrap");
  81. panel = new JPanel();
  82. panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
  83. "TitledBorder.border"), "Output format"));
  84. panel.setLayout(new MigLayout("fillx, ins 5"));
  85. add(panel, "growx, wrap");
  86. }
  87. /**
  88. * Retrieves the (new) notification method order from this config panel.
  89. *
  90. * @return An ordered list of methods
  91. */
  92. public List<String> getMethods() {
  93. return new LinkedList<>(list.getModel().elements());
  94. }
  95. @Override
  96. public void save() {
  97. userSettings.setOption(domain, "methodOrder", getMethods());
  98. }
  99. }