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

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