123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /*
- * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.notifications;
-
- import com.dmdirc.addons.ui_swing.components.reorderablelist.ListReorderButtonPanel;
- import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
- import com.dmdirc.config.prefs.PreferencesInterface;
-
- import java.util.Enumeration;
- import java.util.LinkedList;
- import java.util.List;
-
- import javax.swing.BorderFactory;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.UIManager;
-
- import net.miginfocom.swing.MigLayout;
-
- /**
- * Notification method configuration panel.
- */
- public class NotificationConfig extends JPanel implements PreferencesInterface {
-
- /**
- * A version number for this class. It should be changed whenever the class
- * structure is changed (or anything else that would prevent serialized
- * objects being unserialized with the new class).
- */
- private static final long serialVersionUID = 1;
- /** Notification method order list. */
- private ReorderableJList list;
- /** Notification methods. */
- private final List<String> methods;
- /** The plugin that owns this panel. */
- private final NotificationsPlugin plugin;
-
- /**
- * Creates a new instance of NotificationConfig panel.
- *
- * @param plugin The plugin that owns this panel
- * @param methods A list of methods to be used in the panel
- */
- public NotificationConfig(final NotificationsPlugin plugin,
- final List<String> methods) {
- super();
-
- if (methods == null) {
- this.methods = new LinkedList<String>();
- } else {
- this.methods = new LinkedList<String>(methods);
- }
- this.plugin = plugin;
-
- initComponents();
- }
-
- /**
- * Initialises the components.
- */
- private void initComponents() {
- list = new ReorderableJList();
-
- for (String method : methods) {
- list.getModel().addElement(method);
- }
-
- setLayout(new MigLayout("fillx, ins 0"));
-
- JPanel panel = new JPanel();
-
- panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
- "TitledBorder.border"), "Source order"));
- panel.setLayout(new MigLayout("fillx, ins 5"));
-
- panel.add(new JLabel("Drag and drop items to reorder"), "wrap");
- panel.add(new JScrollPane(list), "growx, pushx");
- panel.add(new ListReorderButtonPanel(list), "");
-
- add(panel, "growx, wrap");
-
- panel = new JPanel();
-
- panel.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
- "TitledBorder.border"), "Output format"));
- panel.setLayout(new MigLayout("fillx, ins 5"));
-
- add(panel, "growx, wrap");
- }
-
- /**
- * Retrieves the (new) notification method order from this config panel.
- *
- * @return An ordered list of methods
- */
- public List<String> getMethods() {
- final List<String> newMethods = new LinkedList<String>();
-
- final Enumeration<?> values = list.getModel().elements();
-
- while (values.hasMoreElements()) {
- newMethods.add((String) values.nextElement());
- }
-
- return newMethods;
- }
-
- /** {@inheritDoc} */
- @Override
- public void save() {
- plugin.saveSettings(getMethods());
- }
- }
|