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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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 java.util.Enumeration;
  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. /**
  40. * A version number for this class. It should be changed whenever the class
  41. * structure is changed (or anything else that would prevent serialized
  42. * objects being unserialized with the new class).
  43. */
  44. private static final long serialVersionUID = 1;
  45. /** Notification method order list. */
  46. private ReorderableJList list;
  47. /** Notification methods. */
  48. private final List<String> methods;
  49. /** The plugin that owns this panel. */
  50. private final NotificationsPlugin plugin;
  51. /**
  52. * Creates a new instance of NotificationConfig panel.
  53. *
  54. * @param plugin The plugin that owns this panel
  55. * @param methods A list of methods to be used in the panel
  56. */
  57. public NotificationConfig(final NotificationsPlugin plugin,
  58. final List<String> methods) {
  59. super();
  60. if (methods == null) {
  61. this.methods = new LinkedList<String>();
  62. } else {
  63. this.methods = new LinkedList<String>(methods);
  64. }
  65. this.plugin = plugin;
  66. initComponents();
  67. }
  68. /**
  69. * Initialises the components.
  70. */
  71. private void initComponents() {
  72. list = new ReorderableJList();
  73. for (String method : methods) {
  74. list.getModel().addElement(method);
  75. }
  76. setLayout(new MigLayout("fillx, ins 0"));
  77. JPanel panel = new JPanel();
  78. panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
  79. "TitledBorder.border"), "Source order"));
  80. panel.setLayout(new MigLayout("fillx, ins 5"));
  81. panel.add(new JLabel("Drag and drop items to reorder"), "wrap");
  82. panel.add(new JScrollPane(list), "growx, pushx");
  83. panel.add(new ListReorderButtonPanel(list), "");
  84. add(panel, "growx, wrap");
  85. panel = new JPanel();
  86. panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
  87. "TitledBorder.border"), "Output format"));
  88. panel.setLayout(new MigLayout("fillx, ins 5"));
  89. add(panel, "growx, wrap");
  90. }
  91. /**
  92. * Retrieves the (new) notification method order from this config panel.
  93. *
  94. * @return An ordered list of methods
  95. */
  96. public List<String> getMethods() {
  97. final List<String> newMethods = new LinkedList<String>();
  98. final Enumeration<?> values = list.getModel().elements();
  99. while (values.hasMoreElements()) {
  100. newMethods.add((String) values.nextElement());
  101. }
  102. return newMethods;
  103. }
  104. /** {@inheritDoc} */
  105. @Override
  106. public void save() {
  107. plugin.saveSettings(getMethods());
  108. }
  109. }